Tint Color works with native colors but not with the color from pattern image

259 Views Asked by At

I am theaming the navigation bar back button with the navigation bar tint color it works when I use native colors and it fails when I use custom color from an image.

working code :

self.navigationController?.navigationBar.tintColor = UIColor.orange

Not working code:

let color = UIColor.init(patternImage: someImage)
self.navigationController?.navigationBar.tintColor = color

Can someone show some light?

2

There are 2 best solutions below

3
JAINESH DOSHI On

If you have a image then please set image in navigationbar as a background image. Like :

self.navigationController?.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "NavigationBackground"), for: .default)

Hope this is helpful.

1
Suhas Aithal On

You cannot use pattern color for tint color.

Refer the following link: https://developer.apple.com/documentation/uikit/uiview/1622467-tintcolor

look for this note:

Important

If you attempt to use a pattern color as a tint color, the system raises an exception.