【代码笔记】iOS-通过颜色来生成一个纯色图片
2016-06-12 09:17
477 查看
一,效果图。
二,代码。
RootViewController.m
二,代码。
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; }
相关文章推荐
- 【代码笔记】iOS-通过颜色来生成一个纯色图片
- AVCaptureDevice 曝光模式
- IOS后台机制分析
- iOS 下的相册与图片处理
- IOS加密方式
- iOS 页面之间传参的总结
- iOS9新特性(一)
- iOS监听键盘和输入法切换事件
- iOS中的设计模式
- iOS每日一记之——————————iOS性能优化
- iOS缩放手势
- ios获取媒体资源以及媒体信息(元数据)---AVAsset
- iOS 导出ipa包时,四个选项的意义
- iOS重写laodView
- iOS常用的三方类库
- IOS管理文件和目录
- iOS 事件传递响应链
- iOS定位从 “始终”定位,改变成“使用期间”定位
- iOS之应用程序国际化
- iOS 访问Bundle中的资源