Basic uibutton usage

Source: Internet
Author: User

Uibutton (basic usage) tsummer

// Initialize the button and select the button type

Uibutton * tbutton = [uibutton buttonwithtype: uibuttontypecustom];

// Specify the position of the button on the View

Tbutton. Frame = cgrectmake (20, 20,280, 20 );

// Set the button to fill the image

[Tbuttonsetimage: [uiimageimagenamed: @ "tsummer.png"] forstate: uicontrolstatenormal];

// Set the rounded corner (5 in radians)

Tbutton. layer. cornerradius = 5;

// The title displayed by the button under normal conditions

[Tbutton settitle: @ "tsummer" forstate: uicontrolstatenormal];

// Events that occur after a button is pressed and lifted

[Tbutton addtarget: Self action: @ selector (tbuttonaction :) forcontrolevents: uicontroleventtouchupinside];

Common types of buttons that can be defined

For example:

Uibutton * tbutton = [uibutton buttonwithtype: uibuttontypecustom];

Typedef Enum {

Uibuttontypecustom = 0, custom style (commonly used)

Uibuttontyperoundedrect, rounded rectangle

Uibuttontypedetaildisclosure, blue arrow button, mainly used for detailed description

Uibuttontypeinfolight, brilliant exclamation point

Uibuttontypeinfodark, dark exclamation point

Uibuttontypecontactadd, plus sign

} Uibuttontype;


[Tbutton settitle: @ "tsummer" forstate: uicontrolstatenormal];

// Forstate: this parameter defines the status in which the text or image of the button appears.

Typedef Enum {

Uicontrolstatenormal = 0, // regular status display

Uicontrolstatehighlighted = 1 <0, // highlighted

Uicontrolstatedisabled = 1 <1, // The disabled status is displayed.

Uicontrolstateselected = 1 <2, // select the status

Uicontrolstateapplication = 0x00ff0000, // when the application is marked

Uicontrolstatereserved = 0xff000000 // reserved for the internal framework.

};


// Trigger events

1) uicontroleventtouchdown

Left mouse buttonPress(Note: Only "Press") Action

2) uicontroleventtouchdownrepeat

Left mouse buttonRepeated press multiple times in a row(Note: Only press), for example, double-click the mouse, three-click ,...... .

Note: The Event Sequence is as follows:

Uicontroleventtouchdown->
(Uicontroleventtouchupinside)->
Uicontroleventtouchdown->
Uicontroleventtouchdownrepeat->
(Uicontroleventtouchupinside)->
Uicontroleventtouchdown->
Uicontroleventtouchdownrepeat->
(Uicontroleventtouchupinside)->

...

Except for the first press, each subsequent press is a uicontroleventtouchdown event, followed by a uicontroleventtouchdownrepeat event.

3) uicontroleventtouchdraginside

By pressing the mouse and dragging it within the control boundary.

4) uicontroleventtouchdragoutside

Unlike uicontroleventtouchdraginside, when dragging, the mouse is out of the control boundary range. However, you must first have a uicontroleventtouchdown event, then a uicontroleventtouchdraginside event, and then a uicontroleventtouchdragexit event. When the mouse is already out of the control, the uicontroleventtouchdragoutside event will continue to be dragged.

The specific operation is to press the mouse in the control and drag it out of the control.

5) uicontroleventtouchdragenter

It refers to the event generated during the drag action from outside the control boundary to the inner.

6) uicontroleventtouchdragexit

An event generated when the widget is dragged from inside to outside the control boundary.

7) uicontroleventtouchupinside (most commonly used)

When the mouse is raised within the control range, you must first press the uicontroleventtouchdown or uicontroleventtouchdownrepeat event.

8) uicontroleventtouchupoutside

When the mouse is lifted out of the control boundary, you must first press the mouse and drag it out of the control, that is, uicontroleventtouchdown-> uicontroleventtouchdraginside (N)-> uicontroleventtouchdragoutside (N) the time series, and then the mouse is raised to generate the uicontroleventtouchupoutside event.





Basic uibutton usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.