我有一个自定义导航栏 View ,因此我可以向每一侧添加多个栏按钮。因此,我想自动缩小导航栏标题而不是截断它。我无法弄清楚如何使用我正在使用的以下代码执行此操作。
navBar = UINavigationBar(frame: CGRectMake(0, 20, UIScreen.mainScreen().bounds.size.width, 44))
navBar.barTintColor = UIColor.blackColor() // Sets bar to black
navBar.translucent = false
self.view.addSubview(navBar)
navItem = UINavigationItem(title: "A Pretty Long String")
navBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 25)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
最佳答案
你可以调用这个函数
override func viewDidLayoutSubviews() {
println(self.view.frame.size)
println(self.view.navBar.frame.size)
}
并在该函数中更改您在 NSFontAttributeName 函数中用于字体大小的变量
关于swift - 自定义导航栏标题自动缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31439354/