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