2012-01-13 108 views
1
UIButton * test=[[UIButton alloc] initWithFrame:CGRectMake(30, 30, 49, 49)]; 

test.buttonType= UIButtonTypeCustom; 

UIButtonTypeCustom選項 - > assinging財產與 '只讀' **屬性不是讓初始化與IOS

爲什麼呢?怎麼樣??

回答

4

您應該使用類方法

+ buttonWithType: 

創建按鈕。之後,設置框架。

UIButton Class Reference

按鈕類型

按鈕類型。 (只讀)

@property(nonatomic, readonly) UIButtonType buttonType

這意味着,創建你不能改變buttonType一次按鈕。

例如,你可以做

UIButton *test = [UIButton buttonWithType:UIButtonTypeCustom]; 
test.frame = CGRectMake(30, 30, 49, 49);