Swift UIActivityViewController电子邮件主题行继承全局UINavigationBar字体更改

时间:2017-11-09 16:06:13

标签: swift uiactivityviewcontroller

我使用以下内容更改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)]

        })
    }

enter image description here

1 个答案:

答案 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)]
      }
 })