下面的代码在iOS 5上运行良好,但在iOS 6或更高版本上就不行了。我想要的是,对于Email composer表单,navigationBar图像将不同于其他的UINavigationBar类。我无法理解,调试指针是响应的外观方法,但在设备上它显示导航栏图像为"bgNavigationBar.png";"bgNavigationBar_2.png"
请指引我.......
if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
UIImage *logoImage44 = [[UIImage imageNamed:@"bgNavigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:logoImage44 forBarMetrics:UIBarMetricsDefault];
UIImage *ImagePlain = [[UIImage imageNamed:@"bgNavigationBar_2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:ImagePlain forBarMetrics:UIBarMetricsDefault];
}
这个东西不能在ios6中工作。
[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"bgNavigationBar_2.png"] forBarMetrics:UIBarMetricsDefault];
您只需要在邮件处理程序类中设置此属性。
if (![[UINavigationBar class]respondsToSelector:@selector(appearance)])
{
UIView *backgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,44)]autorelease];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgNavigationBar_2.png"]]];
controller.topViewController.navigationItem.titleView = backgroundView ;
}
else
{
UIImage *gradientImagePlain = [[UIImage imageNamed:@"bgNavigationBar_2.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImagePlain forBarMetrics:UIBarMetricsDefault];
}
,然后为所有其他导航控制器的背景图像重置另一个图像。
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self.parentController dismissModalViewControllerAnimated:YES];
UIImage *gradientImagePlain = [[UIImage imageNamed:@"bgNavigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImagePlain forBarMetrics:UIBarMetricsDefault];
}