I know we can use the buttonWithType
method to get an UIButton with specific type.
UIButton * button = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
Today, I casually use UIButton's alloc/init method to create an UIButton:
UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(20, 300, 100, 50)];
then I found there is no way to change the button's type.Because the UIButton's buttonType property is readonly.
In UIKit.framework, UIButton.h :
@property(nonatomic,readonly) UIButtonType buttonType;
My question is:if I use alloc/init to create a UIButton, can I change the UIButton's type? If not, since there is NOT any init method like -initWithType
in UIButton, we can only use the +buttonWithType
method to get an autorelease UIButton. It sounds a little strange, why not provide an initWithType method?