Create a “Flaming-Hot” Navigation Bar in Swift in less than 10 seconds

Lawrence Tan
Swift2Go
Published in
1 min readAug 12, 2018

Gradient has been a popular way of filling UI elements to enhance the look and feel of the app.

Here, is a short demo of how you can fill your navigation bar with a gradient color using native CAGradientLayer. This is an advantage over using image assets in cases where designers just want to adjust it to a lighter color, they need not generate new image assets, but just providing you the color code (rgb/hex) is sufficient.

Here is a popular website I use to preview gradient colors and convert it to rgb (or you could just use UIColor extension to throw in hex support) :

The main code here is really extending our CAGradientLayer like this :

Then just apply it to your viewcontroller!

You should not get a beautiful gradient-ed navigation bar!

--

--

Lawrence Tan
Swift2Go

Googler. Loves God, Loves my wife, Loves my Family & Corgis.