BTN. Frame = cgrectmake (X, Y, width, height );
[BTN settitle: @ "Search" forstate: uicontrolstatenormal];
// Set the auto size on the button
// [BTN setfont: [uifont systemfontsize: 14.0]; // This type can be used to set the font size, but it may be removed from future SDK versions.
// Use
BTN. titlelabel. font = [uifont systemfontofsize: 14.0];
[BTN sebackgroundcolor: [uicolor bluecolor];
// Add the button to the specified view superview
[Superview addsubview: BTN];
Appendix: two methods for creating a button:
1. Dynamic Creation
Btnfont = [uibutton buttonwithtype: uibuttontyperoundedrect];
[Btnfont setframe: cgrectmake (100, 10,120, 40)];
[Btnfont addtarget: Self action: Nil forcontrolevents: uicontroleventtouchupinside];
[Btnfont settitle: @ "font" forstate: uicontrolstatenormal];
Btnfont. backgroundcolor = [uicolor clearcolor];
[Self. View addsubview: btnfont];
2. You have already created a file in the XIB file. Use the tag to get it.
Uibutton * testbutton = (uibutton *) [self. View viewwithtag: 100];
[Testbutton addtarget: Self action: @ selector (test :) forcontrolevents: uicontroleventtouchupinside];
Register an event
-(Void) test: (ID) sender {
Uialertview * AV = [[[uialertview alloc] initwithtitle: @ "Ceshi" message: @ "test11111" delegate: Nil cancelbuttontitle: @ "OK" failed: Nil] autorelease];
[AV show];
}
Uibutton font size