setImage:
ボタンに画像をセットして再描画します
-(void)setImage:(NSImage *)image:
解説
ボタンに画像をセットして再描画します。
返り値
( void )
なし
引数
( NSImage * )image
セットする画像
フレームワーク
ApplicationKit
クラス
NSButton
使用可能
10.0
参照
setImagePosition: - Cocoa API解説(iOS/OS X)
setAlternateImage: - Cocoa API解説(iOS/OS X)
setButtonType: - Cocoa API解説(iOS/OS X)
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { //開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObject : @"tiff" ]; //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 ] ]; //ボタンにImageをセット [but1 setImage : img ]; //but1の画像を取得してbut2にセット [but2 setImage : [but1 image] ]; } } @end