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
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
相关文章推荐
- Android 数据存储方式有哪几种
- android基础知识(7)
- Objective-C 的现代语法和新特性
- android基础知识(6)
- Unity中图片去色两种方案
- android 开发目录结构
- android基础知识(4)
- android基础知识(3)
- Android 数据存储之 FileInputStream 工具类及FileInputStream类的使用
- ios 设置LaunchScreen 打开APP的开始界面
- android基础知识(2)
- 在Unity中写单元测试
- android基础知识(1)
- android Notification 点击与移除监听
- 黑马程序员-------Objective-C基础
- 基础Android应用开发 Button显示系统时间+TextView显示随机数+简单计算器
- Android 自定义组件之 带有悬浮header的listview
- I.MX6 GPS Android HAL Framework 调试
- android notification点击与移除监听
- Objective-C的MKNetworkKit开发框架解析