次のようなものが欲しい
UIImage *solid = [UIImage imageWithColor:[UIColor darkGrayColor]];
ある色に関して画像を作成します。
iPhoneSDKでそれを行う方法。
色を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];
次に、単色を表示したいサブビューにビューを追加します。
(もちろん、それはあなたが達成しようとしているものである場合に限られます。おそらくあなたはそうではないでしょう)