Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import UIKit
private var flatAssociatedObjectKey: UInt8 = 0
An extension that adds a "flat" field to UINavigationBar. This flag, when
enabled, removes the shadow under the navigation bar.
@IBDesignable extension UINavigationBar {
@IBInspectable var flat: Bool {
get {
guard let obj = objc_getAssociatedObject(self, &flatAssociatedObjectKey) as? NSNumber else {
return false
return obj.boolValue
set {
if (newValue) {
let void = UIImage()
setBackgroundImage(void, for: .any, barMetrics: .default)
shadowImage = void
} else {
setBackgroundImage(nil, for: .any, barMetrics: .default)
shadowImage = nil
NSNumber(value: newValue as Bool),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment