macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

highlight:

INDEX>AppKit>NSButton

ボタンハイライトの切り替え

Objective-C

- (void)highlight:(BOOL)flag

Swift

func highlight(_ flag: Bool)

解説

ボタンをハイライトします(または、しません)
ボタンを押したように見せます。
ボタンの現在の状態がフラグと同じならば、アクションは実行されません。

設定値

Objective-C

- (void)highlight:(BOOL)flag

Swift

func highlight(_ flag: Bool)

フレームワーク

ApplicationKit

クラス

NSButton

使用可能

10.0

参照


setButtonType: - Cocoa API解説(iOS/OS X)

例文

Objective-C

@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 highlight:YES];
	}
}

@end

Swift

    //NSButton highlight
    var hilightButton: NSButton!
    func buttonAction017(sender: AnyObject?){
        var theWindow : NSWindow = (sender as NSButton).window!
        
        hilightButton.highlight( true )

    }
    @IBAction func function017(sender: AnyObject) {
        var aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        //
        var theSwitch : NSButton = NSButton(frame: NSMakeRect(100.0, 90.0, 100.0, 30.0))
        theSwitch.title = "Switch"
        theSwitch.bezelStyle = NSBezelStyle.RegularSquareBezelStyle
        theSwitch.setButtonType(NSButtonType.PushOnPushOffButton)
        theSwitch.action = Selector("buttonAction002:")
        theSwitch.target = self
        hilightButton = theSwitch
        aWindow.contentView.addSubview(theSwitch)
        
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RegularSquareBezelStyle
        theButton.action = Selector("buttonAction017:")
        theButton.target = self
        aWindow.contentView.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
    }