关于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;

你可能感兴趣的:(关于iOS开发中导航栏那点事)