Re: How to subclass UIButton?
Re: How to subclass UIButton?
- Subject: Re: How to subclass UIButton?
- From: john chen <email@hidden>
- Date: Wed, 7 Apr 2010 21:44:00 -0700
I think UIButton is not designed for subclassing. You can try
composition, or create UIButton category method for custom-build
button. Apple has sample code in UICatalog to create custom-build
button.
On Wed, Apr 7, 2010 at 2:26 PM, WT <email@hidden> wrote:
> Hello all,
>
> I need to create a custom bar of UIButton instances which can be scrolled left and right using a swipe gesture. I am thus following the "Autoscroll" sample code from Apple, which subclasses UIImageView to produce a scrollable bar of thumbnail images. My problem is how to correctly subclass UIButton, since the only available means of instantiating a button is through the class method +buttonWithType:.
>
> Once I allocate an instance of the subclass, how do I initialize it with the desired type? The buttonType property is read-only and there is no instance method -initWithType: in the public API.
>
> One alternative I see is to use composition rather than subclassing, essentially creating a decorator for UIButton, but I'd rather not have to do that.
>
> Another option is to fake a button using UIImageView, just like the "Autoscroll" example does, but I'd prefer to have actual UIButton instances.
>
> Am I missing something trivial here? If UIButton was designed in such a way to prevent subclassing, what would you suggest as the best alternative?
>
> Thanks in advance.
> WT._______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden