zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-通过颜色来生成一个纯色图片

    一,效果图。

    二,代码。

    RootViewController.m

    复制代码
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
        imageView.backgroundColor=[UIColor yellowColor];
        imageView.image=[self buttonImageFromColor:[UIColor redColor]];
        [self.view addSubview:imageView];
        
        
        
    }
    //通过颜色来生成一个纯色图片
    - (UIImage *)buttonImageFromColor:(UIColor *)color{
        
        CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }
    复制代码

     

     

     
     
  • 相关阅读:
    try catch使用示例
    doxgen生成chm文档和乱码解决方法
    MFC中MessageBox()用法
    UML聚合与组合
    C#网络编程
    单元测试(NUnit)
    Autohotkey
    .NET中的并行
    System.Environment类的使用
    一键VHD
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5576555.html
Copyright © 2011-2022 走看看