I want to set the UINavigationbar
backgroundColor
to a gradient color where I would like to set it via an array of colors to create a Gradient, ideally, as accessible methods inside UINavigationBar
to change its color to this gradient.
Any suggestions? (Aside from setting an image manually as the background image of the navigation bar)
Create gradient layer and add it as background of navigation bar.
For creating image from layer.
One more thing, there is one library available in github : CRGradientNavigationBar you can also use this library.
In Swift 3 and Swift 4:
For creating image from layer:
In Swift 2:
For creating image from layer:
In Swift 3
Objective C solution that works on iPhone X as well:
For Swift 4.2
How to use
Details
Xcode 8.3.1, Swift 3.1
Code
Usage
Result