gpt4 book ai didi

ios - swift - UINavigationController 扩展不工作

转载 作者:行者123 更新时间:2023-11-28 08:28:57 24 4
gpt4 key购买 nike

我将在不同 View Controller 中的所有导航 Controller 上使用类似的属性,除了一些导航项和显然的标题。

我做了一个扩展计划,以便能够调用它并设置我的默认值;但是,它什么也没做。当我将代码简单地放在实际类中时代码确实有效,但当我调用 SetDefaults 时却无效。

扩展:

extension UINavigationController {
func setDefaults(titleText: String){
let appDel = UIApplication.sharedApplication().delegate as! AppDelegate

//Set title label
let label = UILabel()
label.font = UIFont(name: appDel.regularDefaultFont, size: 16)
label.text = titleText
label.kern(1.0)
label.sizeToFit()
self.navigationItem.titleView = label

//Set white background tint color
self.navigationBar.barTintColor = UIColor.whiteColor()

//Set navigation bar bottom line
let bottomBorderRect = CGRect(x: 0, y: UIScreen.mainScreen().bounds.height, width: UIScreen.mainScreen().bounds.width, height: 1)
let bottomBorderView = UIView(frame: bottomBorderRect)
bottomBorderView.backgroundColor = UIColor(r: 250, g: 250, b: 250)
self.navigationBar.addSubview(bottomBorderView)
}
}

使用导航 Controller 从类中调用 SetDefaults:

self.navigationController.SetDefaults("Login")

最佳答案

在您的 Storyboard 中,您应该选择 Segue type to show 同时将一个 View Controller 连接到另一个或者简单地选择你的 segue > in attributes inspector > storybook segue > kind > show (e.g) push。如图所示

enter image description here

它将永久解决问题:)

关于ios - swift - UINavigationController 扩展不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39309031/

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