Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>What to subclass</strong> Instead of <code>UIView</code> you would probably want to subclass <code>UIControl</code>. This class has functionality for the Target/Action pattern build in which you can use to respond to actions generated by your custom control. Most elements on UIKit like buttons and sliders inherit from <code>UIControl</code> for this specific reason.</p> <p><strong>Visualizing your subclass</strong> Drawing really depends on what you want to achieve and what parts you want to animate. You can use images, draw using quartz or OpenGL depending on what you need or what you prefer. Just use the technique to achieve the desired effect in the most simplistic way. Multiple images can be used to handle different states (pressed, etc) or be used for a sprite animation. CALayers are nice to easily rotate or move.</p> <p>No matter what technology you use, you would probably use incoming touch events to control the animation. In case of a dial control you would control the amount of rotation based on y coordinate movement for example.</p> <p>To illustrate: I for example have used images if my control only needed to change when pressed for example: just swap the images. I also like to use <code>CALayer</code> a lot which gives you easy ways to generate borders, masks, gradients and a corner radius, all easily animated too.</p> <p><strong>Using in Interface Builder</strong> With Cocoa on the desktop it was possible to build custom IB palettes for custom controls. iOS never had this functionality and I don't thing the IB plugins are available for Xcode 4.</p> <p>So the only way to handle custom subclasses currently is by using a <code>UIView</code> in IB and setting the 'Custom class' field in the <em>Identity Inspector</em> to the name of your custom class. This way you have a view you can layout and size. In Interface Builder it's just a rectangle, when running your app the XIB will actually deserialize that view to your custom class.</p> <p>When using a <code>UIControl</code> you get the target/action mechanisms for free. So you can wire up your touch events to any object in IB just like with any other standard UIKit control.</p> <p>One thing to note: if you have custom <code>- initWith....:</code> selectors, those will not be called. Your class is deserialized from the XIB so you should use <code>- initWithCoder:(NSCoder *)aDecoder;</code> as initialization. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload