How to add a custom UIView to the storyboard scene

I created a UIView with a representation of the image inside it. Gave him the name "XXXMyView".

in my storyboard view manager, I dragged the UIView onto the view controller (scene) and then set its class to XXXMyView.

But when I do, I do not see the image, but only the background color.

How can I do this when I see my presentation, which I created on the screen displaying the image?

+7
source share
3 answers

What you need to do is create an empty UIView in your storyboard. Drag and drop the UIImageView into your view.

Then subclass UIView. In the storyboard, set the class of your view to match your newly created class. Open the editor window (in the upper right of the main project window, the middle button in the "editor" section). Place XXXView.h in the left window and your storyboard on the right. ctrl-drag from your UIImageView to your .h (between @interface and @end ). Give him a name. You have created a connection between your UIImageView visual representation and your code. Now you can access it from your .m file.

Ray Wenderlich has a pretty neat storyboard tutorial. Here is part 1 and part 2 .

+4
source

You may need to set the "view" in the UIViewController to the new XXXMyView.

0
source

I think you are looking at it wrong (from what I understand)

  • See the UIViewController as the β€œmain” view and use it to control subzones ( UIView and UIImageView )

  • Link your UIView and UIImageView objects as objects inside your UIViewController class and use these objects to do what you need (add new subzones dynamically or edit properties, etc.)

  • You can add subviews to UIView with [yourViewObject addSubview: (UIView *)] . Do not be fooled (UIView *) , you can use any subclass of UIView as an argument. (e.g. UIImageView object)

If you don’t know how to link (or reference) objects from the storyboard to the class, I would try to work with the Ray Wenderlich storyboard tutorials since rdurand is sugested. Here the link is again Part 1 .

0
source

All Articles