2015/06/12

[iOS][Objective-C]UIImageを動的につくる

UIImageを動的に作るにはどうすればいいのだろうか?

指定したUIColorとCGRectで、塗りつぶしのUIImageを生成するで確認すると以下のようにすればいけるみたい。

UIColor *color;
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(contextRef, color.CGColor);
CGContextFillRect(contextRef, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
上のコードでimageに指定した色で塗られている画像を作成することができる。

これ透明色のpngを作りたい時に便利かも。

0 コメント:

コメントを投稿