我有一个MFMailComposeViewController
,当我设置主题时,它也将其设置为主题。 问题是我如何自定义标题和颜色的字体?更改MFMailComposeViewController navigationBar标题字体
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setSubject:@"Feedback for MyApp"];
我有一个MFMailComposeViewController
,当我设置主题时,它也将其设置为主题。 问题是我如何自定义标题和颜色的字体?更改MFMailComposeViewController navigationBar标题字体
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setSubject:@"Feedback for MyApp"];
我已经普遍改变了字体从应用程序委托方所有视图控制器的所有导航栏我的应用程序。如果你不介意它改变所有的导航栏标题的字体,把类似下面的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在下面的评论中提出的参数,因为UIViewController继承自UIAppearanceContainer。我知道appearanceWhenContainedIn:在其他情况下工作,比如UINavigationBar中包含的UIBarButtonItems,所以它在这种情况下应该类似地工作。
由于MFMailComposeViewController
是UINavigationController
的一个实例,您可以设置其topViewController
的titleview的如下:
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];
由于某种原因,这不起作用,我复制粘贴你的代码,并用我的 – xonegirlz
@xonegirlz替换mailController,你提到过,你试过这个代码。我记得在改变控制栏的特征方面遇到了问题,这就是为什么我要依赖上述答案中所描述的UIA外观。你也尝试过吗?任何更新? –
我的猜测是它不能因为跨进程限制来完成。我可以更改颜色,大小和字体(如果它是内置的系统字体),但尝试将其更改为我的应用中包含的任何字体都会失败。
'[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class],nil]'? –
该代码仅在包含在邮件撰写视图控制器中时才会更改导航栏的外观。 –
@AlexsanderAkers,更新了您的建议的答案。我有使用appearanceWhenContainedIn的经验:对于UINavigationBar中的UIBarButtonItem;我没有用它来处理这种类型的案件,但它确实有效。 –