xcode 更改 MFMailComposeViewController 中导航的主标题颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10996537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change main title color of navigation in MFMailComposeViewController
提问by user1451163
I haven't problem for change color of main title of navigation on a normal viewController but on a MFMailComposeViewController, it isn't possible. I can change colors of buttons (cancel and send), I can set background of navigation bar but not possible to change color of title. I don't want set a new title (apparently, it's not allow by Apple), I just want change the color :'(
我在普通 viewController 上更改导航主标题的颜色没有问题,但在 MFMailComposeViewController 上,这是不可能的。我可以更改按钮的颜色(取消和发送),我可以设置导航栏的背景但无法更改标题的颜色。我不想设置新标题(显然,Apple 不允许),我只想更改颜色:'(
Please help me. Thanks
请帮我。谢谢
采纳答案by Mani
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Or
或者
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
Hope its work for you..
希望它对你有用..
回答by Ethan Allen
This is the correct answer for iOS 7, 8, 9, and 10:
这是 iOS 7、8、9 和 10 的正确答案:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]];
Here is why:
原因如下:
The check marked answer above (by Mani) referencing [UINavigationBar appearance]
is incorrect as it will change the color of the title in the UINavigationBar
that is popping the MFMailComposeViewController
as well, which was an effect I didn't want. You need to specifically get the picker's NavBar as my code does.
上面(由 Mani)引用的检查标记答案[UINavigationBar appearance]
是不正确的,因为它会改变UINavigationBar
弹出的标题的颜色MFMailComposeViewController
,这是我不想要的效果。您需要像我的代码一样专门获取选择器的 NavBar。
Setting tintColor
is also incorrect as of iOS 7 (the other answer by Mani) as it sets the colors of the buttons, not the title.
tintColor
从 iOS 7 开始,设置也不正确(Mani 的另一个答案),因为它设置按钮的颜色,而不是标题。
Also, UITextAttributeTextColor
is now deprecated, please use NSForegroundColorAttributeName
.
此外,UITextAttributeTextColor
现在已弃用,请使用NSForegroundColorAttributeName
.
回答by Mani
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTintColor:[UIColor blackColor]];
回答by DataPriest
For colors other than black, play around with this code:
对于黑色以外的颜色,请使用以下代码:
MFMailComposeViewController *mailController = [MFMailComposeViewController new];
[mailController.navigationBar setTintColor:[UIColor colorWithHue:240.0f/359.0f
saturation:85.0f/100.0f
brightness:60.0f/100.0f
alpha:0.0f]];