alternateImage
ボタンを押し込んだときに表示される画像を返します
解説
ボタンを押し込んだときに表示される画像を返します。
画像がなければnilを返します。
ボタンタイプによって画像を表示しないことに注意。
ボタンは、デフォルトで画像を表示しない。
返り値
( NSImage * )
画像
引数
フレームワーク
ApplicationKit
クラス
NSButtonCell
Instance Methods
使用可能
10.0
参照
- imagePosition
- keyEquivalent
- setButtonType:
- image (NSCell)
例文
#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をセット [bCell1 setAlternateImage : img ]; //but1の画像を取得してbut2にセット [bCell2 setAlternateImage : [bCell1 alternateImage] ]; } } @end