I just simply want to apply Gradient with 2 UIColors that's why I written below code.
class Constants: NSObject {
class func applyGradient(localView:UIView, color1:UIColor, color2:UIColor) {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.frame = localView.bounds
gradient.colors = [color1.CGColor, color2.CGColor]
gradient.startPoint = CGPoint(x: 0,y: 0)
gradient.endPoint = CGPoint(x: 0,y: 1)
localView.layer.insertSublayer(gradient, atIndex: 0)
localView.layer.masksToBounds = true
}
}
and applying via below code in UIViewController's viewDidLoad.
Constants.applyGradient(viewContactDetail, color1: gradientColor1, color2: gradientColor2)
Constants.applyGradient(viewDiscountDetail, color1: gradientColor1, color2: gradientColor2)
Constants.applyGradient(viewTermsCondDetail, color1: gradientColor1, color2: gradientColor2)
Constants.applyGradient(viewDiscountAvailDetail, color1: gradientColor1, color2: gradientColor2)
And here is the result what I'm getting
You can see, Gradient isn't apply on specific view properly.
I'm not getting what is wrong with my code.


