zoukankan      html  css  js  c++  java
  • iOS 根据颜色创建个图片

    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 }
  • 相关阅读:
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战01
    C语言寒假大作战02
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    C语言I博客作业09
    C语言I博客作业08
    20199101 2019-2020-2 《网络攻防实践》综合实践
  • 原文地址:https://www.cnblogs.com/airy99/p/4741583.html
Copyright © 2011-2022 走看看