使用iOS 中的 Palette 库获取颜色,调用方法
getPaletteImageColorWithMode
- (void)getMostColorFormImage:(UIImage *)image{WEAKSELF[image getPaletteImageColorWithMode:ALL_MODE_PALETTE withCallBack:^(PaletteColorModel *recommendColor, NSDictionary *allModeColorDic,NSError *error) {NSLog(@"获取主题色-----%@",allModeColorDic);__block CGFloat maxPercentage=0;__block PaletteColorModel * mostColorModel = recommendColor;[allModeColorDic.allValues enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {if([obj isKindOfClass:[PaletteColorModel class]]){PaletteColorModel *model = obj;if(model.percentage*100>maxPercentage){maxPercentage = model.percentage*100;mostColorModel = model;}}}];NSString * mosrColorStr = [mostColorModel.imageColorString stringByReplacingOccurrencesOfString:@"#" withString:@"0x"];UIColor *color = [UIColor colorWithHexString:mosrColorStr];}];
}