UIButton *button = [UIButton buttonwithtype:uibuttontyperoundedrect];
There are 6 types of button that can be defined:
/*typedef enum{
Uibuttontypecustom = 0; Custom Style
Uibuttontyperoundedrect, Rounded Rectangle
Uibuttontypedetaildisclosure Blue small arrow button, mainly to do detailed instructions with
Uibuttontypeinfolight//Bright exclamation
Uibuttontypeinfodark Dark Exclamation
Uibuttontypecontactadd Cross plus button
}uibuttontype;
The position of the given button on the view
Button.frame = CGRectMake (20, 20, 280, 40);
*/
Button background color
Button.backgroundcolor = [Uicolor Clearcolor];
Set Button Fill picture
[Button setimage:[uiimage imagenamed:@ "Btn.png"] forstate:uicontrolstatenormal];
/*forstate: The function of this parameter is to define the state of the button's text or picture in which it will appear */
Here are a few states
enum{
UIControlStateNormal = 0; Regular State appearances
uicontrolstatehighlighted = 1<<0; Highlight State appears
uicontrolstatedisabled = 1<<1; The disabled state will only appear
uicontrolstateselected = 1<<2; Checked status
Uicontrolstateapplication = 0x00ff0000 is an application flag
uicontrolstatereserved = 0xff000000 is reserved for the internal frame and can be used regardless of his
/* By default, when the button is highlighted, the color of the image will be darker, if this property is set to No, then this function can be removed */
button.adjustsimagewhenhighlighted = NO;
/* As in the above case, by default, when the button is disabled, the image will be drawn deeper, set No to cancel the setting */
button.adjustsimagewhendisabled = NO;
/* Below this property is set to Yes, the button will glow */
button.showstouchwhenhighlighted = YES;
button click event
Butclick: This method
Addtarget:self means that this method can also pass in other pointers in this class.
[Button addtarget:self action: @selector (Butclick:) forcontrolevents:uicontroleventtouchupinside];
Display controls
[Self.view Addsubview:button];
Attention:
[Button addtarget:self action: @selector (Alarmtimedo:) forcontrolevents:uicontroleventtouchupinside];
Addtarget:self is linked to self, which is generally set
Action: @selector (Alarmtimedo:) Time-processing functions
Forcontrolevents:uicontroleventtouchupinside Control Event handling messages
The Cancel button has added all the events: (This is more important, if two events are added two events will be triggered)
[Button Removetarget:nil Action:nil forcontrolevents:uicontroleventtouchupinside];
When is release UIButton released?
Whether to release the UIButton object in Dealloc depends on how the UIButton is initialized if you use the
[Uibuttonbuttonwithtype:uibuttontypecustom]; In this way, the release operation is not required, because this method is automatically released, and if [[UIBUtton Alloc]init] is used, it is necessary to take active release release operations.
IOS Uibtton Events:
Uicontroleventtouchdown Click on the touch down event: The user touches the screen, or when a new finger falls.
Uicontroleventtouchdownrepeat Multi-Touch press event, the number of points technology is greater than 1, the user pressed the second, third, or fourth with the finger when
Uicontroleventtouchdraginside when a touch is dragged within the control window;
Uicontroleventtouchdragoutside when a touch is dragged outside the control window
Uicontroleventtouchdraginside when a touch is dragged within a control window
Uicontroleventtouchdragenter when a touch is dragged from outside the control window to the inside
Uicontroleventtouchdragexit when a touch is dragged from inside the control window to the outside.
UIControlEventTouchUpInside so touch lift events within the control
Uicontroleventtouchupoutside all touch lift events outside the control (the touch must start with the inside of the control)
Uicontroleventtouchcancel all touch cancellation events, that is, a touch is canceled because too many fingers are placed, or locked or interrupted by a phone call
Uicontroleventeditingtouchchanged when the value of the control changes, send a notification for the slider, segment control
Uicontroleventeditingdidbegin a notification is sent when the text control starts editing.
Uicontroleventeditingdidend send notification when edit ends in text control
Uicontroleventeditingdidendonexit when editing is finished in a text control by pressing ENTER (or equivalent behavior)
Uicontroleventalleditingevents notify all events about text editing
Uicontroleventalltouchevents Notify all Touch events
Uicontroleventallevents Notify all Events
Properties of some UI controls for IOS