Skip to content

Instantly share code, notes, and snippets.

@soffes
Created June 3, 2016 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/0f87e42f1124d875cf754a44c9150704 to your computer and use it in GitHub Desktop.
Save soffes/0f87e42f1124d875cf754a44c9150704 to your computer and use it in GitHub Desktop.
Change navigation bar border color
import UIKit
class NavigationBar: UINavigationBar {
// MARK: - Properties
var borderColor: UIColor? {
set {
borderView.backgroundColor = newValue
}
get {
return borderView.backgroundColor
}
}
private let borderView: LineView = {
let view = LineView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// MARK: - Initializers
override init(frame: CGRect) {
super.init(frame: frame)
shadowImage = UIImage()
addSubview(borderView)
NSLayoutConstraint.activateConstraints([
borderView.topAnchor.constraintEqualToAnchor(bottomAnchor),
borderView.leadingAnchor.constraintEqualToAnchor(leadingAnchor),
borderView.trailingAnchor.constraintEqualToAnchor(trailingAnchor)
])
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
@hy9be
Copy link

hy9be commented Aug 8, 2017

What is LineView?

@KwipApps
Copy link

KwipApps commented Jun 7, 2018

Use a UIView instead on a "LineView"

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