UIBezzierPath为圆角矩形

问题描述:

我使用UIBezzierPath绘制角落找寻框架的循环使用此UIBezzierPath为圆角矩形

let circlePath = UIBezierPath(arcCenter: CGPoint(x: frame.size.width/2.0, y: frame.size.height/2.0), radius: (frame.size.width - 10)/2, startAngle: 0.0, endAngle: CGFloat(M_PI * 2.0), clockwise: true) 

我想要做同样的而是圆的,我想绘制一个圆角矩形。

我该怎么做?

你可以这样做,用UIBezierPath原样

CAShapeLayer * maskLayer = [CAShapeLayer layer]; 
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){10., 10.}].CGPath; 

self.layer.mask = maskLayer; 

你也可以这样做,通过AS-上的视图层设置角半径

view.backgroundColor = UIColor.clearColor() 
view.layer.cornerRadius = 5 
view.layer.borderWidth = 1 
view.layer.borderColor = UIColor.blackColor().CGColor 

我认为这应该是为你工作:

let side = self.view.frame.size.width - 10 
let cornerRadius = 5 
let rectPath = UIBezierPath(roundedRect: CGRectMake(0, 0, side, side), cornerRadius: cornerRadius)