IOS5 and later provide a more powerful tool uiappearance, we set some UI by uiappearance the global effect, so that it is easy to implement UI customization and the simplest to achieve a unified interface style, it provides the following two methods.
+ (ID) appearance
This method is the unification of all changes, such as you set Uinavbar Tintcolor, you can write: [[Uinavigationbar appearance] settintcolor:mycolor];
+ (ID) Appearancewhencontainedin: (Class <>) Containerclass,...
This method sets the change of a class: for example, to set the effect of Uibarbuttonitem in Uinavigationbar, Uipopovercontroller, and Uitabbar. You can write it like this.
[[Uibarbuttonitem Appearancewhencontainedin:[uinavigationbar class], [Uipopovercontroller Class],[UITabbar class] NIL] settintcolor:mypopovernavbarcolor];
Please note that using appearance to set the UI effect is best to use global settings, which are set before all interfaces are initialized, or may fail.
The specific UI appearance is modified as follows:
1. Modify the navigation bar background
The code is as follows:
Uinavigationbar * appearance = [Uinavigationbar appearance];
UIImage *navbackgroundimg =[uiimage imagenamed:@ "Navbg.png"];
[Appearance SetBackgroundImage:navBackgroundImgforBarMetrics:UIBarMetricsDefault];
2. tab bar (Uitabbar)
The code is as follows:
Uitabbar *appearance = [Uitabbar appearance];
Set a background picture
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Tabbar_bg.png"];
Gate Select item Background image
UIImage * selectionindicatorimage =[[uiimageimagenamed:@ "Tabbar_slider"]resizableimagewithcapinsets: Uiedgeinsetsmake (4, 0, 0,0)];
[Appearance setselectionindicatorimage:selectionindicatorimage];
3. Segmented control (Uisegmentcontrol)
The code is as follows:
Uisegmentedcontrol *appearance = [Uisegmentedcontrol appearance];
Segmenteg Normal Background
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Segmente.png"]
Forstate:uicontrolstatenormal
Barmetrics:uibarmetricsdefault];
Segmente Selected background
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Segmente_a.png"]
forstate:uicontrolstateselected
Barmetrics:uibarmetricsdefault];
Split line when Segmente is left unchecked
Barmetrics represents the status of navigation bar, Uibarmetricsdefault represents portrait status (44pixel height), uibarmetricslandscapephone Represents the landscape status (32pixel height)
[Appearance setdividerimage:[uiimage imagenamed:@ "Segmente_line.png"]
Forleftsegmentstate:uicontrolstatenormal
Rightsegmentstate:uicontrolstatenormal
Barmetrics:uibarmetricsdefault];
[Appearance setdividerimage:[uiimage imagenamed:@ "Segmente_line.png"]
forleftsegmentstate:uicontrolstateselected
Rightsegmentstate:uicontrolstatenormal
Barmetrics:uibarmetricsdefault];
[Appearance setdividerimage:[uiimage imagenamed:@ "Segmente_line.png"]
Forleftsegmentstate:uicontrolstatenormal
rightsegmentstate:uicontrolstateselected
Barmetrics:uibarmetricsdefault];
Font
Nsdictionary *textattributes1 = @{uitextattributefont: [Uifont systemfontofsize:18],
Uitextattributetextcolor: [Uicolor Bluecolor],
Uitextattributetextshadowcolor: [Uicolor Whitecolor],
Uitextattributetextshadowoffset: [Nsvaluevaluewithcgsize:cgsizemake (1, 1)]};
[Appearance settitletextattributes:textattributes1 forstate:1];
Nsdictionary *textattributes2 = @{uitextattributefont: [Uifont systemfontofsize:18],
Uitextattributetextcolor: [Uicolor Whitecolor],
Uitextattributetextshadowcolor: [Uicolor Blackcolor],
Uitextattributetextshadowoffset: [Nsvaluevaluewithcgsize:cgsizemake (1, 1)]};
[Appearance settitletextattributes:textattributes2 forstate:0];
4.UIBarbutton
Note: The Uibarbutton has Leftbarbutton,rightbarbutton and Backbarbutton, where the Backbarbutton, with the arrows, need to be set separately.
Barbutton background setting is ios6.0 and later, and Backbutton is ios5.0 and later, here to pay attention!
The code is as follows:
Modify the Uibarbuttonitem on the navigation bar
Uibarbuttonitem *appearance = [Uibarbuttonitem Appearancewhencontainedin:[uinavigationbar class], nil];
Set the font for the navigation bar including Backbarbutton and Leftbarbutton,rightbarbutton
Nsdictionary *textattributes = @{uitextattributefont: [Uifont systemfontofsize:18],
Uitextattributetextcolor: [Uicolorbluecolor],
Uitextattributetextshadowcolor: [Uicolorwhitecolor],
Uitextattributetextshadowoffset: [Nsvaluevaluewithcgsize:cgsizemake (1, 1)]};
[Appearance settitletextattributes:textattributes forstate:1];//forstate is 0 when the normal state, 1 is the click state.
Modify Leftbarbutton,rightbarbutton Background effect
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Navbarbutton.png"]
Forstate:uicontrolstatenormal
Style:uibarbuttonitemstylebordered
Barmetrics:uibarmetricsdefault];
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Navbarbutton_a.png"]
forstate:uicontrolstatehighlighted
Style:uibarbuttonitemstylebordered
Barmetrics:uibarmetricsdefault];
Backbarbutton need to set the background effect separately. Can only be used after ios6.0.
[Appearance setbackbuttonbackgroundimage:[uiimage imagenamed:@ "Nav_bg.png"]
forstate:0
Barmetrics:uibarmetricsdefault];
[Appearance setbackbuttonbackgroundimage:[uiimage imagenamed:@ "Work.png"]
Forstate:1
Barmetrics:uibarmetricsdefault];
[Appearance Setbackbuttontitlepositionadjustment:uioffsetmake (2,-1)
Forbarmetrics:uibarmetricsdefault];
5. Toolbars (Uitoolbar)
Uitoolbar *appearance = [Uitoolbar appearance];
Style and background Two choose one and see what you need.
Style (black translucent, opaque, etc.) settings
[Appearance setbarstyle:uibarstyleblacktranslucent];
Background settings
[Appearance setbackgroundimage:[uiimage imagenamed:@ "Toolbarbg.png"]
Fortoolbarposition:uitoolbarpositionany
Barmetrics:uibarmetricsdefault];
Go to iOS uiappearance using the detailed