iOS导航条处理

 快速的隐藏导航条的方法:

/* 隐藏底部阴影条,传递一个空图片的UIImage对象*/

[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

/*设置标题不能直接设置navigationItem的text

也不能直接设置UILabel的alpha为0

要设置UILabel的text的文字颜色为透明*/

UILabel*label=[[UILabel alloc] init];

label.text=@"邱子硕";

label.textColor=[UIColor colorWithWhite:1 alpha:0];

[label sizeToFit];

self.navigationItem.titleView=label;


/*给导航条的背景图片传递一个空图片的UIImage对象*/

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

/*导航条背景图片怎么生成?利用颜色生成半透明图片,传递一个颜色,就生成一张图片,根据颜色生成一张尺寸为1*1的相同颜色图片*/

+ (UIImage *)imageWithColor:(UIColor *)color

{

/ /描述矩形

CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

// 开启位图上下文

UIGraphicsBeginImageContext(rect.size);

// 获取位图上下文

CGContextRef context = UIGraphicsGetCurrentContext();

// 使用color演示填充上下文

CGContextSetFillColorWithColor(context, [color CGColor]);

// 渲染上下文

CGContextFillRect(context, rect);

// 从上下文中获取图片

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

// 结束上下文

UIGraphicsEndImageContext();

return theImage;

}

你可能感兴趣的:(iOS导航条处理)