IOS 6的UIAppearence支持出现意外结果

6
以下代码在iOS 5上完全正常工作,但在iOS 6或更高版本上则不行。 我想为邮件组合器表单设置导航栏图像,该图像与其他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];
}

iOS 6的bug。Open Radar - http://www.openradar.me/radar?id=2984402 - Daniel
1个回答

7

这个东西在 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];
}

希望这对您有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接