LoginSignup
2
4

More than 5 years have passed since last update.

UINavigationControllerにコードからカスタムNavigationBarとViewControllerを設定する

Posted at
1.イニシャライザでカスタムNavigationBarを指定する
let navigationController = UINavigationController(navigationBarClass: CustomNavigationBarClass.self, toolbarClass: nil)
2.RootViewControllerをセットする

UINavigationControllerにviewControllerのスタックが積まれていない時、setViewControllersメソッドに指定した1件目のViewControllerがRootViewControllerとして扱われます。

navigationController.setViewControllers([UIViewController()], animated: false)

イニシャライザがinit(rootViewController:UIViewController)init(navigationBarClass:AnyClass?, toolbarClass:AnyClass?)しか存在していないので両立は無理なのかと思っていましたが、そういうわけでもなく、setViewControllersを利用することで両立可能なのでした。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4