// Uibutton is a control used in IOS to respond to user clicks. It can display text, images, and user interaction.
// Create uibutton, which is generally created using the class method and does not need to be released
// Uibutton is also a subclass of uicontrol
// 1. Create uibutton (class method is generally used)
// 2. Configure uibutton
// 3. Add it to the parent View
// Create uibutton
Uibutton * mybutton = [uibutton buttonwithtype: uibuttontypesystem];
// Configure uibutton
// Mybutton. Frame = [cgrectmake (100,200, 50, 50)];
[Mybutton setframe: cgrectmake (100,200, 80, 60)];
// Set the text to be displayed for uibutton
[Mybutton settitle: @ "login" forstate: uicontrolstatenormal];
// Set the text size
Mybutton. titlelabel. font = [uifont systemfontofsize: 20];
// Specifies the uibutton background color.
// Mybutton. backgroundcolor = [uicolor orangecolor];
// Add a click event to uibutton
[Mybutton addtarget: Self action: @ selector (mybuttonaction) forcontrolevents: uicontroleventtouchupinside];
// Add an image to the button
[Mybutton setbackgroundimage: [uiimage imagenamed: @ "1.jpg"] forstate: uicontrolstatenormal];
[Mybutton setbackgroundimage: [uiimage imagenamed: @ "2.jpg"] forstate: uicontrolstatehighlighted];
// Add an image to the button, center it, instead of using Al
Mybutton. contentmode = uiviewcontentmodecenter;
// Add to parent View
[Contentview addsubview: mybutton];
Common uibutton usage