Monday 31 July 2017

Sliding with fade in fade out of label in swift 3

class Testing: UIViewController {
    
    
    @IBOutlet weak var slidingView: UIView!
    
    @IBOutlet weak var sliding_label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
       sliding_label.layer.cornerRadius=10
        sliding_label.layer.masksToBounds = true
    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.sliding_label.slideInFromLeft()
        //      self.slidingTextLabel.slideInFromLeft(duration: 1.0, completionDelegate: self) // Use this line to specify a duration or completionDelegate
        self.sliding_label.text = "  "+"Sliding Registration and select location"+"  "
        self.sliding_label.alpha = 0
        self.sliding_label.fadeIn(completion: {
            (finished: Bool) -> Void in
            self.sliding_label.fadeOut()
        })
        self.sliding_label.isHidden = false
        DispatchQueue.main.asyncAfter(deadline: .now() + 7) {
            self.sliding_label.fadeOut()
        }

    }
    


}

-------------------------------------------------------------------------------------------------

extensions:

extension UIView {
    // Name this function in a way that makes sense to you...
    // slideFromLeft, slideRight, slideLeftToRight, etc. are great alternative names
    func slideInFromLeft(duration: TimeInterval = 1.0, completionDelegate: AnyObject? = nil) {
        // Create a CATransition animation
        let slideInFromLeftTransition = CATransition()
        
        // Set its callback delegate to the completionDelegate that was provided (if any)
        if let delegate: AnyObject = completionDelegate {
            slideInFromLeftTransition.delegate = delegate as? CAAnimationDelegate
        }
        
        // Customize the animation's properties
        slideInFromLeftTransition.type = kCATransitionPush
        slideInFromLeftTransition.subtype = kCATransitionFromLeft
        slideInFromLeftTransition.duration = duration
        slideInFromLeftTransition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        slideInFromLeftTransition.fillMode = kCAFillModeRemoved
        
        // Add the animation to the View's layer
        self.layer.add(slideInFromLeftTransition, forKey: "slideInFromLeftTransition")
    }
    
    func fadeIn(duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
        UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
            self.alpha = 1.0
        }, completion: completion)  }
    
    func fadeOut(duration: TimeInterval = 1.0, delay: TimeInterval = 3.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
        UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
            self.alpha = 0.0
        }, completion: completion)
    }
}


Sunday 30 July 2017

set Image in circlein swift 3

   override func viewDidLayoutSubviews() {
        
        imageView.layer.cornerRadius = imageView.frame.size.height/2
        imageView.clipsToBounds = true 
        

    }

Friday 28 July 2017

How to underline a UILabel and UIButton programatically in swift 3



For Label:labelname.attributedText = NSAttributedString(string: "text", attributes:            [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue])

o/p: text




For Button: let linkbuttonAttributes : [String: Any] = [NSUnderlineStyleAttributeName : NSUnderlineStyle.styleSingle.rawValue] let attributeString = NSMutableAttributedString(string: "Terms and Conditions",                                                    attributes: linkbuttonAttributes) termsofServices.setAttributedTitle(attributeString, for: .normal)

o/p: Terms and Conditions

Thursday 27 July 2017

change Navigation bar title colour programatically in swift 3

override func viewDidLoad() {        super.viewDidLoad()        let nav = self.navigationController?.navigationBar        self.title="Address Details"        nav?.tintColor = UIColor.white            }


    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let nav = self.navigationController?.navigationBar
        nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    }

Friday 7 July 2017

Left and Right arrow scrolling button for horizontal UICollection view

import UIKit

extension CAGradientLayer {
    
    func backgroundGradientColor() -> CAGradientLayer {
        let rightColor = UIColor(red: (210/255.0), green: (210/255.0), blue:(210/255.0), alpha: 1)
        let leftColor = UIColor(red: (230/255.0), green: (230/255.0), blue:(230/255.0), alpha: 0.1)
        let gradientColors: [CGColor] = [rightColor.cgColor, leftColor.cgColor]
        let gradientLayer: CAGradientLayer = CAGradientLayer()
        gradientLayer.colors = gradientColors
        gradientLayer.startPoint = CGPoint(x: 0.0,y :0.0)
        gradientLayer.endPoint = CGPoint(x: 1.0,y :0.0)
        return gradientLayer
        
    }
    
    func backgroundGradientColor2() -> CAGradientLayer {
        let rightColor = UIColor(red: (230/255.0), green: (230/255.0), blue:(230/255.0), alpha: 0.1)
        let leftColor = UIColor(red: (210/255.0), green: (210/255.0), blue:(210/255.0), alpha: 1)
        let gradientColors: [CGColor] = [rightColor.cgColor, leftColor.cgColor]
        let gradientLayer: CAGradientLayer = CAGradientLayer()
        gradientLayer.colors = gradientColors
        gradientLayer.startPoint = CGPoint(x: 0.0,y :0.0)
        gradientLayer.endPoint = CGPoint(x: 1.0,y :0.0)
        return gradientLayer
        
    }

}

------------------------------------------------------------------------------------------------


class ViewController: UIViewController{

    
    
    @IBOutlet weak var pickedImaged: UIImageView!
    
    
    @IBOutlet weak var rightarrow: UIButton!
    
    @IBOutlet weak var leftarrow: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        rightarrowstyle()
        leftarrowstyle()
       
    }



 
func rightarrowstyle() {
        let background = CAGradientLayer().backgroundGradientColor2()
        background.frame = self.rightarrow.bounds
        self.rightarrow.layer.insertSublayer(background, at: 0)
    }
    
    func leftarrowstyle() {
        let background = CAGradientLayer().backgroundGradientColor()
        background.frame = self.leftarrow.bounds
        self.leftarrow.layer.insertSublayer(background, at: 0)
    }

}



UICollectionView and Selected Cell loses selection while scrolling

https://stackoverflow.com/questions/33326395/uicollectionview-and-selected-cell-loses-selection-while-scrolling

Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...