2014年3月14日金曜日

[iOS]Xcode5.1(iOS7.1)で旧バージョンのプロジェクトで警告が発生

Xcode5.1にアップデートした時に、
Xcode5.0で作成したプロジェクトに大量の警告が入るが、
プロジェクトのクリアをすれば警告が直る。

・その他
UITableViewのbackgroundcolorが無効になった
>UITableViewCellで色を変更

2014年3月9日日曜日

[iOS]UIColorからUIImageを作成する

stackoverflow.comより
- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *image = [self createImageFromUIColor:[UIColor blackColor]];
}

- (UIImage *)createImageFromUIColor:(UIColor *)color
{
    //1x1のBitmapを作成する
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    //Bitmapを塗りつぶし
    CGContextSetFillColorWithColor(contextRef, [color CGColor]);
    CGContextFillRect(contextRef, rect);
    //UIImageに変換
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
};