IOS設(shè)置按鈕為圓角的示例代碼
iOS中很多時候都需要用到指定風(fēng)格的圓角按鈕,以下是UIButton
提供的創(chuàng)建圓角按鈕方法
設(shè)置按鈕的4個角:
左上: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é)會了嗎?希望這篇文章對大家的開發(fā)能有一定的幫助,如果有疑問大家可以留言交流。謝謝大家對腳本之家的支持。
相關(guān)文章
cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6
這篇文章主要介紹了cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6.0;6.1;7.0;8.3]的解決方案的相關(guān)資料,需要的朋友可以參考下2016-10-10iphone的safari瀏覽器中實現(xiàn)全屏瀏覽的方法
這篇文章主要介紹了iphone的safari瀏覽器中實現(xiàn)全屏瀏覽的方法,同時介紹了Add to Home Screen功能的實現(xiàn)方法,需要的朋友可以參考下2014-06-06Objective-C的MKNetworkKit開發(fā)框架解析
這篇文章主要介紹了Objective-C的MKNetworkKit開發(fā)框架解析,MKNetworkKit是一個用于iOS開發(fā)的輕量級框架,需要的朋友可以參考下2015-11-11