如何将导航栏背景图像添加到ios7上的MFMailComposeViewController
我正在使用MFMailComposeViewController。我无法在ios7上将导航栏背景图像添加到MFMailComposeViewController。我的代码以前在ios7上工作。但在ios7上不工作。如何将导航栏背景图像添加到ios7上的MFMailComposeViewController如何将导航栏背景图像添加到ios7上的MFMailComposeViewController,ios,iphone,objective-c,ios7,uinavigationbar,Ios,Iphone,Objective C,Ios7,Uinavigationbar,我正在使用MFMailComposeViewController。我无法在ios7上将导航栏背景图像添加到MFMailComposeViewController。我的代码以前在ios7上工作。但在ios7上不工作。如何将导航栏背景图像添加到ios7上的MFMailComposeViewController MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init]; m
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
使用外观代理。以下代码将针对整个应用程序:
UINavigationBar *navBar = [UINavigationBar appearance];
[navBar setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarMetrics:UIBarMetricsDefault];
如果希望仅在MFMailComposeViewController中设置目标,请使用以下命令更改第一行:
navBar = [UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil];
如果您已经定制了导航栏,并且还希望它应用MFMailComposeViewController,那么它只允许使用UIAppearance代理执行此操作。对于iOS 7.1.1,我替换了导航栏背景,但无法更改状态栏背景。此外,在随后的调用中,它也会使条形按钮项变灰。因此,在创建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];
谢谢你的回答@vinceBurn。今天我有个会议。我会在空闲时间看看。这不是工作。但这对我的研究和发现很有帮助。我写了这段代码,它成功了:[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“navigationbar background.png”]forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault]。但我不明白为什么你的代码不起作用。你的代码和我有什么不同?thanks@ErhanDemirci我发布的代码不会编译,除非针对您的情况进行修改,否则我将更新代码,使其更“通用”