UIControl custom subclass sets IB position for iOS

I create a subclass of UIControl and therefore programmatically post everything in it. Now that I have created it, I need to place it several times on different screens. I know that you cannot make an IB plugin for iOS, but there is no way to take the UIView in IB and size / put it where my control should be, and then set its Custom Class property as my UIControl subclass? I know that I will not see that it shows how this really happens in IB, but at least it allows me to set the overall size and placement compared to other things on the screen. I also created IBOutlets in my viewController and correctly connected the view in IB to them. However, when I start, I do not see any settings, and when I set breakpoints in initWithFrame: or loadView , I never see my code being called. How am I supposed to do this?

+7
source share
1 answer

You can drag a UIView into a nib file and 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 the initialization code that gets called when loading from nib, i.e. not in initWithFrame: If you are coding for completeness, both methods (programmatic and fundamentally based) should invoke the same initialization.

If you like it, just create addSubview: in the initialization code, and then implement layoutSubviews to layoutSubviews your own subzones. This will be called at any time when the image is resized and initially.

+10
source

All Articles