2016-09-16 2 views
1

Я пытаюсь использовать пользовательский цвет в MFMessageComposeViewController. Я думал, что это будет нормально использовать:Swift MFMessageComposeViewController оттенок и цвет фона 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: '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, которые возвращают изображение желаемого цвета

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 }

Смежные вопросы