iOS颜色转换成图片的方法
// 颜色转换为背景图片
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return image;
}
使用例子
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
[button2 setTitle:@"button2" forState:UIControlStateNormal];
[button2 setBackgroundImage:[self imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
[button2 setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateHighlighted];
[self.view addSubview:button2];
}
效果如下图:

iOS颜色转换成图片的方法的更多相关文章
- Swift3 颜色转换成图片Image
Swift3下的转换写法: /// 将颜色转换为图片 /// /// - Parameter color: <#color description#> /// - Returns: < ...
- C# 实现HTML转换成图片的方法
/// <summary> /// 通过WebBrowser控件来实现从HTML到Bmp图片的生成. /// </summary> / ...
- C#技术分享【PDF转换成图片——13种方案】(2013-07-25重新整理)
原文:C#技术分享[PDF转换成图片--13种方案](2013-07-25重新整理) 重要说明:本博已迁移到 石佳劼的博客,有疑问请到 文章新地址 留言!!! 写在最前面:为了节约大家时间,撸主把最常 ...
- C#技术分享【PDF转换成图片——11种方案】
1.[iTextSharp.dll],C# 开源PDF处理工具,可以任意操作PDF,并可以提取PDF中的文字和图片,但不能直接将PDF转换成图片. DLL和源码 下载地址:http://downloa ...
- 批量将网页转换成图片或PDF文档技巧分享
工作中我们有时要将一些批量的网页转换成图片或者PDF文档格式,尽管多数浏览器具有滚动截屏或者打印输出PDF文档功能.可是假设有几十上百张网页须要处理,那也是要人命的.所以我一直想找一款可以批量处理该工 ...
- Android View转换成图片保存
package zhangphil.viewtoimage; import java.io.File;import java.io.FileOutputStream; import android.o ...
- ASP.Net中实现上传过程中将文本文件转换成PDF的方法
iTextSharp是一个常用的PDF库,我们可以使用它来创建.修改PDF文件或对PDF文件进行一些其他额外的操作.本文讲述了如何在上传过程中将文本文件转换成PDF的方法. 基本工作 在开始之前,我们 ...
- C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。
C#中对象,字符串,dataTable.DataReader.DataSet,对象集合转换成Json字符串方法. public class ConvertJson { #region 私有方法 /// ...
- CAJ转换成PDF在线方法是什么
做学术性的朋友经常会需要将CAJ文件转换成PDF文件,毕竟CAJ文件只能在CAJ阅读器上显示,但是有很多转换软件并不能很好的完成转换,小编今天就为大家讲解一下CAJ转换成PDF在线方法是什么,大家要认 ...
随机推荐
- 从 Apache ORC 到 Apache Calcite | 2019大数据技术公开课第一季《技术人生专访》
摘要: 什么是Apache ORC开源项目?主流的开源列存格式ORC和Parquet有何区别?MaxCompute为什么选择ORC? 如何一步步成为committer和加入PMC的?在阿里和Uber总 ...
- ng-model 将时间戳转换为标准时间
html部分 <div class="form-group loginCon1"> <label class="col-sm-2 control-l ...
- 【原生JS】滑动门效果
效果图: 思路:通过每次鼠标移动至目标上使所有图片重置为初始样式再向左移动目标及其左侧每个图片隐藏部分距离即实现. HTML: <!DOCTYPE html> <html> & ...
- 在linux上安装pear
在搭建centreon的过程中,需要pear模块支持. 什么是pear pear是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写. ...
- [转载] Solaris命令使用
摘自: http://www.jb51.net/os/Solaris/18533.html ★6. rm 删除文件 命令格式: rm [-r] filename (filename 可为档名,或档 ...
- Mockito 使用
1. 算术测试类 package com.smart.test.mockito; public interface Calculator { public int add(int a, int b); ...
- 【codeforces 761D】Dasha and Very Difficult Problem
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 通过页码直接跳转 html
<?php namespace Admin\TagLib; class BootstrapPage{ public $firstRow; // 起始行数 public $listRows; // ...
- turtle 20秒画完小猪佩奇“社会人”
转载:https://blog.csdn.net/csdnsevenn/article/details/80650456 图片源自网络 作者 丁彦军 如需转载,请联系原作者授权. 今年社交平台上最火的 ...
- vue基于 element-ui 实现菜单动画效果,任意添加 li 个数均匀撑满 ul 宽度
%)%)%%%))) .) .) .) .) .) .) .) .) .) .) .) .) .) .) .) .% %% %deg);}