-
UIButtoniOS/UICatalog 2022. 3. 21. 00:23
When adding a button to your interface, perform the following steps:
- Set the type of the button at creation time.
- Supply a title string or image; size the button appropriately for your content.
- Connect one or more action methods to the button.
- Set up Auto Layout rules to govern the size and position of the button in your interface.
- Provide accessibility information and localized strings.
Respond to Button Taps
Buttons use the Target-Action design pattern to notify your app when the user taps the button.
Rather than handle touch events directly, you assign action methods to the button and designate which events trigger calls to your methods.
At runtime, the button handles all incoming touch events and calls your methods in response.
You connect a button to your action method using the addTarget:action:forControlEvents: method or by creating a connection in Interface Builder. The signature of an action method takes one of three forms, which are listed in Listing1. Choose the form that provides the information that you need to respond to the button tap.
Listing 1 Action methods for buttons
- (IBAction)doSomething; - (IBAction)doSomething:(id)sender; - (IBAction)doSomething:(id)sender forEvent:(UIEvent*)event;
Configure a Button’s Appearance
A button’s type defines its basic appearance and behavior. You specify the type of a button at creation time using the buttonWithType:
'iOS > UICatalog' 카테고리의 다른 글
UITabBarController, UICollectionView (0) 2022.04.06 UITextField, UITextFieldDelegate (0) 2022.04.04 UITableView (0) 2022.04.03 UIStackView (0) 2022.04.03 UIPageControl / UIPageViewControl (0) 2022.03.16