Reputation: 53
I've created my own navigation bar:
let height = 100
let navbar = UINavigationBar()
navbar.frame.size.width = UIScreen.main.bounds.size.width
navbar.frame.size.height = CGFloat(height)
navbar.frame = CGRect(x: 0,
y: 0,
width: navbar.frame.size.width,
height: navbar.frame.size.height)
navbar.barTintColor = Colors.schedulerDarkGray
navbar.titleTextAttributes = [.foregroundColor: Colors.schedulerBlue!]
navbar.tintColor = Colors.schedulerBlue
let navItem = UINavigationItem()
navItem.title = "Add employee"
navItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancel))
navbar.items = [navItem]
view.addSubview(navbar)
self.view?.frame = CGRect(x: 0, y: height, width: Int(UIScreen.main.bounds.width), height: (Int(UIScreen.main.bounds.height) - height))
I don't know why I can't set my own height. I can change the x and y position, and width as well.
When I see it in Debug View Hierarchy, it looks like
Do you have any idea why it doesn't work as it should?
Upvotes: 1
Views: 6507
Reputation: 53
I have found solution:
I added this line in view controller ViewDidLoad
self.additionalSafeAreaInsets.top = height
This helped me: https://developer.apple.com/forums/thread/88202#274620
Upvotes: 3