Subclassing UIButton I need to subclass UIButton, however the design of UIButton makes this really painful. This is because to create a button you really need to call:

[UIButton buttonWithType:UIButtonTypeRoundedRect]


So if I want to subclass I really need to do whatever it is this method does. However, it is not possible to set the buttons underlying type.

One option is to use something like decorator and subclass UIButton but have the actual button as an ivar and defer all property/method calls to this button. The problem here is that I then need to implement most of the UIButton interface (yawn).

What I have done is something a bit sneakier in my sub class. I have created this method:

- (id) initWithType:(UIButtonType)buttonType
{
    [super init];

    actualButton = [[UIButton buttonWithType:buttonType] retain];

    memcpy(self, actualButton, sizeof(UIButton));
    self-&gt;isa = [ABDescriptorButton class];

    return self ;
}


I know this is pretty unorthodox, but it works and is fairly clean in terms of code. What are the pitfalls I might have with this approach?
You don't need to make an initWithType: method. Just override the buttonWithType: factory method.