이 같은이 메소드를 호출하여 확장 지금
extension UIView {
func fillGradiant() {
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.frame.size.width = UIScreen.main.bounds.size.width;
gradient.colors = [UIColor(hex:"3067d5").cgColor,UIColor(hex:"009bdf").cgColor] //Choose your gradiant colors
gradient.startPoint = CGPoint.zero
gradient.endPoint = CGPoint(x: 1, y: 0)
self.layer.insertSublayer(gradient, at: 0)
}
}
당신이 특정의 UIView에 그라데이션을 추가 할 수있는 UIView를 추가합니다
extension UIColor {
convenience init(hex: String) {
let scanner = Scanner(string: hex)
scanner.scanLocation = 0
var rgbValue: UInt64 = 0
scanner.scanHexInt64(&rgbValue)
let r = (rgbValue & 0xff0000) >> 16
let g = (rgbValue & 0xff00) >> 8
let b = rgbValue & 0xff
self.init(
red: CGFloat(r)/0xff,
green: CGFloat(g)/0xff,
blue: CGFloat(b)/0xff, alpha: 1
)
}
}