iOS项目应用之笔记

Navigation Bar下边细线颜色修改 Or Tabbar

2016-12-21  本文已影响101人  dragonYao
最近公司出了这样一个需求,说是要修改Navigation Bar下边细线颜色,我上网Google和百度都没有找到合适的方法,于是自己想了一个临时的方法。原理:navigation bar也是View的子类,那就可以使用addSubview:方法,所以直接覆盖原来的线就好了,直接上代码吧。
[CGSize naviBarSize =self.navigationController.navigationBar.frame.size;
UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, naviBarSize.height-.5, naviBarSize.width,1)];
lineImageView.backgroundColor= [UIColor whiteColor];
lineImageView.image= [[UIImage imageNamed:@"nav_border_line.png"] stretchableImageWithLeftCapWidth:10topCapHeight:0.5];
[self.navigationController.navigationBar addSubview:lineImageView]; ] 

说明:nav_border_line.png这张图片是一张 宽度随意 高度为2px的切图 ;naviBarSize.height-.5 ,一定是减去0.5,否则盖不住

UIImageView *lineView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -0.5,self.tabBarController.tabBar.frame.size.width,1)];
lineView.backgroundColor= [UIColor whiteColor];
lineView.image= [[UIImage imageNamed:@"nav_border_line.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0.5];
[self.tabBarController.tabBar addSubview:lineView]; 

  • nav_border_line.png这个就是带颜色的细线切图 高度是1px
上一篇 下一篇

猜你喜欢

热点阅读