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