////VIEWCONTROLLER.M//common methods of 07-uiview//#import "ViewController.h"@interfaceViewcontroller ()//The red view, connected by wire, binds the OC code to the UI. @property (Weak, nonatomic) Iboutlet UIView *Redview;/** Red View*/@property (nonatomic, weak) UIView*RedView1, @property (weak, nonatomic) Iboutlet UIButton*BTN1;//These controls will not die, so you can use weak,@property (Weak, nonatomic) Iboutlet UIButton *btn2, @property (weak, nonatomic) Iboutlet UIButton*Btn3;@end/** * Minimize the use of tag:1> tag efficiency very poor 2> tag use more, easy to mess*/@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //according to the tag to get the corresponding viewUIView *redview = [Self.view viewwithtag:1]; Self.redview=Redview; //1.1 Creating a Uiswitch objectUiswitch *SW =[[Uiswitch alloc] init]; //1.2 Add to the view of the controller[Self.view ADDSUBVIEW:SW]; //1.3 Creating a Uiswitch objectUiswitch *SW1 =[[Uiswitch alloc] init]; //1.4 Add to Red view[Redview ADDSUBVIEW:SW1]; //1.5 Creating a Tab objectUisegmentedcontrol *SG = [[Uisegmentedcontrol alloc] initwithitems:@[@"ha ha haha",@"??",@"hehe"]]; //1.6 Add to Red view[Redview ADDSUBVIEW:SG]; //1.7 Removal//[SG Removefromsuperview];//[Self.redview Removefromsuperview];//[SW Removefromsuperview];[Self.view Removefromsuperview];//We can't remove it here . }#pragmaMark-Pseudo Code---viewwithtag, so the tag is inefficient./*-(UIView *) Viewwithtag: (Nsinteger) tag{if (Self.tag = = tag) return self; For (UIView *subview in self.subviews) {if (Subview.tag = = tag) return subView; Continue recursive traversal//: }}*///as long as the control has a parent control, it must be able to remove- (void) Viewdidappear: (BOOL) animated{[Super viewdidappear:animated];//[Self.view Removefromsuperview]; Here you can remove the view from the controller,}-(ibaction) Remove {[Self.redview Removefromsuperview];}-(Ibaction) CLICKBTN: (UIButton *) button {//The connection is to connect the methods and controls together. //do something personal. if(Button = =self.btn1) {NSLog (@"Click the button 1"); }Else if(Button = =self.btn2) {NSLog (@"Click the button 2"); }Else{NSLog (@"Click the button 3"); } Switch(Button.tag) { Case 3: NSLog (@"Click the button 1"); Break; Case 4: NSLog (@"Click the button 2"); Break; Case 5: NSLog (@"Click the button 3"); Break; default: Break; } //do the public thingNSLog (@"do the public thing");}@end
Common methods of Ios3--uiview