2009-10-27 175 views
18

我在iPhone应用程序中使用有色导航栏和有色全局UIToolbar。 在我的信息视图中,我有一个打开MFMailComposeViewController的按钮,该视图顶部的工具栏(“取消”和“发送”按钮)仍然是蓝色的。我打电话给这样的MFMailComposeViewController:更改MFMailComposeViewController的工具栏颜色

-(void)displayMailSheet 
{ 

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"..."]; 

    NSArray *toRecipients = [NSArray arrayWithObject:@"..."]; 

    [picker setToRecipients:toRecipients]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 

} 

是否有可能改变该视图的工具栏的颜色?如果可能的话,我该怎么做?

+2

全球范围内做到这一点,你有没有尝试设置picker.navigationBar.tintColor? – 2009-10-28 00:03:19

+0

这工作正常!谢谢! :-) – iYassin 2009-10-28 09:23:21

回答

39

在这里你去:

[[picker navigationBar] setTintColor:[UIColor blackColor]]; 

适用于iOS 8.0

[[picker navigationBar] setBarTintColor:[UIColor blackColor]]; 
+0

谢谢你的提示。它已经发布为上面的评论,但现在我可以将问题标记为已解决;-) – iYassin 2009-11-16 16:27:23

+2

对于iOS 7.0应用程序,这不起作用。看看来自eggboxderek的说明。 – 2014-05-20 16:19:27

+0

setTintColor现在更改栏按钮,所以通常在视图控制器上使用setBarTintColor,但这对MFMailComposeViewController不起作用。 – Leon 2015-07-13 10:08:31

-2

从MFMailComposeViewController类的官方参考:

重要提示:邮件撰写界面本身不是定制的,绝不能由您的应用程序修改。 [...]

我认为这将是一个更好的选择,呈现默认的邮件编排界面,无需任何更改。否则,Apple可能会拒绝您的申请。

让我们来问问这里是否有人有这种经验。

+1

Fat Booth尽力避开它。 – 2010-07-19 00:35:54

+0

你可以从appdelegate全局做到这一点。 – 2013-11-19 15:35:11

1

试试这个:

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]]; 
12

约iOS7下此功能一个小点 - 着色颜色属性不再影响酒吧作为一个整体的颜色,而是它只是改变的“发送”颜色和'取消'按钮(这在iOS7风格中是简单的彩色标签)。

如果您已将标题栏颜色更改为白色或清晰等颜色,则值得注意,因为在iOS7下,发送和取消按钮将不再可见。

3

只是想强调一下,上述关于苹果拒绝你的应用程序的帖子是一个旧帖子。下面是从当前MFMailComposeViewController文档报价...

重要:这个类的视图层次是私有的,你不能修改它。但是,您可以使用UIAppearance协议自定义实例的外观。

5

你可以从的appdelegate

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault]; // MFMailComposeViewController's navigationBar backgroundcolor 

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil]; 
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];//MFMailComposeViewController's navigationBar text color 
相关问题