iOS9 解決帶圖片UIButton的圓角設(shè)置問題

以前設(shè)置圓角按鈕只需設(shè)置button的類型就可以了
//設(shè)置按鈕的 形狀

self.loginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
/* buttonWithType: 定義button按鈕的外形 六種定義button類型:
UIButtonTypeCustom = 0, 無類型
UIButtonTypeRoundedRect, 四個角是圓弧 型的
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark, 
UIButtonTypeContactAdd, */

但在最新的UIKit框架下:

 typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = 0,                         // no button type
UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button

UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,

UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead

對于不帶圖片和背景色的button , 設(shè)置圓角只要設(shè)置為UIButtonTypeSystem類型即可。
但是對于帶圖片的button,則需要按如下方法設(shè)置圓角:

buttonObject.layer.cornerRadius = 10;(圓角的半徑,根據(jù)需要設(shè)置大小)
buttonObject.layer.maskToBounds = YES; (帶圖片的必須設(shè)置這一項,默認(rèn)是NO,如果只設(shè)置背景色,則可不用設(shè)置這一項)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容