问题
I have a MFMailComposeViewController
and when I've set the subject it also sets it as the subject.
The question is how do I customize the font of the title and color?
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setSubject:@"Feedback for MyApp"];
回答1:
i've changed the font generally for my apps from the app-delegate for all navigation bars of all view controllers. if you don't mind it changing all of your navigation bar title fonts, put something like the following in 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]];
update: if you want it specific to this one case, you can probably use appearanceWhenContainedIn: using the arguments Alexander Akers suggested in the comment below, since UIViewController inherits from UIAppearanceContainer. i know appearanceWhenContainedIn: works in other cases such as UIBarButtonItems contained in UINavigationBar, so it should work similarly for this situation.
回答2:
My guess is it can't be done because of cross-process restrictions. I can change the color, size, and font (if it's a built-in system font), but attempts to change it to any of the fonts included in my app fail.
回答3:
Since the MFMailComposeViewController
is an instance of a UINavigationController
, you can set the titleView of its topViewController
as follows:
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];
来源:https://stackoverflow.com/questions/11173693/changing-the-mfmailcomposeviewcontroller-navigationbar-title-font