After playing around with UIButton class for a while I found Apple have been very sneaky with some of their UI classes.
What it appears they have done is use the UIButton class as a sort of wrapper for a number of private button classes. “UIRoundedRectButton” is one of those classes.
“UIRoundedRectButton” is a private class so it can not be extended(subclassed). The initilizers normaly return an instance of self and if that self is not the class type trying to hold it there will be trouble. The problem is if you initialise UIButton with buttonWithType the class it returns is a private class. If you try and extended the UIButton once your custom class is initialized it returns a “UIRoundedRectButton” object which is private so you can not contain it.
If you try the code below which uses the description you can see the object description is not UIButton.
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
NSLog(@"myButton type: %@", [myButton description]);
In short you can not extend UIButton and initialize it with buttonWithType in Objective C. On the other hand you can extened UIButton for a button in interface builder. If you use interface builder you need to use initWithCoder as the initialiser. While interface builder does the private stuff.