Tint Color's understanding and simple theme of the app

Source: Internet
Author: User

translated from http://captechconsulting.com/blog/steven-beyers/ios-7-tutorial-series-tint-color-and-easy-app-theming

since IOS7,UIViewwith a new propertyTintcolor, which is used to visually describe which controls on the screen are active or related. For exampleBar button Itemsand theTab Bar ItemsDefault UsageTintcolor. If aViewno display specifiedTintcolor, it inherits the parent view'sTintcolor, so there will be a ripple effect throughout the view hierarchy. The simplest case is that you can use a line of code to give the entireAPPSpecify a color theme:

[[uiapplication sharedapplication] Keywindow].tintcolor = [Uicolor Orangecolor];
uiwindow Inherited from uiview , so we can specify a tintcolor , All child views within the app will then inherit the color. To demonstrate the impact of the tintcolor on various user interface elements, the next step is to take a tabbar example of application, the first page has 6 buttons, each button will change uiwindow tintcolor is a color. The second page will show the effect of the tintcolor on No interface elements. The upper-left corner of the red button sets uiview tintcolor , the blue button in the upper-right corner sets uibutton itself and tabbar" style= " Font-family:menlo ">tintcolor . Finally uisegmentedcontrol will control the appearance of the entire Apple icon. When we press the button on the first page, the UIButtontext automatically adapts to the color specified by the button. Similar to theTabbarThe icon and text on the toolbar will also fit into the new color.


Similarly, we can set the tintcolor tabbar Apply settings uiwindow tintcolor tintcolor tintcolor

Self.view.tintColor = [Uicolor Redcolor];
Setting the tintcolor of a button changes the color of the text on the button, but does not change the color of the button sibling view and the parent view.
Mybutton.tintcolor = [Uicolor Bluecolor];

iOS7 can also be colored or "dark" when alert or action sheet appear. This indicates to the user that these controls are currently unavailable. Press the step control on the second page to see the effect, such as:


in IOS7UIImagea new property has been addedRenderingmode, you can andTintcolorcombined with the use,RenderingmodeThere are three options, the first one isuiimagerenderingmodeautomatic, as the literal meaning of automatic according toUIImagethe usage scenarios andTintcolorto fill the color, for exampleUiimageviewwill not be basedTintcolorRenderingUIImage, whileUibarbuttonitemwill be based onTintcolorAuto FillUIImage. The second option isuiimagerenderingmodealwaysoriginal,UIImageimages are always rendered according to their own colors. The third one isuiimagerenderingmodealwaystemplate, this mode will render all uiimage opaque places with Tintcolor, that is, the UIImage set as this property is used as a template, and if you want parts of the image to be rendered without tintcolor rendering, You need to set which parts to be completely transparent. In the second interface in the example,Segmentedcontrols demonstrate this functionality.


as we have seen,Tintcolorand theRenderingmodeThe two attributes give us a very useful function, but use aTintcolorThere are a few things we need to note, the first isTintcolornot supporteduiappearance. This is very unfortunate, because if supported, we may change the color of the entire app with a few lines of code, for example, we want everyUIButtonhighlighted in a special color, we had to individually set each button'sTintcolor. Second when getting aUIViewof theTintcolor, always return a valid color. This is because if the view'sTintcolorNil will return to the parent view.Tintcolor. If all the views includeUIWindowof theTintcolorif it's all nil,UIWindowalways returns a default value, which is RGB (0,122,255). Third If you customize a view and use theTintcolor, you should achieveTintcolordidchangemethod to make it easier for us to update the rendering of the view when necessary.

-(void) Tintcolordidchange
The default implementation of this method is to perform a standard update. For example, you have a sub-group ofUiimageviewandImageof theRenderingimageset touiimagerenderingmodealwaystemplateor sub-class.UIButtonautomatically redraw when the Tintcolor is updated. The purpose of covering this method is toTintcolorCustomize some behavior when changing. For example we can subclass aUIViewto change the color theme based on the user's choice. The color theme in the example is two options for orange and black, and when the user chooses an option, we can customizeUIViewand setTintcoloris orange, you can then set the child view'sTintcoloris black. There are also iOS6 in theTintcolorProperty But this property is used toNavigation bars,Tab Bars,Toolbars,Search Barsand theScope Barcolor of Beijing. In iOS7 we want to set the background color of these controls we should useBartintcolor.

Tintcolor Very useful and very easy to use, this property allows the user to see which controls are currently active and have related activities by viewing the view.

Tint Color's understanding and simple theme of the app

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.