iPhone開発の記事は、テキストベースのブログでは表現しにくいのですが...
まず、"View-based Application"プロジェクト(Test02)を作成します。
次にヘッダファイルを以下のように、UIImageViewを宣言した形で作成します。
--------【Test02ViewController.h】--------
#import <UIKit/UIKit.h>
@interface Test02ViewController : UIViewController {
UIImageView *imageView;
}
@property(nonatomic, retain) IBOutlet UIImageView *imageView;
@end
--------
対応する実装ファイルは、"viewDidLoad"のところで、
表示したい画像(test.png)を指定したUIImageを、
UIImageView(imageView)のimageに代入するようにします。
("test.png"はプロジェクト直下に置いてあります)
--------【Test02ViewController.m】--------
#import "Test02ViewController.h"
@implementation Test02ViewController
@synthesize imageView;
- (void)viewDidLoad {
[super viewDidLoad];
imageView.image = [UIImage imageNamed:@"test.png"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
--------
最後にInterface Builder"の処理です。
Resources下にある、Test02ViewController.xibを選択し、
"Interface Builder"を立ち上げます。
そして、Libraryの"Image View"(UIImageView)をViewウィンドウに
ドラッグアンドドロップします。
その後、ドロップされたUIImageViewは"File's Owener"(Test02ViewController)の
Inspector上にあるOutletsの一つである"imageView"と結びつけます。
("imageView"の右端の丸をCtrl押しながら結びつけます)
これでシミュレーターなどの画像で実行すると、
"test.png"がiPhone上に表示されるはずです。
上記の説明で、未来の自分はわかるのかなー?
--------
http://www.suz-lab.com
0 コメント:
コメントを投稿