MFMailComposeViewController栏的背景颜色在iOS7中不变
我试图改变在iOS7 MFMailComposeViewController
的背景颜色 ,但我不能让它的工作。
我正在使用以下剪切:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; if([picker.navigationBar respondsToSelector:@selector(barTintColor)]) { // iOS7 picker.navigationBar.barTintColor = READER_NAVIGATION_BAR_BACKGROUND_COLOR; // Set back button arrow color [picker.navigationBar setTintColor:READER_NAVIGATION_BAR_BACK_BUTTON_ARROW_COLOR]; // Set Navigation Bar Title Color [picker.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:READER_NAVIGATION_BAR_TITLE_NORMAL_FONT_COLOR forKey:UITextAttributeTextColor]]; // Set back button color [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:READER_NAVIGATION_BAR_BUTTONS_FONT_COLOR, UITextAttributeTextColor,nil] forState:UIControlStateNormal]; }
有谁知道如何更改iOS7中的MFMailComposeViewController
的bakcground颜色?
尝试这个。 为我工作。
MFMailComposeViewController* myailViewController = [[MFMailComposeViewController alloc] init]; // set other attributes of mailcomposer here. myMailViewController.mailComposeDelegate = self; [myMailViewController.navigationBar setTintColor:[UIColor whiteColor]]; [self presentViewController:myMmailViewController animated:YES completion:nil];
这里的诀窍是调用“外观方法”,如
[UINavigationBar appearance].barTintColor = [UIColor whiteColor]; [UINavigationBar appearance].tintColor = [UIColor redColor];
在打电话之前
[[MFMailComposeViewController alloc] init];
这样的配色scheme将被应用到邮件composer php。 它可能会返回到默认值在mailComposeController:didFinishWithResult:
Swift 3解决scheme:
extension MFMailComposeViewController { override open func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent } open override func viewDidLoad() { super.viewDidLoad() navigationBar.isTranslucent = false navigationBar.isOpaque = false navigationBar.barTintColor = UIColor.white navigationBar.tintColor = UIColor.white } }
对于iOS8:
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],UITextAttributeTextColor, [UIColor blackColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil]; [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
要么
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
试试这个,但有一点BarTintColor只提供iOS7
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
除非将半透明属性设置为NO,否则此颜色默认为半透明。
或者尝试这个链接,它会更有帮助你
更改MFMailComposeViewController的工具栏颜色
尝试下面的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]]; [[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]]; // Your usual code follows here ......
@ SoftDesigner的回答:
从iOS 9开始:
[UINavigationBar appearance].tintColor = yourFavoriteColor;
在MFMailComposeViewController上不起作用。
其余答案的作品(我用它),但据我可以告诉你坚持与苹果的导航栏button的颜色。
希望这可以节省别人的一些焦虑。
首先呈现MFMailComposeViewController
然后更改它的tintColor
[self presentViewController:emailDialog animated:TRUE completion:nil]; [[UINavigationBar appearance] setBackgroundImage:nil forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
我有一个问题,阻止我设置背景颜色。 原来我有其他的代码在其他地方设置背景图像[UIImage新]。
下面的代码修复了它:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:nil];