// Create button
UIButton* button = [UIButton buttonwithtype:uibuttontyperoundedrect];
// Set Button caption
[Button settitle:@ " touch me !" forstate:uicontrolstatenormal];
// The button size is determined automatically according to the title length
[Button SizeToFit];
// Set the button in the center position
button. Center = self. View. Center;
// The button position is adjusted automatically when the screen changes
button. Autoresizingmask = uiviewautoresizingflexiblewidth |
uiviewautoresizingflexibleheight |
uiviewautoresizingflexibleleftmargin |
uiviewautoresizingflexiblerightmargin |
uiviewautoresizingflexibletopmargin |
uiviewautoresizingflexiblebottommargin;
// Set the response method when the button is touched
[Button addTarget: Self
action:@selector(buttondidpush:)
forcontrolevents:uicontroleventtouchupinside];
This article from "Shenzhen Lian City Tong technology company" blog, declined reprint!
IOS UIButton Common Methods Introduction