Pas*_*lac 21 colors uinavigationbar mfmessagecomposeviewcontroller
下面的代码适用于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];
}
Run Code Online (Sandbox Code Playgroud)
它是破碎还是做了一些改变.不知道这里遗漏了什么.我在黑暗中(漆黑)
编辑:我试图在一个新的空单视图项目上使用一些测试代码,我遇到了同样的问题.
@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)
}
Run Code Online (Sandbox Code Playgroud)
编辑:UINavigationBar外观可以在测试应用程序中为背景或barTint设置颜色,但我仍然无法设置测试应用程序的文本颜色.我正在使用的应用程序已使用UINavigationBar外观在应用程序中设置导航栏颜色,但这不会影响SMS的导航栏,因为它出现白色背景和白色文本.无法更改文本颜色或背景颜色使此视图无法使用.
Tes*_*089 11
问题
解
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)
}
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!.