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)
}
}
No comments:
Post a Comment