[英]How can I add navigationbar background image to MFMailComposeViewController on ios7
I am using MFMailComposeViewController.I can't add navigationBar background image to MFMailComposeViewController on ios7.My Code working ios7 before .But doesn't work on ios7.How can I add navigationbar background image to MFMailComposeViewController on ios7? 我正在使用MFMailComposeViewController。我无法在ios7上将navigationBar背景图像添加到MFMailComposeViewController。我的代码之前只能在ios7上运行,但是在ios7上不起作用。如何将导航栏背景图像添加到ios7的MFMailComposeViewController?
MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
mailCompose.mailComposeDelegate = self;
[mailCompose setSubject:@"SubjectName"];
[mailCompose setMessageBody:shareBodyString isHTML:NO];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:mailCompose animated:YES completion:nil];
}
else {
[self presentModalViewController:mailCompose animated:YES];
}
[mailCompose.topViewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault]; // working before ios7
Use the Appearance Proxy. 使用外观代理。 Following code will target the whole application :
以下代码将针对整个应用程序:
UINavigationBar *navBar = [UINavigationBar appearance];
[navBar setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault];
If you prefer to target only in MFMailComposeViewController change the first line with this : 如果您只希望在MFMailComposeViewController中定位,请使用以下命令更改第一行:
navBar = [UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil];
If you already customised navigation bar and also want it to apply MFMailComposeViewController, It only allows to do it with UIAppearance proxy. 如果您已经自定义了导航栏,并且还希望它应用MFMailComposeViewController,则它仅允许使用UIAppearance代理来实现。 For iOS 7.1.1, i replaced navigation bar background but couldn't change status bar background.
对于iOS 7.1.1,我替换了导航栏背景,但是无法更改状态栏背景。 Also it greyed out bar button items on subsequent calls.
此外,它在以后的呼叫中将条形按钮项目变为灰色。 Therefore I stop customising and tried to turn back to default navigation bar style before creating MFMailComposeViewController
因此,在创建MFMailComposeViewController之前,我停止自定义并尝试返回默认的导航栏样式
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setTintColor:nil];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica-Bold" size:18.0], NSFontAttributeName, nil]];
MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.