我有一个尝试转换为Swift 3的Gradient类,但是出现以下错误
迅速无法使用“ CGPointMake”
对于
func configureGradientView() { let color1 = topColor ?? self.tintColor as UIColor let color2 = bottomColor ?? UIColor.black as UIColor let colors: Array <AnyObject> = [ color1.cgColor, color2.cgColor ] let layer = self.layer as! CAGradientLayer layer.colors = colors layer.startPoint = CGPointMake(startX, startY) layer.endPoint = CGPointMake(endX, endY) }
任何人都可以帮我解决我可以代替的东西 CGPointMake
CGPointMake
这是全班;
@IBDesignable public class XGradientView: UIView { @IBInspectable public var topColor: UIColor? { didSet { configureGradientView() } } @IBInspectable public var bottomColor: UIColor? { didSet { configureGradientView() } } @IBInspectable var startX: CGFloat = 0.0 { didSet{ configureGradientView() } } @IBInspectable var startY: CGFloat = 1.0 { didSet{ configureGradientView() } } @IBInspectable var endX: CGFloat = 0.0 { didSet{ configureGradientView() } } @IBInspectable var endY: CGFloat = 0.0 { didSet{ configureGradientView() } } public class func layeredClass() -> AnyClass { return CAGradientLayer.self } public required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! configureGradientView() } override init(frame: CGRect) { super.init(frame: frame) configureGradientView() } public override func tintColorDidChange() { super.tintColorDidChange() configureGradientView() } func configureGradientView() { let color1 = topColor ?? self.tintColor as UIColor let color2 = bottomColor ?? UIColor.black as UIColor let colors: Array <AnyObject> = [ color1.cgColor, color2.cgColor ] let layer = self.layer as! CAGradientLayer layer.colors = colors layer.startPoint = CGPointMake(startX, startY) layer.endPoint = CGPointMake(endX, endY) } }
您可以迅速创建一个CGPoint快捷方式CGPoint(x: xPos, y:yPos)。因此,将您更改CGPointMake(startX,startY)为CGPoint(x: startX, y: startY)
CGPoint
CGPoint(x: xPos, y:yPos)
CGPointMake(startX,startY)
CGPoint(x: startX, y: startY)