2017-01-03 38 views
0

有時,發送和取消按鈕顯示爲白色,因此它們在MFMailComposeViewController上的白色背景上幾乎不可見。將發送和取消按鈕設置爲MFMailComposeViewController中的白色背景上的其他顏色

extension MFMailComposeViewController { 
    override public func viewWillAppear(animated: Bool) {   
     super.viewWillAppear(animated) 
     UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent 
    } 

    override public func viewWillDisappear(animated: Bool) { 
     super.viewWillDisappear(animated) 
     UINavigationBar.appearance().barTintColor = UIColor.blackColor() 
    } 

    override public func viewDidLoad() { 
     UINavigationBar.appearance().barTintColor = UIColor.redColor() 
     navigationBar.barTintColor = UIColor.blueColor() 
     super.viewDidLoad() 
     navigationBar.translucent = false 
     navigationBar.opaque = false 
    } 
} 

如何設置上的MFMailComposeViewController按鈕的默認顏色:MFMailComposeViewController的實例按下與dataDetectorTypes。鏈路一個UITextView,所以我不能立即訪問之前在viewDidLoad中函數實例見下文之後創建並避免弄亂了應用程序其餘部分的導航欄?

因爲它現在barTintColor沒有設置第一次進入。但第二次繞着它設置爲blackColor,我猜從前一個實例的viewWillDisappear調用。

+0

Didi你試着把它放在'UINavigationController'(它已經按照你需要的樣式),然後呈現它?即使您在應用中使用了不同的「UINavigationController」,也可以爲「MFMailSomposeViewController」創建另一個。 – NSDmitry

回答

0

我所做的就是趕上從TextView的網址交互設置委託,然後將tintColor設置爲導航欄,並設置爲defaultTintColor。

extension ContactViewController: UITextViewDelegate { 
    func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool { 
     if URL.absoluteString.containsString("mailto:") { 
      let mailVC = MFMailComposeViewController() 
      let emailString = URL.absoluteString.stringByReplacingOccurrencesOfString("mailto:", withString: "") 
      mailVC.setToRecipients([emailString]) 
      mailVC.mailComposeDelegate = self 
      let defaultTintColor = UIColor(red: 0.0, green: 122/255, blue: 1.0, alpha: 1) 
      mailVC.navigationBar.tintColor = defaultTintColor 
      mailVC.navigationBar.translucent = false 
      mailVC.navigationBar.opaque = false 
      self.presentViewController(mailVC, animated: true, completion: nil) 
      return false 
     } 
     else if URL.absoluteString.containsString("tel") { 
      if let url = NSURL(string: URL.absoluteString) where UIApplication.sharedApplication().canOpenURL(url) { 
       return true //let the system handle with a telprompt 
      } 
     } 
     return false 
    } 
} 

extension ContactViewController: MFMailComposeViewControllerDelegate { 
    func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) { 
     switch result.rawValue { 
     case MFMailComposeResultCancelled.rawValue: 
      print("Mail cancelled") 
     case MFMailComposeResultSaved.rawValue: 
      print("Mail saved") 
     case MFMailComposeResultSent.rawValue: 
      print("Mail sent") 
     case MFMailComposeResultFailed.rawValue: 
      if let error = error { 
       print("Mail sent failure: %@", [error.localizedDescription]) 
      } 
     default: 
      break 
     } 
     self.dismissViewControllerAnimated(true, completion: nil) 
    } 
} 
1

起初,如果你有一個UINavigationController故事板設置着色顏色有你的UINavigationBar的..不使用 UINavigationBar.appearance()。barTintColor = UIColor.blackColor()

只有一個每個UINavigationController的

你不能處理所有案件醜陋的外表工具你的顏色的導航欄。一些控制器(MailComposer,PhotoRoll,...)使用黑色的BarButton,有些色彩爲白色。

如果您正在使用的外觀......所有的酒吧都影響(僅適用於新創建的酒吧,而不是在內存中的)

+0

我放棄使用MFMailComposeViewController的擴展。通過手動配置mailComposeVC的實例,手動連接.Link交互。 – user12345625

相關問題