Created
October 3, 2017 08:14
GradientView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// GradientView.swift | |
// Aura | |
// | |
// Created by Egor Sakhabaev on 23.07.17. | |
// Copyright © 2017 Egor Sakhabaev. All rights reserved. | |
// | |
import UIKit | |
@IBDesignable | |
class GradientView: UIView { | |
@IBInspectable var firstColor: UIColor = UIColor.clear { | |
didSet { | |
updateView() | |
} | |
} | |
@IBInspectable var secondColor: UIColor = UIColor.clear { | |
didSet { | |
updateView() | |
} | |
} | |
@IBInspectable var isHorizontal: Bool = true { | |
didSet { | |
updateView() | |
} | |
} | |
override class var layerClass: AnyClass { | |
get { | |
return CAGradientLayer.self | |
} | |
} | |
func updateView() { | |
let layer = self.layer as! CAGradientLayer | |
layer.colors = [firstColor, secondColor].map {$0.cgColor} | |
if (isHorizontal) { | |
layer.startPoint = CGPoint(x: 0, y: 0.5) | |
layer.endPoint = CGPoint (x: 1, y: 0.5) | |
} else { | |
layer.startPoint = CGPoint(x: 0.5, y: 0) | |
layer.endPoint = CGPoint (x: 0.5, y: 1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanl you man its realy help