UIImageViewクラスは、画面上での画像表示を管理するクラスです。
また、UIImageViewクラスにはアニメーションを行う機能もあり、パラパラ漫画のようにコマ送りのアニメーションを容易に行うことが可能となっています。




UIImageViewの宣言

// 生成例
UIImageView *imageView = [[UIImageView alloc] init];

// UIImageを指定した生成例
UIImage *image = [UIImage imageNamed: @"hoge.png" ];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

主要なプロパティ

image
表示させる画像データを指定する
例)imageView.image = [[[UIImage]] imageNamed:@"hoge.png"];

animationImages
アニメーションに使われるイメージ配列を指定
例)imageView.animationImages = [NSArray arrayWithObjects:@"hoge1.png", @"hoge2.png", @"hoge.png", nil];

animationRepeatCount
アニメーションの繰り返し回数を指定
例)imageView.animationRepeatCount = 3;

animationDuration
アニメーション中の1コマが切り替わる時間を設定
例)imageView.animationDuration = 0.5;

highlighted
イメージがハイライトされているか設定
例)imageView.highlighted = YES;

userInteractionEnabled
イメージビューのタッチ検知を許可するか設定
例)imageView.userInteractionEnabled = YES;

contentMode
画像データの表示方法を設定
例)imageView.contentMode = UIViewContentModeScaleAspectFit;
表示方法
UIViewContentModeScaleToFill 設定が無い場合、これがデフォルトとなる。UIImageViewのサイズにあわせひろがる    
UIViewContentModeScaleAspectFit     画像のaspect比を維持し、UIImageViewのサイズに収まるように設置
UIViewContentModeScaleAspectFill 画像のaspect比を維持し、UIImageViewのサイズにあわせひろがる
UIViewContentModeRedraw UIViewContentModeScaleToFillと同様
UIViewContentModeCenter 画像サイズをそのままに、真ん中に表示
UIViewContentModeTop 画像サイズをそのままに、上に表示
UIViewContentModeBottom 画像サイズをそのままに、下に表示
UIViewContentModeLeft 画像サイズをそのままに、左に表示
UIViewContentModeRight 画像サイズをそのままに、右に表示
UIViewContentModeTopLeft 画像サイズをそのままに、左上に表示
UIViewContentModeTopRight 画像サイズをそのままに、右上に表示
UIViewContentModeBottomLeft 画像サイズをそのままに、左下に表示
UIViewContentModeBottomRight 画像サイズをそのままに、右下に表示

主要なインスタンスメソッド

initWithImage:
 - (id)initWithImage:(UIImage *)image
指定されたイメージにてイメージビューを初期化
例)UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hoge.png"]];

initWithImage:highlightedImage:
 - (id)initWithImage:(UIImage *)imagehighlightedImage:(UIImage *)highlightedImage
指定されたイメージとハイライトされたイメージでイメージビューを初期化
例)UIImageView *imageView = [[UIImageView alloc] initWithImage:image1 imagehighlightedImage:image2];

startAnimating
 - (void)startAnimating
アニメーションを開始する。
例)[imageView startAnimating];

stopAnimating
 - (void)stopAnimating
アニメーションを停止する。
例)[imageView stopAnimating];

isAnimating
 - (BOOL)isAnimating
現在、アニメーションが動作しているかどうかの検知
例)BOOL anime = [imageView isAnimating];
最終更新:2013年03月01日 18:03