I'm attempting to round just the top left and bottom left corners of a UITextField
. Here is the code I am using:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: locationText.bounds, byRoundingCorners: .TopLeft | .BottomLeft, cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
locationText.layer.mask = maskLayer;
}
The line
maskLayer.path = UIBezierPath(roundedRect: locationText.bounds, byRoundingCorners: .TopLeft | .BottomLeft, cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
is producing the error
Cannot assign a value of type 'CGPath' to a value of type 'CGPath?'
This is confusing me since I've been able to set values to optionals no problem elsewhere in the code. Could someone help me understand what I am doing wrong?
如果您将Swift 2.0与Xcode Beta一起使用,则可能是编译器的一个错误,试图告诉您应该使用数组来指示拐角
maskLayer.path = UIBezierPath(roundedRect: self.view.bounds, byRoundingCorners: [.TopLeft, .BottomLeft], cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.