您的位置:首页 > 移动开发

UINavigationController子类化继承后,app切换主视图返回图标颜色出错

2015-11-02 10:07 295 查看
UINavigationController子类化继承后,app切换主视图返回图标颜色出错。

app中注册与登陆流程的UINavigationController显示不一样,所以做了两个UINavigationController子类分别作为登陆注册的导航与登陆之后进入app的导航。

所以在LoginNavigationController中时返回时灰色的。

- (id)initWithRootViewController:(UIViewController *)rootViewController {

self = [super initWithRootViewController:rootViewController];

if (self) {

[self setBackgroundImage];

UIColor *color = [UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0];

if (IS_IOS7_OR_LATER) {

[UINavigationBar appearance].tintColor = color;

[UINavigationBar appearance].barTintColor = color;

} else {

[UINavigationBar appearance].tintColor = color;

}

[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor colorWithHexString:@"5d5b5c"],

UITextAttributeFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]}];

}

return self;

}

- (void)setBackgroundImage {

if (IS_IOS7_OR_LATER) {

[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav_white_bar_ios7"] forBarPosition:UIBarPositionTop barMetrics:UIBarMetricsDefault];

//iOS7 阴影需单独设定 UIColor clearColor 是去掉字段 1像素阴影]

[self.navigationBar setShadowImage:[UIImage imageWithColor:RGBA(37.0, 37.0, 37.0, 0.8) size:CGSizeMake(self.navigationBar.frame.size.width, 0.125)]];

} else {

[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav_white_bar"] forBarMetrics:UIBarMetricsDefault];

}

}

这里使用的是[UINavigationBar appearance]设置UINavigationBar tintColor颜色值。但是登陆成功后切换的视图,切换了不一样的UIVigationController(RootMainNavigationController)控制器后。RootMainNavigationController这个中的代码时这样的

- (id)initWithRootViewController:(UIViewController *)rootViewController {

self = [super initWithRootViewController:rootViewController];

if (self) {

UIColor *color = [UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0];

if (IS_IOS7_OR_LATER) {

[UINavigationBar appearance].tintColor = color;

[UINavigationBar appearance].barTintColor = color;

} else {

[UINavigationBar appearance].tintColor = color;

}

[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor colorWithHexString:@"5d5b5c"],

UITextAttributeFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]}];

}

return self;

}

当在其中的一个ViewController中设置

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ic_nav_white_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarButtonItemClicked)];

self.navigationItem.leftBarButtonItem = backBarButtonItem;

发现,这个返回按钮按钮本来是白色的,但是还是登陆时显示的灰色的。这个问题的话,解决方式如下

在两个LoginNavigationController和RootMainNavigationController中,将- (id)initWithRootViewController:(UIViewController *)rootViewController方法中的[UINavigationBar appearance]改成self.navigationBar。这样重新测试,发现结果正常了。

在此记录此问题,作为一个记录,方便查阅。

欢迎访问:www.wahenzan.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: