init中使用ios中的UIButtonTypeCustom选项

时间:2012-01-13 04:58:04

标签: iphone ios uibutton

UIButton * test=[[UIButton alloc] initWithFrame:CGRectMake(30, 30, 49, 49)];

test.buttonType= UIButtonTypeCustom;

- >使用“只读” **属性分配属性而不是允许

为什么呢?如何??

1 个答案:

答案 0 :(得分:4)

您应该使用类方法

+ buttonWithType:

创建按钮。之后,设置框架。

来自UIButton Class Reference

  

<强>按钮类型

     

按钮类型。 (只读)

     

@property(nonatomic, readonly) UIButtonType buttonType

这意味着一旦按钮创建,您就无法更改buttonType

例如,您可以

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