Common methods of Ios3--uiview

Source: Internet
Author: User

////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

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.