Hi i'm having trouble to apply gradient color to my UIView
. It is correctly applied, but the color bounds varies with horizontal & portrait orientation.
if I set correctly on Portrait orientation, then the gradient view's bounds are not changed when I flip the device to horizontal.
So, How to get correct constraints and size of the UIView
for both horizontal and portrait device orientation?.
Thanks a lot for your help!!!
Code I have tried:
import UIKit
class ViewController: UIViewController {
@IBOutlet var viewBar: UIView!
override func viewDidLoad() {
super.viewDidLoad()
viewBar.layer.shadowOpacity = 0.5
viewBar.layer.shadowOffset = CGSize(width: 3.0, height:2.0)
viewBar.layer.shadowRadius = 5.0
viewBar.layer.shadowColor = UIColor.blueColor().CGColor
let gradient: CAGradientLayer = CAGradientLayer()
gradient.colors = [UIColor.blueColor().CGColor, UIColor.redColor().CGColor]
gradient.locations = [0.0 , 1.0]
gradient.startPoint = CGPoint(x: 0.0, y: 1.0)
gradient.endPoint = CGPoint(x: 1.0, y: 1.0)
gradient.frame.size = self.viewBar.bounds.size
self.viewBar.layer.insertSublayer(gradient, atIndex: 0)
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Coding output: