setImage:
レシーバーに表示する画像をセットします
-(void)setImage:(NSImage *)image:
解説
レシーバーに表示する画像をセットします。
imageがnilなら現在表示されている画像は削除されます。
返り値
( void )
なし
引数
( NSImage * )image
セットする画像
フレームワーク
ApplicationKit
クラス
NSActionCell
Instance Methods
使用可能
10.0
参照
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { //開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObjects: @"tiff", @"png", @"jpg",nil ]; //OpenPanelを作る NSOpenPanel *opImage = [ NSOpenPanel openPanel ]; //Imageを作る NSImage *img; //OpenPanelの結果のボタン番号 int opRet; //OpenPanelでファイル選択 opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのファイルを選択しておくか types : imgTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら //NSImageを作ってファイルから読み込む img = [ [ NSImage alloc ] initWithContentsOfFile: [ opImage filename ] ]; //but1,but2は NSButtonCell [but1 setImage : img ]; [but2 setImage : img ]; } } @end