簡體   English   中英

iOS:如果背景圖片的顏色與按鈕的顏色相同,則更改UIButton的顏色

[英]iOS: Change color of my UIButton if the background image have same color of the button

我有一個UIImageView從服務器獲取圖像,在它的右上方,我有一個白色的UIButton 現在,如果imageview的圖像在我的按鈕附近為白色,則由於背景和button為白色,因此我的button無法很好地顯示。 我想一個辦法可以改變按鈕的背景color ,如果圖像color是一樣的button的背景color

嘗試這個 -

-(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]);
}

這將幫助您找到背景顏色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM