iOS development FIX: Uibarbuttonitem settitletextattributes in iOS8.1 is not valid for disabled color setting

Source: Internet
Author: User

(1) Scenario: In iOS8.1, we usually use the following statement to set the Global navigation bar button item's theme

Uibarbuttonitem *item=[uibarbuttonitem appearance]; Nsmutabledictionary *textattrs=[nsmutabledictionary dictionary];textattrs[nsforegroundcolorattributename]=[ Uicolor Orangecolor]; [item Settitletextattributes:textattrs Forstate:uicontrolstatenormal]; [item Settitletextattributes:textattrs forstate:uicontrolstatehighlighted];    Nsmutabledictionary *dtextattrs=[nsmutabledictionary Dictionarywithdictionary:textattrs];d textattrs[ Nsforegroundcolorattributename]=[uicolor Graycolor]; [item Settitletextattributes:dtextattrs forstate:uicontrolstatedisabled];


(2) The problem is that we clearly set the properties (normal,highlighted and disabled) on the item in various States, but when we add an item to a controller and set it to the disabled state, we find that it does not work.

-(void) setupnavbar{    self.navigationitem.rightbarbuttonitem=[[uibarbuttonitem alloc]initwithtitle:@ "send" style : Uibarbuttonitemstyledone target:self Action: @selector (send)];    Self.navigationitem.rightbarbuttonitem.enabled=no;}


(3) Solutions

Place the above statement set to Disabled in Viewwillappear.

-(void) Viewwillappear: (BOOL) animated{    [Super viewwillappear:animated];    If the following sentence is written in viewdidload, disabled's item color has no effect    self.navigationitem.rightbarbuttonitem.enabled=no;}


(4) As to why this is so? To tell the truth, I'm not quite sure what I thought was the reason for the call order (normal test order), which was later thought to be viewdidload in the enabled unassigned (but the test is 0 and has an assignment). Please advise me if you have the understanding. Think of it as a bug in iOS8.1. It is normal to test in iOS7.1.

iOS development FIX: Uibarbuttonitem settitletextattributes in iOS8.1 is not valid for disabled color setting

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.