iOS中UIImage和UIColor之间的转换
2015-12-29 17:13
549 查看
//UIColor 转UIImage
- (UIImage*)imageWithColor: (UIColor*)color
{
CGRect rect=CGRectMake(0.0f,
0.0f, 100.0f,
50.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color
CGColor]);
CGContextFillRect(context, rect);
UIImage *Image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return Image;
}
//UIImage转UIColor
UIButton *Button = [[UIButton
alloc] initWithFrame:CGRectMake(20,
200,
100, 50)];
UIImage *image = [UIImage
imageNamed:@"radio_bn.png"];
[cancelButton setBackgroundColor:[UIColor
colorWithPatternImage:image]];
转载请注明出处:http://blog.csdn.net/sevenquan
- (UIImage*)imageWithColor: (UIColor*)color
{
CGRect rect=CGRectMake(0.0f,
0.0f, 100.0f,
50.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color
CGColor]);
CGContextFillRect(context, rect);
UIImage *Image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return Image;
}
//UIImage转UIColor
UIButton *Button = [[UIButton
alloc] initWithFrame:CGRectMake(20,
200,
100, 50)];
UIImage *image = [UIImage
imageNamed:@"radio_bn.png"];
[cancelButton setBackgroundColor:[UIColor
colorWithPatternImage:image]];
转载请注明出处:http://blog.csdn.net/sevenquan
相关文章推荐
- UIPageViewController-浅析
- UI - TableView高级(自定义cell、cell自定义高度)
- for-switch-continue的嵌套使用问题。
- UIScrollView做图片缩放
- IOS学习笔记——iOS组件之UIScrollView详解
- 使用NSURLCache为NSURLRequest设置缓存
- UIPopoverPresentationController 弹出 UIViewController 包裹的 UICollectionView
- UGUI Navigation Events
- 提示框的综合使用--UIAlertViewController
- TableView性能优化——动态cell适应工具(UITableView+FDTemplateLayoutCell)
- IOS:UIPickerView设置三组数据联动的选择框(地区,上课时间段等类型数据的选择)
- UITextField和UITextView隐藏键盘
- UIActivityIndicatorView、UIProgressView 活动与进度指示器-IOS开发
- 前端开发 各种懒人灵巧UI库汇总-只作为记录
- EasyUI datagrid 复杂表头处理
- IOS开发UIScrollView控件详解
- getRequestURI,getRequestURL的区别
- UIScrollView基本用法和代理方法
- ueditor多图片上传中去掉在线管理和图片搜索Tab页功能
- KVM error when create guest