ios 'CGPointMake' 在 swift 中不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39336793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'CGPointMake' is unavailable in swift
提问by RileyDev
I have a Gradient class which I am trying to convert to Swift 3 but I get the following error
我有一个 Gradient 类,我试图将其转换为 Swift 3,但出现以下错误
'CGPointMake' is unavailable in swift
'CGPointMake' 在 swift 中不可用
for
为了
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)
}
Can anyone help me out with what I can use instead of CGPointMake
任何人都可以帮助我解决我可以使用的东西而不是 CGPointMake
Here's the full class;
这是完整的课程;
@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)
}
}
回答by Adnan Aftab
In swift you can create a CGPoint
in swifty way CGPoint(x: xPos, y:yPos)
.
So change your CGPointMake(startX, startY)
to CGPoint(x: startX, y: startY)
在 swift 中,您可以CGPoint
以 swifty 的方式创建一个CGPoint(x: xPos, y:yPos)
。所以改变你CGPointMake(startX, startY)
的CGPoint(x: startX, y: startY)
回答by pkc456
swift 3 emphasizes in use of named Parameters.
swift 3 强调使用命名参数。
CGPoint
Can be created like this.
CGPoint
可以这样创建。
let point = CGPoint(x: 0,y :0) // CGFloat, Double, Int