My iOS Learning Path (i): Creating a UI interface using code

Source: Internet
Author: User
Tags set background

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

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.