views:

661

answers:

1

I am having trouble over simply assigning a value to a UI Button:

//Assume rect is defined
rect = CGRectMake(13, 10, 48, 48);
profileButton = [[UIButton alloc] initWithFrame:rect];
profileButton.buttonType = UIButtonTypeCustom;

I am getting "object cannot be set - either read-only property or setter found" when trying to assign the buttonType to UIButtonTypeCustom.

+4  A: 

This is because buttonType is a read-only property. You can only create buttons of a specific type with buttonWithType:.

profileButton = [[UIButton buttonWithType: UIButtonTypeCustom] retain];
profileButton.frame = CGRectMake(13, 10, 48, 48);

(Not knowing what profileButton is, but assuming it is not a retaining property)

St3fan
That did the trick. I will need to keep this in mind when initializing. Thanks!
Sheehan Alam