我使用以下内容更改UINavigationBar
字体的大小和重量:
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
UINavigationBar.appearance().titleTextAttributes = [ NSAttributedStringKey.font: UIFont.systemFont(ofSize: 28, weight: .heavy)]
当我出示UIActivityViewController
并选择邮件时,标题中的主题行(不是电子邮件)会继承字体更改。为了改变这种情况,我将UINavigationBar
改回了更小的东西。
虽然这有效,并且标题中的主题行较小,现在可读,但当UIActivityViewController
返回时,UINavigationBar
字体仍然设置为新的大小和重量。我尝试按照下面的方式完成,但字体没有调整大小。
@objc func showActivityViewController() {
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
UINavigationBar.appearance().titleTextAttributes = [ NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17, weight: .thin)]
present(activityViewController, animated: true, completion: {
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
UINavigationBar.appearance().titleTextAttributes = [ NSAttributedStringKey.font: UIFont.systemFont(ofSize: 28, weight: .heavy)]
})
}
答案 0 :(得分:0)
我以类似的方式更改UIButton
的字体颜色。我发现使用主线程有帮助。试试这个,看它是否有效:
present(activityViewController, animated: true, completion: {
DispatchQueue.main.async {
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 28, weight: .heavy)]
}
})