在VC之间切换导航栏标题字体时会有一些延迟,任何帮助都会受到赞赏。
在我的mainVC上,我将viewDidLoad中的导航栏标题字体设置为:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Billabong", size: 27)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
然后,要切换回其他VC之后的普通字体,我将mainVC viewWillDisappear上的字体更改回正常状态:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "HelveticaNeue-Medium", size: 17)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
到目前为止一切都很好,newVC显示原始字体很好,但是当回到mainVC时,字体更改有一些滞后。我这样做的方法是使用显示的newVC中的viewWillDisappear,但是当它返回到mainVC时,它会显示一半标题,其中新的字体后跟......并且在一些短暂的延迟后显示标题的其余部分(例如“CoolTi ......”然后“CoolTitle”)。
我尝试在mainVC上使用viewWillAppear,同样的事情发生了,也尝试了mainVC上的viewDidAppear,字体更改的滞后性更差。不确定如何在没有延迟的情况下切换回其他字体,任何想法?感谢
[求助]谢谢@warrenm:
使用navigationItem.titleView
代替mainVC标题,在VC之间切换字体时没有延迟
代码:
let coolTitle = UILabel()
coolTitle.attributedText = NSAttributedString(string: "coolTitle", attributes: [NSFontAttributeName: UIFont(name: "Billabong", size: 27)!, NSForegroundColorAttributeName: UIColor.whiteColor()])
coolTitle.sizeToFit()
navigationItem.titleView = coolTitle