문제
나는 다음과 같이 무언가를 원한다
UIImage *solid = [UIImage imageWithColor:[UIColor darkGrayColor]];
어떤 색상과 관련하여 이미지를 만듭니다.
iPhone SDK에서 수행하는 방법.
해결책
색상을 CGContext로 그린 다음 이미지를 캡처 할 수 있습니다.
- (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
//Create a context of the appropriate size
UIGraphicsBeginImageContext(size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//Build a rect of appropriate size at origin 0,0
CGRect fillRect = CGRectMake(0,0,size.width,size.height);
//Set the fill color
CGContextSetFillColorWithColor(currentContext, color.CGColor);
//Fill the color
CGContextFillRect(currentContext, fillRect);
//Snap the picture and close the context
UIImage *retval = UIGraphicsGetImageFromCurrentImageContext(void);
UIGraphicsEndImageContext();
return retval;
}
다른 팁
단지 단단한 사각형의 색상을 만들려고한다면
UIView *solid = [[UIView alloc] initWithFrame:someFrame];
solid.backgroundColor = [UIColor greyColor];
그런 다음 단색을 표시하려는 하위 뷰에보기를 추가하십시오.
(즉, 물론 그게 당신이 성취하려고하는 것인지.
제휴하지 않습니다 StackOverflow