一、設(shè)置系統(tǒng)導(dǎo)航欄顏色
/**
* 給targetController的導(dǎo)航條設(shè)置顏色和透明度
*
* @param color
* @param alpha
* @param targetController
*/
- (void)setNavigationBarColor:(UIColor *)color
alpha:(CGFloat)alpha
targetController:(UIViewController *)targetController
{
targetController.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
UIImage *image = [self createAImageWithColor:color alpha:alpha];
[targetController.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
/**
* 根據(jù)顏色和透明度生成一張圖片
*
* @param color
* @param alpha
*
* @return
*/
- (UIImage *)createAImageWithColor:(UIColor *)color
alpha:(CGFloat)alpha
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextSetAlpha(context, alpha);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
二、導(dǎo)航欄透明度漸變效果

5月-17-2016 10-57-27.gif