Adding Gradients to the Buttons
Watch the video: https://youtu.be/LKSvLuguzUs
- Add some colors at the top of the ButtonController class, before the first method. These will control the colors of the gradient. These colors are green. You may have to change these numbers if you want to have a different color button.
class ButtonController: UIViewController {
let color1 = UIColor.init(red: 0, green: 0.7, blue: 0.5, alpha: 1)
let color2 = UIColor.init(red: 0, green: 0.6, blue: 0.4, alpha: 1)
override func viewDidLoad() {
- Add this code after the code that changes the corner radius:
for v in view.subviews {
if (v.isKindOfClass(UIButton)) {
v.layer.cornerRadius = 4
let gl = CAGradientLayer()
gl.colors = [ color1.CGColor, color2.CGColor ]
gl.locations = [ 0.0, 1.0 ]
gl.frame.size = v.frame.size
v.layer.insertSublayer(gl, atIndex: 0)
v.layer.sublayers![0].cornerRadius = 4
}
}
- Add the same code to the AnimalViewController class. Instead of green buttons, I used gray buttons like this. YOu can make the buttons whatever color you wish.
let color1 = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 1)
let color2 = UIColor.init(red: 0.4, green: 0.4, blue: 0.4, alpha: 1)
No comments:
Post a Comment