setAlternateImage:
解説
ボタンを押し込んだときにボタンに表示される画像をセットします。
behaviorがMomentary Changeになっている必要があります。
タイプによって代理の画像を表示しないボタンがあります。
返り値
( void )
なし
引数
( NSImage * )image
セットする画像
フレームワーク
ApplicationKit
クラス
NSButton
Instance Methods
使用可能
10.0
参照
- setButtonType:
- setImage:
例文
- (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 setAlternateImage : img ]; //but1の画像を取得してbut2にセット [but2 setImage : [but1 alternateImage] ]; } } @end