Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'CGPointMake' is unavailable in swift [duplicate]

Tags:

ios

swift

swift3

I have a Gradient class which I am trying to convert to Swift 3 but I get the following error

'CGPointMake' is unavailable in 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

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)
}
}
like image 837
RileyDev Avatar asked Sep 05 '16 19:09

RileyDev


2 Answers

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)

like image 135
Adnan Aftab Avatar answered Oct 25 '22 00:10

Adnan Aftab


swift 3 emphasizes in use of named Parameters.

CGPoint Can be created like this.

let point = CGPoint(x: 0,y :0) // CGFloat, Double, Int
like image 14
pkc456 Avatar answered Oct 24 '22 22:10

pkc456