【问题标题】: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 是白色的。如果图像colorbutton 背景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]);
}

它将帮助您找到背景颜色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 2015-04-03
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多