Creating a reusable UIView with xib (and loading from storyboard)

前端 未结 6 1046
孤独总比滥情好
孤独总比滥情好 2020-11-28 18:49

OK, there are dozens of posts on StackOverflow about this, but none are particularly clear on the solution. I\'d like to create a custom UIView with an accompan

6条回答
  •  情深已故
    2020-11-28 19:25

    Don't forget

    Two important points:

    1. Set the File's Owner of the .xib to class name of your custom view.
    2. Don't set the custom class name in IB for the .xib's root view.

    I came to this Q&A page several times while learning to make reusable views. Forgetting the above points made me waste a lot of time trying to find out what was causing infinite recursion to happen. These points are mentioned in other answers here and elsewhere, but I just want to reemphasize them here.

    My full Swift answer with steps is here.

提交回复
热议问题