srk72

Custom Navigation

May 20th, 2022 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.96 KB | None | 0 0
  1. final class CustomNavigation: UIView {
  2.    
  3.     @IBOutlet weak var leftBarBut2: UIButton!
  4.     @IBOutlet var navView: UIView!
  5.     @IBOutlet weak var backBut: UIButton!
  6.     @IBOutlet weak var leftBarBut: UIButton!
  7.     @IBOutlet weak var largeTitle: UILabel!
  8.     @IBOutlet weak var smallTitle: UILabel!
  9.    
  10.     var title: String = "" {
  11.         didSet {
  12.             largeTitle.text = title
  13.         }
  14.     }
  15.    
  16.     var subTitle: String = "" {
  17.         didSet {
  18.             smallTitle.text = subTitle
  19.         }
  20.     }
  21.    
  22.     var isSubTitleHidden: Bool {
  23.         set {
  24.             smallTitle.isHidden = newValue
  25.         }
  26.         get {
  27.             return smallTitle.isHidden
  28.         }
  29.     }
  30.    
  31.     var isBackButtonHidden: Bool {
  32.         set {
  33.             backBut.isHidden = newValue
  34.         }
  35.         get {
  36.             return backBut.isHidden
  37.         }
  38.     }
  39.    
  40.     var isLeftBarButtonHidden: Bool {
  41.         set {
  42.             leftBarBut.isHidden = newValue
  43.         }
  44.         get {
  45.             return leftBarBut.isHidden
  46.         }
  47.     }
  48.    
  49.     var isLeftBarButton2Hidden: Bool {
  50.         set {
  51.             leftBarBut2.isHidden = newValue
  52.         }
  53.         get {
  54.             return leftBarBut2.isHidden
  55.         }
  56.     }
  57.    
  58.     override func awakeFromNib() {
  59.         self.clipsToBounds = true
  60.         initWithNib()
  61.     }
  62.    
  63.     private func initWithNib() {
  64.         Bundle.main.loadNibNamed("CustomNavigation", owner: self, options: nil)
  65.         navView.translatesAutoresizingMaskIntoConstraints = false
  66.         addSubview(navView)
  67.         setupLayout()
  68.     }
  69.    
  70.     private func setupLayout() {
  71.         NSLayoutConstraint.activate([
  72.             navView.topAnchor.constraint(equalTo: topAnchor),
  73.             navView.leadingAnchor.constraint(equalTo: leadingAnchor),
  74.             navView.bottomAnchor.constraint(equalTo: bottomAnchor),
  75.             navView.trailingAnchor.constraint(equalTo: trailingAnchor)
  76.         ])
  77.     }
  78.    
  79. }
  80.  
Add Comment
Please, Sign In to add comment