Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UIControl subclass set position in IB for iOS

I'm making a UIControl subclass and therefor programmatically laying out everything in it. Now that I have it made up I need to place it multiple times on various screens. I know you can't make a IB plugin for iOS, but isn't there a way to take a UIView in IB and size/place it where my control should be, and then set its' Custom Class property to be my UIControl's subclass? I know I won't see it show the way it really is in IB, but at least this lets me set overall size and placement relative to the other things on screen. I've also created IBOutlets in my viewController and properly connected the view in IB to them. However when run I don't see any customizations, and when I set breakpoints in initWithFrame: or loadView I never see that my code is being called. How should I be doing this?

like image 807
jamone Avatar asked Jul 12 '11 22:07

jamone


1 Answers

You can drag a UIView onto the nib file, then use the identity inspector (command-opt-3) to change the class to any subclass of UIView.

You will need to set the subclasses in initialization code that gets called when loaded from a nib, i.e. not in initWithFrame:. If you're coding for completeness, both methods (programatic and nib-based) should call the same initialization.

If you like, just create and addSubview: in the initialization code, then implement layoutSubviews to layout your custom subviews. This will be called anytime the view is resized as well as initially.

like image 101
bshirley Avatar answered Sep 23 '22 06:09

bshirley