//
// UIView+ColorView.m
// CAEmitterCell
//
// Created by Holly on 2017/11/30.
// Copyright © 2017年 Holly. All rights reserved.
//
#import "UIView+ColorView.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (ColorView)
-(UIColor *)colorOfPoint:(CGPoint)point {
unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
CGContextRef context =CGBitmapContextCreate(pixel, 1,1, 8,4, colorSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.layerrenderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIColor *color = [UIColorcolorWithRed:pixel[0]/255.0green:pixel[1]/255.0blue:pixel[2]/255.0alpha:pixel[3]/255.0];
return color;
}
@end
参考:http://www.cnblogs.com/Free-Thinker/p/5105900.html