UIView *oneview = name[0];//2. Add to view inside the controller[Self.view Addsubview:greenview];//similarities and differences of 3.storyboard and Xib 1>difference*Storyboard: Description software interface, large-scale, heavyweight, more suitable for describing the software of all the interface*xib: Description Software interface, small-scale, lightweight, more suitable for describing a small interface2>the same point: the essence is the conversion code//4.xib explanationNsarray*array = [NSBundle mainbundle] loadnibnamed:@"MyView"Owner:_name Options:nil];-(Nsarray *) loadnibnamed: (NSString *) name owner: (ID) Owner options: (Nsdictionary *) options{//parsing myview.xib Files//CREATE VIEWUIView *blue =[[UIView alloc] init]; Blue.backgroudcolor=[Uicolor Bluecolor]; //.... Set other properties//Create buttonUIButton *btn =[UIButton Buttonwithtype:uibuttontyperoundedrect]; [BTN Settitle:@"I'm the button ."Forstate:uicontrolstatenormal]; [Btn Addtarget:owner Action: @selector (Btnclick) forevent:uicontroleventtouchupinside]; //... Set other properties[Blue addsubview:btn]; //Create a text input boxUitextfield *field =[[Uitextfield alloc] init]; //Set other properties return@[blue, field];}5. File'use steps for s owner 1> Setting file in the Xib.'the class attribute of S owner (the purpose is to find the owner's method in Xib) 2> Create File'the link between S Owner and the control 3> Use code to load Xib, pass Owener parameters (type must match)
Xcode--xib