IOS Dynamic Add button

Source: Internet
Author: User

Automatically creates a new button after clicking an existing button and adds an event to the new button so that the prompt pops up when clicked.

Add in Viewcontroller.h

@property (weak, nonatomic) iboutletUIButton *addbutton;

Add response events for this button AddButton

Add in VIEWCONTROLLER.M

-(ibaction) AddButton: (ID) Sender {

// Add a button dynamically

CGRect frame = cgrectmake(0,0, +) ;

UIButton *button = [UIButtonbuttonwithtype: Uibuttontyperoundedrect];

button. frame = frame;

[Button settitle:@ " newly added dynamic button "forstate: UIControlStateNormal];

button. BackgroundColor = [uicolor RedColor];

button. tag =+;

[Button addTarget:self action:@selector(buttonclicked :)forcontrolevents:uicontroleventtouchupinside];

[Self. View addsubview: button];

}

// This is the response function of the new button

-(ibaction) buttonclicked: (ID) Sender {

    uialertview *alert = [[ uialertview< Span style= "COLOR: #000000" > alloc ] Span style= "COLOR: #3d1d81" >initwithtitle : @ " hint "

message:@ " click the dynamic button! "

delegate: Self

cancelbuttontitle:@ " OK "

otherbuttontitles:nil];

[Alertshow];

}



IOS Dynamic Add button

Related Article

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.