开发者

How to create a user control for IPhone?

开发者 https://www.devze.com 2023-01-05 21:54 出处:网络
So I read about Interface Builder Plug-Ins but from what I understood they\'re not supported on IPhone on the MAC.

So I read about Interface Builder Plug-Ins but from what I understood they're not supported on IPhone on the MAC.

Basically I want to create a User Control (this is a .NET term) is this possible in 开发者_如何学运维iPhone development? A user control is basically like me trying to create my own custom button, or own custom slider, etc so that it is easily re-usable.

Any suggestions? thanks!


Nothing so generic as “User Control” (from the sound of it) exists in Cocoa Touch, except that you can directly subclass UIView to make a wholly-new kind of view.

However, you'll probably find it easier to subclass the existing UIButton, UISlider, etc. classes instead. Such subclasses should be lightweight: You shouldn't need to do more than change the control's part images (e.g., the slider's thumb and tracks).

Besides being easier, subclassing the existing classes will also mean your controls will remain consistent in behavior with standard controls. Imagine if you'd implemented your own text field from the ground up prior to Apple adding copy and paste.

Once you've made your subclasses, you should be able to select your controls in IB and set their custom class names to the names of your custom subclasses. You should then be able to add those controls to the Library to reuse them. (Caveat: I only write Mac software, so I don't know whether IB has these features for iPhone development.)


It's easier than you think, actually. While you can't make your own "User Control" so to speak, you can actually customize the appearance of almost every UIKit control anyway, such as custom buttons, and editing text field properties and fonts, etc. You could make a view with this in it, and add it to a parent view at runtime if you so desired. It can be used multiple times, or you can just customize them individually as you need them, which is how I prefer because of the simplicity.


My Objective-C is a little rusty (I'm digging back into it as we speak), but what I would do is create an object to control the button. Then you can send messages to the button so it acts consistently between instantiations of the button.

I'd add some code for you to look at, but I've got nephews and nieces climbing all over me (happy 4th of July!) - good luck! (by the way, I'm a fan of adium!)

0

精彩评论

暂无评论...
验证码 换一张
取 消