美文网首页
将颜色转换成图片(导航栏颜色渐变使用)

将颜色转换成图片(导航栏颜色渐变使用)

作者: 雨雪霏霏why | 来源:发表于2015-12-18 11:09 被阅读71次

+(UIImage *)imageWithBgColor:(UIColor *)color {

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

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

代码使用

```[self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:243.0 / 255.0 green:82.0 / 255.0 blue:15.0 / 255.0 alpha:(self.scrollView.contentOffset.x)/150+APP.navAlpha]] forBarMetrics:UIBarMetricsDefault];```

相关文章

网友评论

      本文标题:将颜色转换成图片(导航栏颜色渐变使用)

      本文链接:https://www.haomeiwen.com/subject/hxpphttx.html