[英]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.