2015-05-05 174 views
-1

我使用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) 

我想要做同樣的而是圓的,我想繪製一個圓角矩形。

我該怎麼做?

回答

1

你可以這樣做,用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 
0

我認爲這應該是爲你工作:

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