Powerful UI modification tool in iOS 5-uiappearance

Source: Internet
Author: User

Ios5 provides a powerful tool, uiappearance, to easily unify your interface. It provides the following two methods:

+ (ID) Appearance

+ (ID) appearancewhencontainedin :( class <>)Containerclass ,...

The first method is to unify all the changes. For example, if you set the tintcolor of uinavbar, you can write: [[uinavigationbar appearance] settintcolor: mycolor];
The second method changes when a class appears: for example:

[[Uibarbuttonitem appearancewhencontainedin: [uinavigationbar class], [uipopovercontroller class], nil] settintcolor: mypovernavbarcolor];


Other UI exterior modifications are as follows:


First, define two values:

// This facilitates the following UI settings: textattributes: font ID appearance; nsdictionary * textattributes = nil;

1. navigation bar

The Code is as follows:

// Navigation bar {appearance = [uinavigationbar appearance]; uiimage * navbackgroundimg = [uiimage imagenamed: @ "blank"]; [appearance progress: navbackgroundimg forbarmetrics: blank];}

2. Tag bar (uitabbar)

The Code is as follows:

// Tag bar {appearance = [uitabbar appearance]; uiimage * tabbarbackgroungimg = [uiimage imagenamed: @ "tabbar_background"]; [appearance setbackgroundimage: tabbarbackgroungimg]; uiimage * selectionindicatorimage = [[uiimage imagenamed: @ "tabbar_slider"] runtime: uiedgeinsetsmake (4, 0, 0, 0)]; [appearance usage: selectionindicatorimage];}

3. segment Control)

The Code is as follows:

// Segmente unselected background {// cap insets is used to specify which regions are fixed and the unspecified regions are repeat uiimage * segmentselected = [[uiimage imagenamed: @ "bg_o.png"] usage: uiedgeinsetsmake (5, 5, 5)]; uiimage * segmentunselected = [[uiimage imagenamed: @ "bg.png"] usage: uiedgeinsetsmake (5, 5, 5, 5)]; uiimage * segmentselectedunselected = [uiimage imagenamed: @ "line.png"]; uiimage * segunselectedselected = [uiimage imagenamed: @ "line.png"]; uiimage * attributes = [uiimage imagenamed: @ "line.png"]; appearance = [uisegmentedcontrol appearance]; [appearance attributes: segmentunselected forstate: statenormal barmetrics: uibarmetricsdefault] // selected segmente background [appearance progress: segmentselected forstate: stateselected barmetrics: uibarmetricsdefault]; // The split line when no segmente is selected. // barmetrics indicates the status of the navigation bar, orientation indicates the portrait status (44 pixel height), and orientation indicates the landscape status (32 pixel height) [appearance setdividerimage: invalid attributes: stateselected attributes: statenormal barmetrics: Attributes]; [appearance setdividerimage: Attributes attributes: statenormal attributes: stateselected barmetrics: Attributes]; // textattributes = [nsdictionary attributes: Attributes, uitextattributetextcolor, identifier, [nsvalue valuewithcgsize: cgsizemake (1, 1)], identifier, nil]; [appearance settitletextattributes: textattributes forstate: 1]; textattributes = [nsdictionary attributes: attributes, [nsvalue valuewithcgsize: cgsizemake (1, 1)], attributes, nil]; [appearance settitletextattributes: textattributes forstate: 0];}

4. uibarbutton

Note: uibarbuttons include leftbarbutton, rightbarbutton, and backbarbutton. backbarbutton must be set separately because it has arrows.

The barbutton background is set to ios6.0 and later, while the backbutton is set to ios5.0 and later. Pay attention to this!

The Code is as follows:

// Uibarbuttonitem {// only modify uibarbuttonitem appearance = [uibarbuttonitem appearancewhencontainedin: [uinavigationbar class], nil]; // backbarbutton and leftbarbutton, set textattributes = [nsdictionary attributes: delimiter, uitextattributetextcolor, expires, [nsvalue valuewithcgsize: cgsizemake (1, 1)], expires, nil]; [appearance settitletextattributes: textattributes forstate: 0]; textattributes = [nsdictionary attributes: attributes, [nsvalue valuewithcgsize: cgsizemake (1, 1)], response, nil]; [appearance settitletextattributes: textattributes forstate: 1]; uiimage * leftbutton = [[uiimage imagenamed: @ "bgleftbutton.png"] response: 14 topcapheight: 0]; uiimage * normalbutton = [[uiimage imagenamed: @ "bgnormalbutton.png"] accept: accept (0, 5, 0, 5)]; // leftbarbutton, rightbarbutton background [appearance setbackgroundimage: normalbutton forstate: uicontrolstatenormal style: Alert barmetrics: uibarmetricsdefault]; [appearance progress: normalbutton forstate: alert style: Alert barmetrics: alert]; // set the backbarbutton background separately [appearance progress: alert: leftbutton forstate: 0 barmetrics: seconds]; [appearance progress: leftbutton forstate: 1 barmetrics: uibarmetricsdefault]; [appearance progress: uioffsetmake (2,-1) forbarmetrics: seconds];}

5. toolbar (uitoolbar)

The Code is as follows:

// Toolbar {appearance = [uitoolbar appearance]; // select either style or background. You can set [appearance setbarstyle: background]; // background settings [appearance setbackgroundimage: [uiimage imagenamed: @ "background_nav.png"] fortoolbarposition: uitoolbarpositionany barmetrics: uibarmetricsdefault];}

Note: It is best to set global settings before Initialization on all interfaces. Otherwise, the settings may fail.

Related Article

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.