iOS中很多時(shí)候都需要用到指定風(fēng)格的圓角按鈕,以下是UIButton提供的創(chuàng)建圓角按鈕方法
設(shè)置按鈕的4個(gè)角:
左上:UIRectCornerTopLeft
左下:UIRectCornerBottomLeft
右上:UIRectCornerTopRight
右下:UIRectCornerBottomRight
示例代碼:
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é)會(huì)了嗎?希望這篇文章對(duì)大家的開發(fā)能有一定的幫助,如果有疑問大家可以留言交流。謝謝大家對(duì)VEVB武林網(wǎng)的支持。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注