This instance is used to dynamically delete and add tags (label) using code
The main list of view controller files, see the code
1 #import "FCViewController.h"2 3 @interfaceFcviewcontroller ()4@property (Strong, nonatomic) Nsmutablearray *Labels;5 @end6 7 @implementationFcviewcontroller8 intNexty = +;9- (void) ViewdidloadTen { One [Super Viewdidload]; A //additional setup after loading the view, typically from a nib. - //Set Background color -Self.view.backgroundColor =[Uicolor Greencolor]; the //instantiating an array -Self. Labels =[Nsmutablearray array]; - //Create Add button and set parameters and event response method. -UIButton *ADDBN =[UIButton Buttonwithtype:uibuttontyperoundedrect]; +Addbn.frame = CGRectMake ( -, -, -, +); -[Addbn Settitle:@"Add"Forstate:uicontrolstatenormal]; + [addbn addtarget:self Action: @selector (add:) forcontrolevents:uicontroleventtouchupinside]; A //Create a Delete button and set the parameters and event response method. atUIButton *REMOVEBN =[UIButton Buttonwithtype:uibuttontyperoundedrect]; -Removebn.frame = CGRectMake ( the, -, -, +); -[REMOVEBN Settitle:@"Remove"Forstate:uicontrolstatenormal]; - [REMOVEBN addtarget:self Action: @selector (remove:) forcontrolevents:uicontroleventtouchupinside]; - //Add a button to the view control - [Self.view ADDSUBVIEW:ADDBN]; in [Self.view ADDSUBVIEW:REMOVEBN]; - } to +- (void) didreceivememorywarning - { the [Super didreceivememorywarning]; * //Dispose of any resources the can be recreated. $ }Panax Notoginseng //Add label --(void) Add: (ID) Sender the { +UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake ( the, Nexty, $, -)]; ALabel.text =@"The champion!"; the [Self. Labels Addobject:label]; + [Self.view Addsubview:label]; -Nexty + = +; $ } $ //Delete lable --(void) Remove: (ID) Sender - { the if([Self. Labels Count] >0) { - //Remove the last label from ViewWuyi [Self. Labels Lastobject] Removefromsuperview]; the [Self. Labels Removelastobject]; -Nexty-= +; Wu } - } About @end
My iOS Learning Path (i): Creating a UI interface using code