iOS development--Custom controls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.