For custom controls such as uitoolbar, uinavigationbar, uitabbar, uibarbuttonitem, and uitabbaritem, we will discuss them together because they are common.
There are usually two ways to implement customization.
1) obtain the control object, and then make specific changes to this specific object.
2) use uiappearance to customize all similar controls and specific similar controls. Because most applications use the same type of controls for appearance, the use of uiappearance makes it very convenient to customize interfaces. This method is usually implemented in the appdelegate. M file.
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary
*) Launchoptions is implemented in this method.
This section describes how to use uiappearance. For details, refer to "uiappearance Protocol Reference". There are two methods:
1. Customize the display of all class objects.
[[Uinavigationbar appearance] settintcolor: mycolor];
2. display of custom class objects contained in a specific containerclass. This is mainly for uibarbuttonitem, that is to say, some uibarbuttonitems are in uinavigationbar, and some are in uitoolbar, we can choose to customize the button in which the button exists. Example:
[[Uibarbuttonitem appearancewhencontainedin: [uinavigationbar class], nil] settintcolor: mynavbarcolor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class],[UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setTintColor:myToolbarColor];
The following is a summary of the custom methods for each control using uiappearance. This is taken from Apple's official reference. Note that the following method can also be used separately for a single object.
1. uitoolbar
Customizing appearance
-Backgroundimagefortoolbarposition: barmetrics :( page 7)
Returns the image to use for the background in a given position and with given metrics.
-Setbackgroundimage: fortoolbarposition: barmetrics :( page 7)
Sets the image to use for the background in a given position and with given metrics.
-Shadowimagefortoolbarposition :( page 9)
Returns the image to use for the toolbar shadow in a given position.
-Setshadowimage: fortoolbarposition :( page 9)
Sets the image to use for the toolbar shadow in a given position.
Tintcolor (page 6)
Property
The color used to tint the bar.
2. uitabbar
Customizing appearance
Backgroundimage
(Page 5)PropertyThe background image for the bar.
Selectedimagetintcolor
(Page 7)Property
The tint color to apply to the gradient image used when creating the selected image.
Selectionindicatorimage
(Page 8)PropertyThe image used for the selection indicator.
Shadowimage
(Page 8)Property
The Shadow image to be used for the tab bar.
Tintcolor
(Page 8)Property
The tint color to apply to the tab Bar background.
3. uinavigationbar
Customizing the bar appearance
Tintcolor
(Page 9)Property
The color used to tint the bar.
-Backgroundimageforbarmetrics :( page11)
Returns the background image for given bar metrics.
-Setbackgroundimage: forbarmetrics :( page 13) sets the background image for given bar metrics.
-Titleverticalpositionadjustmentforbarmetrics :( page 14) returns the title's vertical position adjustment for given bar metrics.
-Settitleverticalpositionadjustment: forbarmetrics :( page 14) sets the title's vertical position adjustment for given bar metrics.
Titletextattributes
(Page 9)PropertyDisplay attributes for the bar's title text.
4. uibarbuttonitem
Customizing appearance
Tintcolor (page 9)
Property
The tint color for the button item.
-Backbuttonbackgroundimageforstate: barmetrics :( page 10)
Returns the back button background image for a given control state and bar metrics.
-Setbackbuttonbackgroundimage: forstate: barmetrics :( page 17)
Sets the back button background image for a given control state and bar metrics
-Backbuttontitlepositionadjustmentforbarmetrics :( page11) returns the back button title offset for given bar metrics.
-Setbackbuttontitlepositionadjustment: forbarmetrics :( page 19) sets the back button title offset for given bar metrics
-Backbuttonbackgroundverticalpositionadjustmentforbarmetrics :( page 10) returns the back button vertical position offset for given
Bar metrics.
-Setbackbuttonbackgroundverticalpositionadjustment: forbarmetrics :( page 18) sets the back button vertical position offset
Given bar metrics.
-Backgroundverticalpositionadjustmentforbarmetrics :( page 13) returns the background vertical position offset for given bar metrics.
-Setbackgroundverticalpositionadjustment: forbarmetrics :( page 21) sets the background vertical position offset for given bar metrics.
-Backgroundimageforstate: barmetrics :( page11)
Returns the background image for a given State and bar metrics.
-Setbackgroundimage: forstate: barmetrics :( page 19)
Sets the background image for a given State and bar metrics.
-Backgroundimageforstate: style: barmetrics :( page 12)
Returns the background image for the specified state, style, and metrics.
-Setbackgroundimage: forstate: style: barmetrics :( page 20)
Sets the background image for the specified state, style, and metrics.
-Titlepositionadjustmentforbarmetrics :( page 22) returns the title offset for given bar metrics.
-Settitlepositionadjustment: forbarmetrics :( page 21) sets the title offset for given bar metrics.
5. uitabbaritem
Customizing appearance
-Titlepositionadjustment (page 8)
Returns the offset to use to adjust the title position.
-Settitlepositionadjustment :( page 8)
Sets the offset to use to adjust the title position.
In addition, it is customized for specific objects.
1. uitabbaritem
-Finishedselectedimage
(Page 5) returns the finished selected image.
-Finishedunselectedimage (page 5) returns the finished unselected image.
-Setfinishedselectedimage: withfinishedunselectedimage :( page 7) sets the finished selected and unselected images.
The preceding method is used to change the selected and unselected images of each single tabbaritem.
2. uibarbuttonitem
Style
(Page 8)PropertyThe style of the item.
Possibletitles
(Page 7)Property
The set of possible titles to display on the bar button.
Width
(Page 9)PropertyThe width of the item.
Customview
(Page 7)Property
A custom view representing the item.
3. uinavigationbar
Barstyle
(Page 7)Property
The appearance of the navigation bar.
Shadowimage
(Page 8)Property
The Shadow image to be used for the navigation bar.
Translucent
(Page 10)Property
A boolean value indicating whether the navigation bar is only partially opaque.
Basically, it is easy to customize these methods.