【问题标题】:iOS: Change color of my UIButton if the background image have same color of the buttoniOS:如果背景图像与按钮颜色相同,则更改我的 UIButton 的颜色
【发布时间】:2016-06-30 21:38:41
【问题描述】:
我有一个从服务器获取图像的UIImageView,在右上角我有一个我制作的白色UIButton。现在如果imageview 中的图像在我的按钮附近是白色的,我的button 不会很好地显示,因为背景和我的button 是白色的。如果图像color 与button 背景color 相同,我想要一种能够更改按钮背景color 的方法。
【问题讨论】:
标签:
ios
objective-c
uiimageview
uibutton
【解决方案1】:
试试这个 -
-(void) getPixelColorAtLocation:(CGPoint)point
{
unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.layer renderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
NSLog(@"RGB Color code %d %d %d",pixel[0],pixel[1],pixel[2]);
}
它将帮助您找到背景颜色。