iOS中很多時候都需要用到指定風(fēng)格的圓角按鈕,以下是UIButton
提供的創(chuàng)建圓角按鈕方法
設(shè)置按鈕的4個角:
左上:UIRectCornerTopLeft
左下:UIRectCornerBottomLeft
右上:UIRectCornerTopRight
右下:UIRectCornerBottomRight
示例代碼:
1
2
3
4
5
6
7
8
9
10
|
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 60, 80, 40)]; button.backgroundColor = [UIColor orangeColor]; [self.view addSubview:button]; //這里設(shè)置的是左上和左下角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = button.bounds; maskLayer.path = maskPath.CGPath; button.layer.mask = maskLayer; |
效果圖
總結(jié)
IOS設(shè)置按鈕為圓角的方法到這就結(jié)束了,大家都學(xué)會了嗎?希望這篇文章對大家的開發(fā)能有一定的幫助,如果有疑問大家可以留言交流。謝謝大家對服務(wù)器之家的支持。