iOS 為UI控件設置任意一個角的圓角

分類:技術 時間:2016-10-25

給指定角度設計成圓角,方法步驟如下:

步驟:

1、新建UIBezierPath對象maskPath

2、新建CAShapeLayer對象maskLayer

3、將maskPath的CGPath賦值給maskLayer的path,即maskLayer.path = maskPath.CGPath

4、把caShapeLayer添加到某個顯示該圖形的layer中

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: button.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: CGSizeMake(10, 10) ];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = button.bounds;

maskLayer.path = maskPath.CGPath;

button.layer.mask = maskLayer;

圓角可選為四種

UIRectCornerBottomLeft

UIRectCornerBottomRight //UI底部兩個角為圓角

UIRectCornerTopRight

UIRectCornerTopRight //UI頂部角為圓角


Tags: iOS開發

文章來源:http://www.jianshu.com/p/88b389b2a34e


ads
ads

相關文章
ads

相關文章

ad