关于iOS开发中导航栏那点事

1、iOS如何实现导航栏背景透明,但按钮保持不透明?

具体实现代码如下:

CGRect rect2 = [[UIScreen mainScreen] bounds];

CGSize size = rect2.size;

CGFloat width = size.width;

UIColor *color=[UIColor clearColor];

CGRect rect=CGRectMake(0, 0, width, 64);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context=UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image=UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.clipsToBounds=YES;

2、如何去掉导航栏下面那根线,如何修改背景色?

具体实现代码如下:

//去除背景

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

//消除阴影

self.navigationController.navigationBar.shadowImage = [UIImage new];

3、如何修改导航栏底部的横线颜色?

CGRect rect = CGRectMake(0, 0, self.view.bounds.size.width, 0.5);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context,[UIColor groupTableViewBackgroundColor].CGColor);

CGContextFillRect(context, rect);

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

self.navigationController.navigationBar.shadowImage =img;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 4,808评论 1 6
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 5,261评论 0 3
  • 1.NSString过滤特殊字符串定义一个特殊字符的集合NSCharacterSet set = [NSChara...
    奋拓达阅读 4,189评论 0 0
  • 转自:http://www.code4app.com/blog-866962-1317.html1、设置UILab...
    MMOTE阅读 5,668评论 1 1
  • 每一次回首,内心都充满了温柔。不是我惊艳了时光,而是那青春年少的日子着实难忘。 谁的人生不曾年轻过?谁年轻的时候不...
    Aylin楚吟阅读 3,931评论 8 27