iOS - UIAppearance appearanceWhenContainedIn问题 [英] iOS – UIAppearance appearanceWhenContainedIn issues
问题描述
我为我的导航栏设置图像,如下所示:
[[UINavigationBar外观] setBackgroundImage:[UIImage imageNamed: @navbar.png] forBarMetrics:UIBarMetricsDefault];
然后我不想让这个图像类的 MFMessageComposeViewController
所以我通过这样做排除它:
[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class],nil] setBackgroundImage: nil forBarMetrics:UIBarMetricsDefault];
但它没有效果(navbar仍然以我的形象在 MFMessageComposeViewController
)。
找到我的问题的解决方案:
子类 MFMessageComposeViewController
在init方法中设置 backgroundImage
到
navigationBar
到 nil
VibinOrNil Bundle(NSBundle *)nibBundleOrNil
{
$
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
//自定义初始化
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
return self;
}
I'm setting an image for my navigationbar like so:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
Then I don't want this image for classes of MFMessageComposeViewController
so I exclude it by doing this:
[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
But it has no effect (the navbar is still styled with my image inside the MFMessageComposeViewController
). What am I missing here?
Found out the solution to my problem:
Subclass the MFMessageComposeViewController
In the init method set the backgroundImage
of the navigationBar
to nil
Voilá!
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
return self;
}
这篇关于iOS - UIAppearance appearanceWhenContainedIn问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!