iOS 渐变 Button
2017-06-19 本文已影响0人
xiAo__Ju
效果
Simulator Screen Shot 2017年6月19日 下午10.07.14.pngclass GradientButton: UIButton {
override class var layerClass: AnyClass {
return CAGradientLayer.self
}
override init(frame: CGRect) {
super.init(frame: frame)
if let gradientLayer = layer as? CAGradientLayer {
gradientLayer.colors = [
UIColor(r: 0, g: 233, b: 249).cgColor,
UIColor(r: 50, g: 254, b: 217).cgColor,
]
gradientLayer.locations = [0.25, 0.75]
// set gradient start and end points
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 1, y: 0)
layer.cornerRadius = frame.height / 2
layer.shadowColor = UIColor(r: 0, g: 233, b: 249).cgColor
layer.shadowOffset = CGSize(width: 0, height: 2)
layer.shadowOpacity = 0.9
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}