UIImage与UIColor互转】的更多相关文章

Objective-C UIColor -> UIImage ? 1 2 3 4 5 6 7 8 9 10 11 - (UIImage*) createImageWithColor: (UIColor*) color {     CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);     UIGraphicsBeginImageContext(rect.size);     CGContextRef context = UIGraphicsGetCur…
一,效果图 二,工程目录. 三,代码 RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //添加背景图 [self addView]; } #pragma -mark -functions //添加背景图 -(void)addView { UIView *view=[[UIView alloc]initWithFram…
一般我们会用此方法加载被背景图片 [self.view setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc]initWithContentsOfFile:App_ContentFile(@"xxx", @"png")]]]; 但是有时候会发现内存变大的离谱,再给self.view设置背景时候可以用UIImageView: self.view = [[UIImageView alloc]…
/** * 将UIColor变换为UIImage * **/+ (UIImage *)createImageWithColor:(UIColor *)color{ CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWit…
+ (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]…
UIImage+YYWebImage是YYWebImage(https://github.com/ibireme/YYWebImage)中的一个分类,这个分类封装了一些image常用的变化方法,非常值得学习下源码~(我看的版本是1.0.5)   预备知识: 1,这里大量使用了CoreGraphics的方法,第一个非常常用的的方法就是 UIKIT_EXTERN void    UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaq…
定义 #import <UIKit/UIKit.h> @interface UIImage (ChangeImageColor) /** * 改变图片的颜色 * * @param tintColor <#tintColor description#> * * @return <#return value description#> */ - (UIImage *) imageWithTintColor:(UIColor *)tintColor; @end 实现 - (U…
//  颜色转换为背景图片 + (UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [colo…
只能说太神奇了,完美应用到我的毕业设计 - (UIImage*) createImageWithColor: (UIColor*) color { CGRect rect=CGRectMake(,,self.view.bounds.size.width,); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithC…
来源:iOS_小松哥 链接:http://www.jianshu.com/p/9ab1205f5166 有时候我们需要处理图片,比如改变大小,旋转,截取等等,所以今天说一说图片处理相关的一些操作. 本文所说的方法都是写在UIImage的Category中,这样使用起来也方便:由于代码太多,这里就不贴具体实现代码了,大家可以去我的Github查看demo(https://github.com/lisongrc/UIImage-Categories),效果如下: 颜色相关 1.根据颜色生成纯色图片…
在开发中使用分类对原有的系统类进行方法扩展,是增强系统原有类功能的常见做法. /** * 自由拉伸一张图片 * * @param name 图片名字 * @param left 左边开始位置比例 值范围0-1 * @param top 上边开始位置比例 值范围0-1 * * @return 拉伸后的Image */ + (UIImage *)resizedImageWithName:(NSString *)name left:(CGFloat)left top:(CGFloat)top { UI…
一有用的 UIImage 扩展,支持(等比例)放大和旋转可在许多 App 中使用. UIImage-Extensions.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> CGFloat DegreesToRadians(CGFloat degrees); CGFloat RadiansToDegrees(CGFloat radians); @interface UIImage (JQ_Extensions) -…
#import <UIKit/UIKit.h> @interface UIImage (ImageWithColor) + (UIImage *)imageWithColor:(UIColor *)color; @end #import "UIImage+ImageWithColor.h" @implementation UIImage (ImageWithColor) + (UIImage *)imageWithColor:(UIColor *)color { CGRec…
1. open class VericalCenteringScrollView: UIScrollView { override open var contentOffset: CGPoint { didSet { let contentSize = self.contentSize let scrollViewSize = self.bounds.size var contentOffset = self.contentOffset if contentSize.height < scrol…
根据颜色返回图片,根据str返回颜色,压缩UIImage不大于300k .h代码: #import <Foundation/Foundation.h> @interface ImageService : NSObject /** 根据颜色返回图片 */ +(UIImage*) createImageWithColor:(UIColor*) color; /** 根据str返回颜色 */ + (UIColor *) colorWithHexString: (NSString *)color; /…
UIGraphicsBeginImageContextWithOptions,本文主要在图片类型上下文中对图片进行操作,具体实现的功能:  - 1.生成图片  - 2.绘制图片到视图 - 3.添加水印 - 4.截取屏幕或者相应view - 5.图片擦除 - 6.图片裁剪 具体的方法使用就在方法的介绍中解释吧,为了代码的复用,对上述方法进行了封装,放在UIImage的类别中,方便今后使用. 图片操作的基本步骤 .开启图形上下文 .绘制图片 - 使用drowInRect或者drawAtPoint绘制…
UIImage+PYJColorBecomeImage.h: // // UIImage+PYJColorBecomeImage.h // 颜色转成图片 // // Created by PengYunjing on 16/8/24. // Copyright © 2016年 PYJ. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImage (PYJColorBecomeImage) + (UIImage*)imag…
代码地址如下:http://www.demodashi.com/demo/11609.html 人生得意须尽欢,莫使金樽空对月. 天生我材必有用,千金散尽还复来. 前记 说到UIImage大家都不会感到陌生,最近在研究UIImage,就顺便把之前工作中用到的一些category总结了一下,记录记录. 在这之前先看一下一些简答的效果图 1.简单处理 2.GIF图片加载 3.图片添加文字.图片及图片截屏.擦除 代码分析 1.图片圆角处理 关于图片的圆角处理,这个可能用的比较多点,当然你也可以用给UI…
- (UIColor *)colorAtPixel:(CGPoint)point { // Cancel if point is outside image coordinates if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, self.size.width, self.size.height), point)) { return nil; } NSInteger pointX = trunc(point.x); NSInteger pointY…
+ (UIImage *)clearImageView { UIColor *color=[UIColor clearColor]; CGRect rect =CGRectMake(,,,); UIGraphicsBeginImageContext(rect.size); CGContextRef context =UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CG…
十七:返回到主线程进行操作,对UI进行更新只能在主线程进行 /*将数据显示到UI控件,注意只能在主线程中更新UI, 另外performSelectorOnMainThread方法是NSObject的分类方法,每个NSObject对象都有此方法, 它调用的selector方法是当前调用控件的方法,例如使用UIImageView调用的时候selector就是UIImageView的方法 Object:代表调用方法的参数,不过只能传递一个参数(如果有多个参数请使用对象进行封装) waitUntilDo…
移动中隐藏tabBar,静止显示tabbar - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { // 隐藏tabbar [self hideTabBar]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // 显示tabbar [self showTabBar]; } -(void)hideTabBar { // 隐藏tabBa…
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; 2.隐藏某行cell 1 2 3 4 5 6 7 8 9 10 11 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // 如果是你需要隐藏的那一行,返回…
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; 2.隐藏某行cell 1 2 3 4 5 6 7 8 9 10 11 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // 如果是你需要隐藏的那一行,返回…
tableViewCell分割线左对齐: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setSeparatorInset:UIEdgeInsetsZero]; [cell setLayoutMargins:UIEdgeInsetsZero]; cell.preservesSu…
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; 2.隐藏某行cell 1 2 3 4 5 6 7 8 9 10 11 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // 如果是你需要隐藏的那一行,返回…
之前每次用到UICollectionView的时候都会都需要在Controller里面去实现DataSource & Delegate方法 单独Delegate方法还好不是很多, 但是再加上DataSource就很臃肿了, 为了避免代码臃肿也减少ViewController的代码量 我们可以将DataSource方法分离出去, 大致方法如下: -> 创建需要的Model & 自定义Cell文件 -> 创建DataSource类, 导入 Cell头文件并实现UICollectio…
GCD定时器 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, , ,queue); dispatch_source_set_timer(timer,dispatch_walltime(NULL, ),); //每秒执行…
遍历可变数组的同时删除数组元素 NSMutableArray *copyArray = [NSMutableArray arrayWithArray:array]; NSString *str1 = @“zhangsan”; for (AddressPerson *perName in copyArray) { if ([[perName name] isEqualToString:str1]) { [array removeObject:perName]; } } 获取系统当前语言 NSStr…
在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)]; self.tableView.tableHeaderView = view; UITableView的plain样式下,取消区头停滞效果 - (void)scrollViewDidScroll:(UIScro…