석진영
석진영

Reputation: 243

init with UIButtonTypeCustom option in ios

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

test.buttonType= UIButtonTypeCustom;

-> assinging to property with 'readonly' **attribute not a allow

why? how??

Upvotes: 1

Views: 1397

Answers (1)

PengOne
PengOne

Reputation: 48398

You should use the class method

+ buttonWithType:

to create the button. After that, set the frame.

From the UIButton Class Reference:

buttonType

The button type. (read-only)

@property(nonatomic, readonly) UIButtonType buttonType

This means that you cannot change the buttonType once the button as been created.

For example, you can do

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

Upvotes: 4

Related Questions