以前設(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è)置這一項)