描述
在写项目时我们有时会需要根据点击图片的颜色来改变主题颜色,就需要获取照片主色值,在这里我应用第三方库 SOZOChromoplast 来实现
使用步骤
- 首先通过Cocoapods安装
在终端处将 pod ‘SOZOChromoplast’ 添加到Podfile中并运行 pod install - 在使用处写头文件
#import <SOZOChromoplast.h>
- 调用的代码
//获取图片
NSString *urlString = [NSString stringWithFormat:@"%@",_smallModel.images.medium];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *image = [UIImage imageWithData:data];
//实例化颜色
SOZOChromoplast *color = [[SOZOChromoplast alloc] initWithImage:image];
//设置背景颜色
_smallView.backgroundColor = color.firstHighlight;