更改MFMailComposeViewController navigationBar标题字体

我有一个MFMailComposeViewController ,当我设置主题时,它也将它设置为主题。 问题是如何自定义标题和颜色的字体?

 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; [picker setSubject:@"Feedback for MyApp"]; 

我已经为所有视图控制器的所有导航栏的app-delegate更改了我的应用程序的字体。 如果您不介意更改所有导航栏标题字体,请在applicationDidFinishLaunching:withOptions:以下内容applicationDidFinishLaunching:withOptions:

  if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) // set the navigation bar font to "courier-new bold 14" [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"CourierNewPS-BoldMT" size:14.0], UITextAttributeFont, nil]]; 

更新:如果你想要特定于这一个案例,你可以使用appearanceWhenContainedIn:使用Alexander Akers在下面的评论中建议的参数,因为UIViewControllerinheritance自UIAppearanceContainer。 我知道appearanceWhenContainedIn:适用于其他情况,例如UINavigationBar中包含的UIBarButtonItems,所以它应该适用于这种情况。

我的猜测是因为跨进程限制而无法完成。 我可以更改颜色,大小和字体(如果它是内置系统字体),但尝试将其更改为我的应用程序中包含的任何字体都会失败。

由于MFMailComposeViewControllerUINavigationController一个实例,因此您可以按如下方式设置其topViewController的topViewController

 UIViewController *controller = [mailController topViewController]; UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 170.0f, 44.0f)]; titleView.backgroundColor = [UIColor clearColor]; UILabel *label = [[UILabel alloc] initWithFrame:titleView.bounds]; label.textColor = [UIColor whiteColor]; label.backgroundColor = [UIColor clearColor]; label.text = @"Custom Font"; label.font = [UIFont italicSystemFontOfSize:27.0f]; label.textAlignment = UITextAlignmentCenter; [titleView addSubview:label]; [label release]; controller.navigationItem.titleView = titleView; [titleView release];