【问题标题】:Change main title color of navigation in MFMailComposeViewController在 MFMailComposeViewController 中更改导航的主标题颜色
【发布时间】:2012-06-12 12:20:19
【问题描述】:

在普通 viewController 上更改导航主标题的颜色没有问题,但在 MFMailComposeViewController 上,这是不可能的。 我可以更改按钮的颜色(取消和发送),我可以设置导航栏的背景但不能更改标题的颜色。我不想设置新标题(显然,Apple 不允许这样做),我只想更改颜色 :'(

请帮助我。 谢谢

【问题讨论】:

标签: iphone objective-c xcode cocoa-touch


【解决方案1】:
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];

希望它对你有用..

【讨论】:

  • 这会改变整个应用程序的颜色,但不会在 MFMailComposure 中。 IOS 12.
【解决方案2】:

这是 iOS 7、8、9 和 10 的正确答案:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]];

原因如下:

上面的复选标记答案(由 Mani)引用 [UINavigationBar appearance] 是不正确的,因为它会改变 UINavigationBar 中标题的颜色,这也会弹出 MFMailComposeViewController,这是我没有的效果想。您需要像我的代码一样专门获取选择器的 NavBar。

设置 tintColor 在 iOS 7 中也是不正确的(Mani 的另一个答案),因为它设置了按钮的颜色,而不是标题。

另外,UITextAttributeTextColor 现已弃用,请使用 NSForegroundColorAttributeName

【讨论】:

    【解决方案3】:
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
        picker.mailComposeDelegate = self;
        [[picker navigationBar] setTintColor:[UIColor blackColor]];
    

    【讨论】:

    • 不是我找的,这里你改导航栏的颜色(我已经有背景了),我要改titleview的颜色
    【解决方案4】:

    对于黑色以外的颜色,请使用以下代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      相关资源
      最近更新 更多