Below code works on iOS version 9.x or less, for some reason this does not work if iOS 10
if([MFMessageComposeViewController canSendText])
{
Issue
Solution
UINavigationBar.appearance()
to change the navigation bar colour.backgroundColor
property & setBackgroundImage(_:for:)
method to fix the navigation bar colour.Code
/// 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)
}
}
Hope it helps!.