Custom view for iOS development (97) using XIB to customize a uiview

Source: Internet
Author: User
1 Preface

The Bi integration in xcode is rich in controls, but sometimes it cannot meet our needs. Today we will learn how to use XIB to customize a uiview for reuse.

2. Detailed Process

Directory View:


2.1 create a single view application IOS application project named customview. For example, we do not add any controls to customviewcontroller. XIB.

2.2 create a customview. XIB. The procedure is as follows:



Drag a label and a button to the interface:


2.3 modify view attributes:

Remove autolayout:


Set size to freeform and background color:


2.4 set the size attribute of View in zyviewcontroller. XIB to none:


Zyviewcontroller. m code:

-(Void) viewdidload {[Super viewdidload]; // obtain the nib view array nsarray * nib = [[nsbundle mainbundle] loadnibnamed: @ "customview" Owner: Self options: Nil]; // obtain the first uiview * tmpcustomview = [nib objectatindex: 0]; // obtain the screen frame cgrect tmpframe = [[uiscreen mainscreen] bounds]; // set the midpoint of the custom View to the midpoint of the screen [tmpcustomview setcenter: cgpointmake (tmpframe. size. width/2, tmpframe. size. height/2)]; // Add view [self. view addsubview: tmpcustomview];}

Running result:


3 conclusion

The above is all content and I hope it will help you.

DEMO code download: http://download.csdn.net/detail/u010013695/5419407

Related Article

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.