UIBarButtonItem color is not working

I recently noticed that the behavior of the property tintColorhas changed significantly in one of the latest iOS 10 updates.

I had code that worked fine earlier and which now doesn't work at all.

In one of my applications, I have a collection UIBarButtonItemthat are added to the toolbarItemsview controller array . They are displayed well.

However, at some point I want to change the hue of some elements in response to a user action. The code is trivial:

flagButton.tintColor = [UIColor redColor];

This code used to work, but now it doesn't work! I checked that there is a link to UIBarButtonItemand that line of code is being executed. However, the color of the hue does not change as it should.

The property description tintColorsays:

To update the subview rendering when this property changes, override the tintColorDidChange () method.

I tried adding a method tintColorDidChange, but it is not being called. My guess at this point is that after the change, tintColormy button does not automatically update.

Has anyone found a way to update it manually? The button is standard UIBarButtonItemwith the image.

Update 1

In fact, I noticed that if I changed tintColorthe toolbar instead of a separate item, the code works. It seems that for some reason, setting the hue color to individual objects no longer works. Does anyone know why this is so?

Update 2

Thanks to the matte prompt, I was able to find the source of the problem. This was caused by the code executed when the application started:

[[UITableViewCell appearance] setTintColor:[ColourTheme sharedTheme].navBackground];

, UIBarButtonItem... , UIAppearance. , , . , , , , , .

, - , , .

+4
4

- . , ; tintColor :

enter image description here

        let c = self.replyButton.tintColor
        if c == UIColor.red {
            self.replyButton.tintColor = .green
        } else {
            self.replyButton.tintColor = .red
        }

, , , - , .

+1

,

UIActivityIndicatorView.appearance.tintColor = FlatWhite;

set in didFinishLaunchingWithOptions UIBarItemItems.tintColor , , ...

, , , . IOS. , .

+1

, UIImageRenderingMode.alwaysOriginal, .

public enum UIImageRenderingMode : Int {

     case automatic // Use the default rendering mode for the context where the image is used
     case alwaysOriginal // Always draw the original image, without treating it as a template
     case alwaysTemplate // Always draw the image as a template image, ignoring its color information

}

.alwaysTemplate

0

, :

1) . "closeButton" 2) :

override func viewWillAppear(animated: Bool) {
  let barButtonAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
  closeButton.setTitleTextAttributes(barButtonAttributes, for: .normal)
}

viewWillAppear, UIAppearance.

0

Source: https://habr.com/ru/post/1667264/


All Articles