UIImage的分类,可用于动态改变navigetionBar的背景图片颜色,

示例

  // 修改navigationBar的背景图片
  [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor purpleColor]] forBarMetrics:UIBarMetricsDefault];

    // 修改navigationBar的线条的图片

    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor whiteColor]]];



//
根据颜色创建图片 尺寸为1*1 + (UIImage *)imageWithColor:(UIColor *)color;
 1 + (UIImage *)imageWithColor:(UIColor *)color
 2 {
 3     // 描述矩形
 4     CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
 5     
 6     // 开启位图上下文
 7     UIGraphicsBeginImageContext(rect.size);
 8     // 获取位图上下文
 9     CGContextRef context = UIGraphicsGetCurrentContext();
10     // 使用color演示填充上下文
11     CGContextSetFillColorWithColor(context, [color CGColor]);
12     // 渲染上下文
13     CGContextFillRect(context, rect);
14     // 从上下文中获取图片
15     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
16     // 结束上下文
17     UIGraphicsEndImageContext();
18     
19     return image;
20 }

 

相关文章:

  • 2022-12-23
  • 2021-12-28
  • 2022-02-26
  • 2021-11-01
  • 2021-07-13
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案