Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameter from storyboard to custom UIView iOS

I have created a custom UIView and I would like to initialize it with custom parameters from the UIStoryboard. Basically I have added a UIView in the UIStoryboard and I have changed the class to my custom UIView.

In my custom UIView class I'm using the initWithCoder method to initialize it but I would like to use the provided NSCoder to get some configuration parameters from the UIStoryboard, is this possible or is there another way to pass parameters from the UIStoryboard to my custom UIView?

Thanks!!

like image 911
rdiaz82 Avatar asked Sep 03 '13 09:09

rdiaz82


Video Answer


1 Answers

Apparently is not possible to add parameters to NSCoder using the initwithCoder:

Initializing a view with custom initWithCoder

I have found a workaround to solve the problem, simply using the User Defined Runtime Attributes doing the following:

1) Add the custom properties in the storyboard in the "User Defined Runtime Attributes".

2) Add the same properties to my custom class.

3) Use the properties to customize the UIView in the awakeFromNib method.

With this solution, I'm able to initialize my custom UIView from the storyboard and just use it from my controller.

like image 119
rdiaz82 Avatar answered Oct 08 '22 22:10

rdiaz82