System button
In addition to the image and text buttons, there is a small library of system buttons that can create standardized, predefined buttons that you can see in many applications. System buttons are also uibarbuttonitem objects that can be created through the Initwithbarbuttonsystemitem method of the class. The following example:
- Uibarbuttonitem *mybookmarks = [[Uibarbuttonitem alloc]
- Initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks
- Target:self
- Action: @selector (Myselector:)
- ];
Table 3-2 is the currently supported system button that can be found in the UIBarButtonItem.h header file.
Table 3-2
|
button identifiers |
Description |
|
Uibarbuttonsystemitemdone |
Blue text button labeled "Done" |
|
Uibarbuttonsystemitemcancel |
Text button, labeled "Cancel" |
|
Uibarbuttonsystemitemedit |
Text button, labeled "Edit" |
|
Uibarbuttonsystemitemsave |
Blue text button labeled "Save" |
|
Uibarbuttonsystemitemadd |
Image button with a å symbol on it |
|
Uibarbuttonsystemitemflexiblespace |
Blank, variable space-occupying size |
|
Uibarbuttonsystemitemfixedspace |
Blank placeholder |
|
Uibarbuttonsystemitemcompose |
Image button with a pen and paper on it |
|
Uibarbuttonsystemitemreply |
Image button with a reply arrow on it |
|
Uibarbuttonsystemitemaction |
Image button with an action arrow on it |
|
Uibarbuttonsystemitemorganize |
Image button, with a folder on it and a down arrow |
|
Uibarbuttonsystemitembookmarks |
Image button with bookmark icon on it |
|
Uibarbuttonsystemitemsearch |
Image button with Spotlight icon on it |
|
Uibarbuttonsystemitemrefresh |
Image button with a circular flush arrow on it |
|
Uibarbuttonsystemitemstop |
Image button with a stop mark on the X |
|
Uibarbuttonsystemitemcamera |
Image button with a camera on it |
|
Uibarbuttonsystemitemtrash |
Image button with a trash bin on it |
|
Uibarbuttonsystemitemplay |
Image button with a play icon on it |
|
Uibarbuttonsystemitempause |
Image button with a pause icon on it |
|
Uibarbuttonsystemitemrewind |
Image button with a rewind icon on it |
|
Uibarbuttonsystemitemfastforward |
Image button with a fast forward icon |
Custom View Buttons
Like the navigation bar, a button can also be drawn according to a custom view class so that you can display any other type of view object as a button:
- Uibarbuttonitem *custombutton = [[Uibarbuttonitem alloc]
- Initwithcustomview:myview];
Creating toolbars
Add all the buttons you want to display to the buttons array you created earlier:
- [Buttons Addobject:buttonimage];
- [Buttons Addobject:buttontext];
- [Buttons Addobject:mybookmarks];
Next, create a Uitoolbar object and assign your button array to the toolbar as a list of items:
- Uitoolbar *toolbar = [[Uitoolbar alloc] init];
- [Toolbar setitems:buttons Animated:yes];
Finally, replace the title view of your navigation bar with the newly created toolbar, just as you would replace a component segment control:
- Self.navigationItem.titleView = toolbar;
When the navigation bar is displayed, the toolbar appears in its center.
Adjust size
The toolbar will apply the default size to the added buttons. If you want to adjust the toolbar so that it fits neatly into the size of the navigation bar, you can use the SizeToFit method:
- [Toolbar SizeToFit];
The style of the toolbar
Just like many other view-based objects, Uitoolbar also contains a style attribute named Barstyle. This property can be used to adjust the style of the toolbar so that it matches the style you define for the navigation bar:
- Toolbar.barstyle = Uibarstyledefault;
You can set the style of the toolbar to one of three standard style themes that are also used by most other types of column objects, as shown in table 3-3.
Table 3-3
|
Style |
Description |
|
Uibarstyledefault |
Default style: Gray background, white text |
|
Uibarstyleblackopaque |
Pure black background, white text |
|
Uibarstyleblacktranslucent |
Transparent black background, white text |
iOS Basics-System comes with button style-Uibarbuttonsystemitem