IOS Uitabbaritem Select the color of the chart, set the UIImage rendering mode

Source: Internet
Author: User
Tags border color

Uitbarcontroller before in this article explains: http://www.cnblogs.com/niit-soft-518/p/4447940.html

If you have customized the image of Uitabbaritem, when you create it with the above article, we find that the border color of the selected chart is blue by default.

To solve this problem, we need to set the rendering mode of UIImage

Imagewithrenderingmode
set the rendering mode for UIImage: Uiimage.renderingmode Coloring (Tint Color) is one of the iOS7 interfaces. Set the rendering mode of the UIImage: Uiimage.renderingmode A significant change, you can set a UIImage whether to use the tint Color of the current view when rendering. UIImage added a read-only property: Renderingmode, corresponding to a new method: Imagewithrenderingmode:, It uses the Uiimagerenderingmode enumeration value to set the Renderingmode property of the picture. The enumeration contains the following values: Uiimagerenderingmodeautomatic  //  automatically adjusts the rendering mode based on the environment in which the picture is used and the drawing context in which it is located.   Uiimagerenderingmodealwaysoriginal   //  always draws the original state of the picture without using tint Color.   Uiimagerenderingmodealwaystemplate   //  always draws a picture based on tint color, ignoring the color information of the picture.  

If you want to use the custom color of the selected chart, you need to set uiimagerenderingmodealwaysoriginal. Example: Uitabbaritem *tabbar; TabBar. SelectedImage =[[uiimage imagenamed:@ "Bar_icon.png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

  //Initialize Controllers{Fourviewcontroller*one=[[Fourviewcontroller alloc]init]; Uitabbaritem*itemone=[[uitabbaritem Alloc]initwithtitle:@"message"Image:[uiimage imagenamed:@"Btn_message_nor"] Selectedimage:[[uiimage imagenamed:@"Btn_message_sel"]imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]]; One.tabbaritem=ItemOne; [ItemOne settitletextattributes:[nsdictionary Dictionarywithobject:kdefault_coloe ForKey:        Nsforegroundcolorattributename] forstate:uicontrolstatehighlighted];    [Controllers Addobject:one]; } {Fiveviewcontroller*five=[[Fiveviewcontroller alloc]init]; Uitabbaritem*itemfive=[[uitabbaritem Alloc]initwithtitle:@"my own"Image:[uiimage imagenamed:@"Btn_me_nor"] Selectedimage:[[uiimage imagenamed:@"Btn_me_sel"] [imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]]; Five.tabbaritem=itemfive; [Itemfive settitletextattributes:[nsdictionary Dictionarywithobject:kdefault_coloe ForKey:        Nsforegroundcolorattributename] forstate:uicontrolstatehighlighted];    [Controllers addobject:five]; }

IOS Uitabbaritem Select the color of the chart, set the UIImage rendering mode

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.