// Create a button uibutton * button1 = [uibutton buttonwithtype: uibuttontyperoundedrect] For a rounded rectangle. // The following types of buttons can be defined, // typedef Enum {// uibuttontypecustom = 0, custom style // uibuttontyperoundedrect, rounded rectangle // rectangle, small blue arrow button, mainly for detailed description // uibuttontypeinfolight, bright color exclamation point // uibuttontypeinfodark, dark color exclamation point // uibuttontypecontactadd, cross plus button //} uibuttontype; // specifies the position of the button on the view. button1.frame = cgrectmake (20, 20,280, 20 ); // button background color button1.backgroundcolor = [uicolor clearcolor]; // set the button filling image // [button1 setimage: [uiimage imagenamed: @ "btng.png"] forstate: uicontrolstatenormal]; // set the button title [button1 settitle: @ "click" forstate: uicontrolstatenormal];/* forstate: the function of this parameter is to define the status in which the text or image of the button appears * // The following are several statuses // Enum {// uicontrolstatenormal = 0, general status display // uicontrolstatehighlighted = 1 <0, highlighted Status display // uicontrolstatedisabled = 1 <1, disabled status appears/uicontrolstateselected = 1 <2, selected status // uicontrolstateapplication = 0x00ff0000, when the applicationProgram When the flag is enabled, // uicontrolstatereserved = 0xff000000 is reserved for the internal framework, regardless of whether it is enabled/};/** by default, when the button is highlighted, the color of the image will be painted a little deeper. If this attribute is set to no, * you can remove this function */button1.adjustsimagewhenhighlighted = no;/* the same as above, by default, when the button is disabled, the image will be painted a little deeper. If no is set, you can cancel the setting */button1.adjustsimagewhendisabled = no; /* when this attribute is set to yes, the button will glow when it is pressed */button1.showstouchwhenhighlighted = yes;/* adds events to the button. There are many types of events, I will open a separate blog post to introduce them. The following time means to trigger this event when you press the button and move your finger away from the screen, It is the same as the click event in the web. After this event is triggered, run the butclick: method. addtarget: Self indicates that this method can also be used to input pointers of other classes */[button1 addtarget: self action: @ selector (butclick :) forcontrolevents: uicontroleventtouchupinside]; // display control [self. view addsubview: button1];