Skip to content

Instantly share code, notes, and snippets.

@efremidze
Created June 9, 2017 21:25
Show Gist options
  • Save efremidze/396b65b2196bb1835fbdf03b4587c50c to your computer and use it in GitHub Desktop.
Save efremidze/396b65b2196bb1835fbdf03b4587c50c to your computer and use it in GitHub Desktop.
extension UINavigationBar {
var barColor: UIColor? {
get { return self.backgroundView.backgroundColor }
set { self.backgroundView.backgroundColor = newValue }
}
private var backgroundView: UIView {
return self.subviews.filter { $0 is TransparentView }.first ?? {
let statusBarHeight = UIApplication.shared.isStatusBarHidden ? 20 : UIApplication.shared.statusBarFrame.height
$0.frame = self.bounds
$0.frame.origin.y -= statusBarHeight
$0.frame.size.height += statusBarHeight
self.insertSubview($0, at: 0)
return $0
}(TransparentView())
}
}
class TransparentView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let view = super.hitTest(point, with: event)
if view == self { return nil }
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment