简体   繁体   中英

iOS - Tint color changes when pressing back

I set global tint color to blue in storyboard, everything is OK, but when pressing back button, some items such as navigation icons or bar segmented controls change to grey. This issue just happens in iOS7.

I know the question is quite general, but I don't know which part of the code is causing this issue. Hopefully, someone has faced into similar problem and could share their idea.

Many thanks.

I think tintAdjustmentMode(UIView property) is causing this problem. Try setting tintAdjustmentMode of window to UIViewTintAdjustmentModeNormal.

In your delegate:

self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;

Add this piece of code to the segment:

self.segmentedControl.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;    

If this works you should check your code if you made anything wrong with adding or removing Views. I guess the problem is that you don't make it the right way and because of that it sets a gray color to the segmentedControl as it does when a popover or sheet is presented.

I had the same problem in my current project. Well, since you did not provide any code I'll try my best to explain it to you. Make sure that the tint color is set in every view controller that you want it on. For Example, I had the same error and it was happening because I set the tint color in one view controller and forgot it in another one. So whenever I segue to the second view controller where the tint color was not set, it sets the whole thing to that color. So when I return to the original view controller, it changes color of the second view controller. I hope this makes sense to you, if not please tell me and I can rephrase it for you.

This is the just simple problem. you are facing problem with inherit color that loads first after that your blue color load.you can see their property color. that have default color set gray

This may be a good case for appearance proxies . You can do something like…

[[UISegmentedControl appearance] setTintColor:[UIColor redColor]];

…to make every instance of UISegmentedControl the same color by default. Bear in mind that UIAppearance styles are applied at runtime.

you can manually override this property for any of those subviews and its descendants. In other words, each view inherits its superview's tint color if its own tint color is nil. If the highest level view in the view hierarchy has a nil value for tint color, it defaults to the system blue color .you write this code in the screen 1 and screen 2.

self.view.tintColor = [UIColor redColor];

In some cases setting the tintAdjustmentMode to the window or controller's view is not enough, surely because some view in the hierarchy overrides the value. Then you have to manually set the concerned view's tint mode.

If you're like me and try to use Interface Builder as much as possible you can use Runtime Attributes:

在此处输入图片说明

The value 1 comes from the mode's definition:

enum UIViewTintAdjustmentMode : Int {

    case Automatic

    case Normal
    case Dimmed
}

Where, unless set otherwise, the cases are assigned numbers starting from 0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM