[英]How to change border style of CGRect in Swift2?
I'm learning Swift and my designer has given me a screen like this. 我正在学习Swift,我的设计师给了我这样的屏幕。
I am facing problem in how to change the border style of total credits CGRect
in this dashed form. 我在如何以这种虚线形式更改总积分
CGRect
的边框样式时CGRect
问题。
My code is: 我的代码是:
override func viewDidLoad()
{
let promobox = UIView()
promobox.frame = CGRectMake(16, promotextfield.frame.minY + 180, self.view.frame.width - 32, 60)
promobox.layer.borderColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.2).CGColor
promobox.layer.borderWidth = 2.0
promobox.layer.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 0.2).CGColor
//background color of box
self.view.addSubview(promobox)
}
This is how you can do this: 这是您可以执行的操作:
let promobox = UIView()
promobox.frame = CGRectMake(16, 50, self.view.frame.width - 32, 60)
promobox.layer.borderColor = UIColor.whiteColor().CGColor
promobox.layer.borderWidth = 2.0
promobox.layer.backgroundColor = UIColor(red: 255, green: 255, blue: 255, alpha: 0.2).CGColor
let border = CAShapeLayer.init()
border.frame = promobox.bounds
border.path = UIBezierPath(rect: border.frame).CGPath
border.lineWidth = 2
border.strokeColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.2).CGColor
border.fillColor = UIColor.clearColor().CGColor
border.lineDashPattern = [4, 6]
promobox.layer.addSublayer(border)
Play with lineDashPattern
to meet your designer's expectations. 玩
lineDashPattern
可以满足设计师的期望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.