簡體   English   中英

Swift MFMessageComposeViewController色調和背景色iOS 10

[英]Swift MFMessageComposeViewController tint and background color iOS 10

我試圖在MFMessageComposeViewController使用自定義顏色。 我認為可以使用:

@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)
}

但它不起作用。

您可以使用以下代碼更改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

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 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM