gpt4 book ai didi

添加 UINavigationBar 时 Swift 约束错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:05:29 25 4
gpt4 key购买 nike

我正在尝试向我的应用添加自定义导航栏,但每当它加载时,我都会收到“无法同时满足约束”错误。我似乎无法以编程方式删除任何约束 - 而且我绝对没有添加任何约束。

控制台输出:

"<NSLayoutConstraint:0x600000092750 UILabel:0x7ffc40507d20'Configure'.firstBaseline == UILayoutGuide:0x6000007b18e0'TitleView(0x7ffc40503120)'.top + 23   (active)>",
"<NSLayoutConstraint:0x600000092840 UILabel:0x7ffc40507d20'Configure'.top >= UILayoutGuide:0x6000007b18e0'TitleView(0x7ffc40503120)'.top (active)>"

应用委托(delegate):

self.window = UIWindow(frame: UIScreen.main.bounds)
let nav1 = UINavigationController(navigationBarClass: CustomNavBar.self, toolbarClass: nil)
let mainView = TableViewController()
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window!.makeKeyAndVisible()

自定义导航栏类​​:

self.frame.size.height = 60
self.backgroundColor = appColour
self.tintColor = UIColor.white
self.titleTextAttributes = [
NSForegroundColorAttributeName : UIColor.white,
NSFontAttributeName : UIFont(name: "Avenir-Heavy", size: 30)!
]
self.setTitleVerticalPositionAdjustment(-5, for: .default)

View Controller :

navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(start))
navigationItem.rightBarButtonItem!.imageInsets = UIEdgeInsets(top: -7, left: 0, bottom: 0, right: 0)
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "Folder")!, style: .plain, target: self, action: #selector(viewSaved))
navigationItem.leftBarButtonItem!.imageInsets = UIEdgeInsets(top: -7, left: 0, bottom: 0, right: 0)
self.title = "Configure"

我只是不知道该怎么办。

提前致谢!

最佳答案

问题出在您的 CustomNavBar 类中的字体大小,减小字体大小直到您没有收到约束错误。

self.titleTextAttributes = [
NSForegroundColorAttributeName : UIColor.white,
NSFontAttributeName : UIFont(name: "Avenir-Heavy", size: <30>)!
]

关于添加 UINavigationBar 时 Swift 约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48323618/

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