iOS - UIAppearance appearanceWhenContainedIn问题 [英] iOS – UIAppearance appearanceWhenContainedIn issues

查看:458
本文介绍了iOS - UIAppearance appearanceWhenContainedIn问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的导航栏设置图像,如下所示:

  [[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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆