gpt4 book ai didi

ios - 不在导航栏上制作栏按钮项目和标题(iOS,Swift)

转载 作者:行者123 更新时间:2023-11-29 01:20:12 25 4
gpt4 key购买 nike

在我的主导航 Controller 上,有一个名为“Next Page” 的右栏按钮。按下按钮时,它会调用名为 "nextPage()" 的方法,该方法会初始化导航 Controller 并显示它。

nextPage() 的代码如下:

func nextPage() {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
let CustomLoginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("viewControllerID") as! customVC

let navVC = UINavigationController.init(rootViewController: CustomLoginVC)
navVC.view.autoresizingMask = [.FlexibleHeight, .FlexibleWidth, .FlexibleTopMargin, .FlexibleLeftMargin]

navVC.navigationBar.translucent = false
navVC.navigationItem.title = "haha"
navVC.navigationBar.tintColor = UIColor.whiteColor()
navVC.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "AvenirNext-Medium", size: 22)!, NSForegroundColorAttributeName: UIColor.whiteColor() ]
navVC.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "AvenirNext", size: 18)!], forState: UIControlState.Normal)

let backButton = UIBarButtonItem.init(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "backButtonPressedInPDF")
let exportButton = UIBarButtonItem.init(image: UIImage(named: "export"), style: UIBarButtonItemStyle.Plain, target: self, action: "saveAsPDF")

navVC.navigationItem.setLeftBarButtonItem(backButton, animated: false)
navVC.navigationItem.setRightBarButtonItem(exportButton, animated: false)
window.rootViewController = navVC
self.presentViewController(navVC, animated: true, completion: nil)
}

如您所见,我正在实例化 CustomLoginVC,它是主 Storyboard中的一种 customVCcustomVC 是 UIViewController 的子类。然后,使用 CustomLoginVC 初始化 UINavigationController 并分配左右栏按钮项。但是,标题和栏按钮项未显示在导航栏上,如下图所示。

enter image description here

我不明白为什么导航栏上没有栏按钮项目和标题。

同样在 AppDelegate 中,我设置了如下方法:

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationBar.appearance().barTintColor = UIColor(hex: "00BFA5")
application.statusBarStyle = UIStatusBarStyle.LightContent

return true
}

如有任何意见,我们将不胜感激!

最佳答案

您需要在 CustomLoginVC 上设置标题和按钮,而不是在 navVC 上设置

关于ios - 不在导航栏上制作栏按钮项目和标题(iOS,Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34704881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com