以下代码适用于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]; }
是破坏还是做了一些改变.不知道这里丢失什么我在黑暗中(黑色黑色)
编辑:
我试图在一个新的空单视图项目上使用一些测试代码,我遇到了同样的问题.
@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的导航栏,因为它出现了白色背景和白色文本.无法更改文本颜色或背景颜色,使此视图不可用.
解决方法
在iOS 10之前,我正在使用UINavigationBar的外观代理,像这样:
NSDictionary* titleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourNavBarTitle,NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle }; [[UINavigationBar appearance] setBarTintColor:[ColoursAndStyles sharedInstance].viewColourNavBarMain]; [[UINavigationBar appearance] setTintColor:[ColoursAndStyles sharedInstance].viewColourNavBarTint]; [[UINavigationBar appearance] setTitleTextAttributes:titleAttribs];
这覆盖了我对MFMessageComposeViewController的使用,其中setTitleTextAttributes处理标题/标题的文本颜色.
使用iOS 10,我正在使用以下工作.在我提交MFMessageComposeViewController之前,我更改标题文本属性.例如.:
- (void)sendTap:(id)s { // some code... NSDictionary* newTitleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourTitleStrip,NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle }; [[UINavigationBar appearance] setTitleTextAttributes:newTitleAttribs]; // present the MFMessageComposeViewController... }
然后,当MFMessageComposeViewController完成时,将其重新设置为我想要的应用程序的其余部分,例如:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { NSDictionary* titleAttribs = @{ NSForegroundColorAttributeName: [ColoursAndStyles sharedInstance].fontColourNavBarTitle,NSFontAttributeName: [ColoursAndStyles sharedInstance].fontNavbarBoldTitle }; [[UINavigationBar appearance] setTitleTextAttributes:titleAttribs]; // some code... [controller dismissViewControllerAnimated:YES completion:^{ // some code... }]; }