Skip to content

Instantly share code, notes, and snippets.

@siberianisaev
Last active October 30, 2019 07:57
Show Gist options
  • Select an option

  • Save siberianisaev/4fa28cb830d51d4b5803 to your computer and use it in GitHub Desktop.

Select an option

Save siberianisaev/4fa28cb830d51d4b5803 to your computer and use it in GitHub Desktop.
Change height of UINavigationBar
import Foundation
private var AssociatedObjectHandle: UInt8 = 0
extension UINavigationBar {
var height: CGFloat {
get {
if let h = objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat {
return h
}
return 0
}
set {
objc_setAssociatedObject(self, &AssociatedObjectHandle, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}
}
override public func sizeThatFits(size: CGSize) -> CGSize {
if self.height > 0 {
return CGSizeMake(self.superview!.bounds.size.width, self.height);
}
return super.sizeThatFits(size)
}
}
@annjawn

annjawn commented Dec 14, 2017

Copy link
Copy Markdown

What is the usage for this? Where should I put the height?

@AlexanderBollbach

Copy link
Copy Markdown

what is the usage for this?

ghost commented Oct 30, 2019

Copy link
Copy Markdown

Dosen't work with iOS 13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment