I'm trying to learn how to programmatically create the UI of my application. I added to the application a navigation controller with code, this is the code:
AppDelegate:
var window: UIWindow?
var navigationController: UINavigationController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
if let window = window{
let mainVC = MainVC()
navigationController = UINavigationController(rootViewController: mainVC)
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
return true
}
And this is my mainVC:
class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = UIColor.blue
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.title = "Hello"
setupTextBox()
// Do any additional setup after loading the view, typically from a nib.
}
let textBox: UITextField = {
var tBox = UITextField(frame: CGRect(x: 100, y: 100, width: 200, height: 30))
tBox.placeholder = "Please Enter Name"
tBox.textAlignment = .center
tBox.borderStyle = .roundedRect
tBox.backgroundColor = UIColor.red
return tBox
}()
private func setupTextBox(){
view.addSubview(textBox)
}
}
The navigation bar does appear but it is huge, couldn't find a way to view it as it should be. This is the image of the navigation bar:
What am I doing wrong?