IOS中UIImage和UIColor相互转化

//UIColor 转UIImage

- (UIImage*) createImageWithColor: (UIColor*) color

{

CGRect rect=CGRectMake(0, 0, 1, 1);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *senderImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return senderImage;

}

//UIImage转UIColor

[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];

时间: 2024-08-06 00:04:49

IOS中UIImage和UIColor相互转化的相关文章

iOS中UIImage和UIColor之间的转换

//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,

iOS中UIImage存为本地文件与UIImage转换为NSData

UIImage *[email protected]"XXX"; //png格式 NSData *imagedata=UIImagePNGRepresentation(image); //JEPG格式 //NSData *imagedata=UIImageJEPGRepresentation(image); NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES

IOS中常用的UIColor

UIColor + (UIColor *)blackColor; // 0.0 white 黑色 + (UIColor *)darkGrayColor; // 0.333 white 深灰色 + (UIColor *)lightGrayColor; // 0.667 white 亮灰色 + (UIColor *)whiteColor; // 1.0 white 白色 + (UIColor *)grayColor; // 0.5 white 灰色 + (UIColor *)redColor; //

iOS NSMutableDictionary中UIImage的存储和读取

思路:将UIImage转换成NSData,然后插入到NSMutableDictionary中,读取时,用NSData读出来,然后再转换成UIImage -存储 UIImage *image = [self getPicture: id]; NSData *imageData = UIImagePNGRepresentation(image); [tmpDic setObject:imageData forKey:@"imageData"]; -读取 NSData *imageData

IOS中十六进制的颜色转换为UIColor

#pragma mark - 颜色转换 IOS中十六进制的颜色转换为UIColor + (UIColor *) colorWithHexString: (NSString *)color { NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; // String should be 6 or 

iOS中Animation 动画 UI_22

1.iOS中我们能看到的控件都是UIView的子类,比如UIButton UILabel UITextField UIImageView等等 2.UIView能够在屏幕的显示是因为在创建它的时候内部自动添加一个CALayer图层,通过这个图层在屏幕上显示的时候会调用一个drawRect: 的方法,完成绘图,才能在屏幕上显示 3.CALayer 本身就具有显示功能,但是它不能响应用户的交互事件,如果只是单纯的显示一个图形,此时你可以使用CALayer创建或者是使用UIView创建,但是如果这个图形

iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见

iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见 (2015-12-05 12:48:20)[编辑][删除] 转载▼     首先我们先明确一下问题: 1.因为UI是在主线程中更新的,不能在down数据的同时显示界面,这样会使得下载的时间占用主线程,导致的后果就是你的屏幕就那样的卡死在哪了 2.如果要解觉问题1,就势必要将其下载数据的环节放在其他分线程上来实现,但是这里还会遇见一个问题,分线程的执行是不会有序的,这样,在动态显示的过 程中,cell中的数据就会混乱的变

IOS中AutoLayout的使用

1.基本概念 在 iPad 和 iPhone 5 出现之前,iOS 设备就只有一种尺寸.我们在做屏幕适配时需要考虑的仅仅有设备方向而已.而很多应用并不支持转向,这样的话就完全没有屏幕适配的工作了.随着 iPad 和 iPhone 5,以及接下来的 iPhone 6 的推出,屏幕尺寸也变成了需要考虑的对象.在 iOS 7 之前,为一个应用,特别是 universal 的应用制作 UI 时,我们总会首先想我们的目标设备的长宽各是多少,方向变换以后布局又应该怎么改变,然后进行布局.iOS 6 引入了

如何让IOS中的文本实现3D效果

本转载至 http://bbs.aliyun.com/read/181991.html?spm=5176.7114037.1996646101.25.p0So7c&pos=9     zhedianshi 级别: 帮帮团 发帖 487 云币 430 加关注 写私信 只看楼主 更多操作楼主  发表于: 2014-06-10 我想要在IOS中对一些文本进行3D效果渲染,使用了UIKit和标准视图控制器. 实现之的效果大概能成为这样:   能不能通过iOS和UIKit实现?我只用了一个静态PNG图片,