colors - iOS 10不再能够在MFMessageComposeViewController上设置barcolor和tint

标签 colors uinavigationbar mfmessagecomposeview

以下代码可在iOS 9.x或更低版本上运行,由于某些原因,如果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];
             }

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

编辑:
我试图在一个新的空单 View 项目上使用一些测试代码,但遇到了同样的问题。
@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的导航栏,因为它显示白色背景和白色文本。无法更改文本颜色或背景颜色会使该 View 不可用。

最佳答案

问题

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

  • 解决方案
  • 使用UINavigationBar.appearance()更改导航栏颜色。
  • 使用backgroundColor属性和setBackgroundImage(_:for:)方法固定导航栏的颜色。

  • 代码
    /// 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)
        }
    }
    

    希望能帮助到你!。

    关于colors - iOS 10不再能够在MFMessageComposeViewController上设置barcolor和tint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39453933/

    相关文章:

    css - 无法悬停以更改文本颜色

    UINavigationController 和 UISearchBar 之间的 iOS 9 细线

    ios - 文本 UIButton 周围的边框

    ios - 适用于iOS的自定义颜色选择器

    安卓颜色配置文件?

    ios - 自定义 iOS UINavigationBar/UITabBar 和移除 Tint Colors

    ios - UINaviguationBar底部阴影消失

    iphone - 如何在iPhone设备上发送消息?

    ios - iOS-广播SMS(将SMS发送给多个收件人,而不是作为一组MMS?)