星空网 > 软件开发 > 操作系统

【代码笔记】通过颜色来生成一个纯色图片

一,效果图。

【代码笔记】通过颜色来生成一个纯色图片images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151020151827364-850094855.jpg" width="218" height="400" />

二,代码。

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;}
【代码笔记】通过颜色来生成一个纯色图片

 

 


 

原标题:【代码笔记】通过颜色来生成一个纯色图片

关键词:图片

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流