2012-01-13 116 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);