• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to subclass UIButton?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to subclass UIButton?


  • Subject: How to subclass UIButton?
  • From: WT <email@hidden>
  • Date: Wed, 7 Apr 2010 23:26:43 +0200

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

  • Follow-Ups:
    • Re: How to subclass UIButton?
      • From: john chen <email@hidden>
  • Prev by Date: NSPrintInfo, setting filename for print to PDF?
  • Next by Date: Character Map
  • Previous by thread: Re: iPad: UIImagePickerController
  • Next by thread: Re: How to subclass UIButton?
  • Index(es):
    • Date
    • Thread