ios客户端学习-ios及android改变图片颜色的方法
2016-01-12 17:50
627 查看
iOS:
学习资料链接:http://www.onevcat.com/2013/04/using-blending-in-ios/下载地址:https://github.com/onevcat/VVImageTint
android:
转载地址:http://www.360doc.com/content/14/0818/05/4587493_402721688.shtmliOS 简述
使用方法2.在类里面调用如下
#import "UIImage+Tint.h"
self.img.image = [[UIImage
imageNamed:@"left_green_me"]
imageWithGradientTintColor:[UIColor
redColor]];
self.img2.image
= [[UIImage
imageNamed:@"add_cert_me"]imageWithTintColor:[UIColor
purpleColor]];
1.创建.h和.m文件
.h
#import <UIKit/UIKit.h>
@interface UIImage (Tint)
- (UIImage *) imageWithTintColor:(UIColor *)tintColor;
- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor;
@end
。m
#import "UIImage+Tint.h"
@implementation UIImage (Tint)
- (UIImage *) imageWithTintColor:(UIColor *)tintColor
{
return [self
imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];
}
- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor
{
return [self
imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];
}
- (UIImage *) imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode
{
//We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
UIGraphicsBeginImageContextWithOptions(self.size,
NO,
0.0f);
[tintColor
setFill];
CGRect bounds = CGRectMake(0,
0, self.size.width,
self.size.height);
UIRectFill(bounds);
//Draw the tinted image in context
[self
drawInRect:bounds
blendMode:blendMode alpha:1.0f];
if (blendMode !=
kCGBlendModeDestinationIn) {
[self
drawInRect:bounds blendMode:kCGBlendModeDestinationIn
alpha:1.0f];
}
UIImage *tintedImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage;
}
@end
android 简述
相关文章推荐
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- Android图片加载库Picasso源码分析
- Android应用性能测试
- android之壁纸机制
- AlertDialog的create和show
- android的动画相关参数说明
- Android 实用工具Hierarchy Viewer实战
- android 在Button 的onDraw中加上invalidate()会导致背景缩放失败
- Android 实现布局动态加载
- android v4,v7-RecyclerView基于23的源码
- Android 高亮指示层提示
- Android 讲解:布局
- Lowen 基于monkeyrunner的android应用的自动化测试
- Android下载服务器资源文件(支持断点续传)
- 读《Android开发艺术探索》---View滑动冲突
- Android Studio报错:Could not download junit.jar
- Android Studio上方便使用butterknife注解框架的偷懒插件Android Butterknife Zelezny
- 监听ScrollView的滚动
- Android ListView的A-Z字母排序和过滤搜索功能
- Android客户端注入及清除Cookie