iOS 10不再可以在MFMessageComposeViewController上设置barcolor和tint [英] iOS 10 can no longer set barcolor and tint on MFMessageComposeViewController

查看:140
本文介绍了iOS 10不再可以在MFMessageComposeViewController上设置barcolor和tint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码可在iOS 9.x或更低版本上运行,由于某些原因,如果iOS 10则无法运行

Below code works on iOS version 9.x or less, for some reason this does not work if iOS 10

 if([MFMessageComposeViewController canSendText])
             {
                 controller.body = message;
                 NSString *tel = pContact.tlc;
                 controller.recipients = pContact.tlc?@[tel]:nil;
                 controller.messageComposeDelegate = self;
                 controller.navigationBar.tintColor = [UIColor whiteColor];
                 controller.navigationBar.barTintColor = [UIColor blueColor];
                 [self presentViewController:controller animated:YES completion:nil];
             }

是坏了还是有什么变化.不知道这里缺少什么.我在黑暗中(漆黑)

is it broken or did some thing change. Not sure whats missing here. I am in the dark (pitch black)

我试图在一个新的空单视图项目上使用一些测试代码,但遇到了同样的问题.

I tried to use some test code on a new empty single view project and I am getting the same problems.

@IBAction func SMS(_ sender: AnyObject) {
        let composeVC = MFMessageComposeViewController()
        composeVC.messageComposeDelegate = self

        // Configure the fields of the interface.
        composeVC.recipients = ["5555555555"]
        composeVC.body = "Hello from California!"
        composeVC.navigationBar.tintColor = UIColor.green
        composeVC.navigationBar.barTintColor = UIColor.purple
        // Present the view controller modally.
        self.present(composeVC, animated: true, completion: nil)
    } 

UINavigationBar的外观可以在测试应用程序中为背景或barTint设置颜色,但是我仍然无法为测试应用程序设置文本颜色.我正在使用的应用程序已经使用UINavigationBar外观设置了整个应用程序中的导航栏颜色,但这不会影响SMS的导航栏,因为它显示白色背景和白色文本.无法更改文本颜色或背景颜色会使该视图不可用.

UINavigationBar appearance can set the color in a test App for the background or barTint but I am still unable to set the text color for the test app. The app I am working on uses the UINavigationBar appearance already to set the navbar color across the app, but this is not affecting the navbar for the SMS as it come up white background and white text. not able to change the text color or background color make this view un-usable.

推荐答案

问题

  • 由于iOS10.x中的某些原因, barTintColor 不适用于某些共享容器.
  • 但是有一种解决方法可以修复所有共享容器上的导航栏颜色.

解决方案

  • 使用UINavigationBar.appearance()更改导航栏颜色.
  • 使用backgroundColor属性& setBackgroundImage(_:for:)固定导航栏颜色的方法.
  • Use UINavigationBar.appearance() to change the navigation bar colour.
  • Use backgroundColor property & setBackgroundImage(_:for:) method to fix the navigation bar colour.

代码

/// Method to set navigation bar color
func setNavigationBar() -> Void
{
    // barTintColor will apply color for the app's navigation bar
    UINavigationBar.appearance().barTintColor       = UIColor.blue

    // backgroundColor will apply color for some of the sharing container's app except for Messages app
    UINavigationBar.appearance().backgroundColor    = UIColor.blue

    // backgroundImage will apply the color image for navigation bar for most of the sharing container's except for `Notes`
    UINavigationBar.appearance().setBackgroundImage(UIImage(color: UIColor.blue), for:UIBarMetrics.default)
}

/// UIImage extension to create an image from specified color
extension UIImage
{
    public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
        let rect = CGRect(origin: .zero, size: size)
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
        color.setFill()
        UIRectFill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        guard let cgImage = image?.cgImage else { return nil }
        self.init(cgImage: cgImage)
    }
}

希望有帮助!.

这篇关于iOS 10不再可以在MFMessageComposeViewController上设置barcolor和tint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆