There is no need to customize a panel with several controls in it, and this panel is used on multiple pages.
There are three ways to solve this problem:
1. Inherit UIView write a class, where you add the required controls in the form of code to complete the layout.
2. Using the Xib layout file to complete the layout
3. Use storyboard to complete the layout
In the three-way, 1 appears high-end atmosphere on the grade, crashed and knocked half a day. Although I am a technical control, but also very disgusted with this pure feelings.
3 to Uiviewcontroller can not meet my needs, it is not very convenient to use. (may also be very useful, I will not use, seeking guidance)
So on the xib how to implement the control of their own, and here also do not talk about the causes and consequences, gradually engaged in half a day, make head dizzy, directly on the final usage.
Use the hair to divide into three steps:
1. Create a new class that inherits from NSObject to hold the UIView in the custom xib.
A. To facilitate the addition of a class method to this class
+ (ID) viewfromnibbyname: (nsstring *) name{
FileOwner2 * owner = [FileOwner2 new];
[ [nsbundlemainbundle] loadnibnamed: Nameowner: Owner Options:nil];
return owner. View;
}
2. Create a new Xib file.
A. Set the size and size of the xib,
B. Set the Xib Fileowner to 1 in the new class.
C. Associate the view with the Fileowner so that the fileowner can manipulate it.
3. Use in other files
// load View5
UIView* view5 = [FileOwner2viewfromnibbyname:@ "VIEW5"];
[View5setframe:cgrectmake(0,N, 375, +)];
[Self. View addsubview: view5];
Summary: Can be multiple xib common one fileowner this way, a fileowner static method can be used to create a different panel by name.
iOS development--Custom controls