2016-09-16 81 views
1

我想在MFMessageComposeViewController中使用自定義顏色。我認爲它可以使用:Swift MFMessageComposeViewController tint和背景顏色iOS 10

@IBAction func sendMessage(sender: AnyObject) { 
    let messageVC = MFMessageComposeViewController() 
    messageVC.body = "Enter a message"; 
    messageVC.recipients = [phoneString] 
    messageVC.messageComposeDelegate = self; 
    //color 
    UINavigationBar.appearance().barTintColor = UIColor(hexString: "fec13e") 
    UINavigationBar.appearance().tintColor = UIColor.whiteColor() 

    self.presentViewController(messageVC, animated: false, completion: nil) 
} 

但它不工作。

+0

嘗試的圖像之前呈現messageVC的FUNC:'messageVC.navigationBar.tintColor = UIColor.whiteColor()'和'messageVC.navigationBar.barTintColor = UIColor.blueColor()' – TonyMkenu

+1

@TonyMkenu我做了您的評論。但它不適合我。 xcode8/swift3 – user2809312

+1

任何解決方案?我也面臨同樣的問題 –

回答

0

您可以使用下面的代碼更改MFMessageComposeViewController導航顏色的顏色。

let size = CGSize(width: (self.window?.frame.size.width)!, height: 64) let image = self.getImageWithColor(UIColor .init(colorLiteralRed: 40.0/255.0, green: 140.0/255.0, blue: 204.0/255.0, alpha: 1.0), size:size) UINavigationBar.appearance().setBackgroundImage(image.resizableImage(withCapInsets: UIEdgeInsets.zero, resizingMode: .stretch), for: .default)

getImageWithColor是返回期望的顏色

func getImageWithColor(_ color: UIColor, size: CGSize) -> UIImage { let rect = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size.width, height: size.height)) UIGraphicsBeginImageContextWithOptions(size, false, 0) color.setFill() UIRectFill(rect) let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return image }