我正在学习Swift,我的设计师给了我一个这样的画面。
我在如何以虚线形式更改总学分CGRect
的边框样式时遇到问题。
我的代码是:
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)
}
答案 0 :(得分:0)
您可以这样做:
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)
与lineDashPattern
一起玩,以满足您设计师的期望。