toggleToolbarShown:
ツールバーの表示・非表示を切り替えます
- (void)toggleToolbarShown:(id)senderfunc toggleToolbarShown(_ sender: AnyObject?)
解説
ツールバーの表示・非表示を切り替えます。
返り値
なし
引数
送信オブジェクト
Objective-C- (void)toggleToolbarShown:(id)senderfunc toggleToolbarShown(_ sender: AnyObject?)
フレームワーク
ApplicationKit
クラス
NSWindow
使用可能
10.1
参照
更新時のバージョン
OS X 10.10
関連記事(外部サイト)
例文
#import "Toggle.h" @implementation Toggle - (IBAction)myAction:(id)sender { [myOutlet toggleToolbarShown:nil]; } @end
//NSWindow toolbar //NSWindow toggleToolbarShown //NSWindow runToolbarCustomizationPalette func buttonAction083_toggle(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! aWindow.toggleToolbarShown(self) } func buttonAction083_custom(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! aWindow.runToolbarCustomizationPalette(self) NSLog("custom") } func toolBarAction083(sender: AnyObject){ NSLog("!!!") } //NSToolbarDelegate にはこの3つのメソッドが必要 var toolBarArray : [String] = ["toolBarItem1",NSToolbarSeparatorItemIdentifier,"SearchDocToolbarItemIdentifier"] func toolbarAllowedItemIdentifiers(toolbar: NSToolbar) -> [AnyObject] { return toolBarArray } func toolbarDefaultItemIdentifiers(toolbar: NSToolbar) -> [AnyObject] { return toolBarArray } func toolbar(toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: String, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { var aToolBarItem : NSToolbarItem = NSToolbarItem() if ( itemIdentifier == "SearchDocToolbarItemIdentifier"){ aToolBarItem = NSToolbarItem(itemIdentifier: "SearchDocToolbarItemIdentifier") aToolBarItem.label = "Search" aToolBarItem.paletteLabel = "Search" aToolBarItem.toolTip = "Search item" //検索 let searchFieldOutlet : NSSearchField = NSSearchField(frame: NSMakeRect(0.0, 0.0, 100.0,30.0)) aToolBarItem.view = searchFieldOutlet }else if( itemIdentifier == "toolBarItem1" ){ aToolBarItem = NSToolbarItem(itemIdentifier: "toolBarItem1") aToolBarItem.label = "item 1" aToolBarItem.paletteLabel = "item 1" aToolBarItem.toolTip = "toolbar item 1 " aToolBarItem.image = NSImage(named: "toolbarImage") aToolBarItem.action = Selector("toolBarAction083:") aToolBarItem.target = self }else{ } return aToolBarItem } @IBAction func function083(sender: AnyObject) { var theWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false) windowArray.addObject(theWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 //ボタンを作成 let theButton1 : NSButton = NSButton(frame: NSMakeRect(50.0, 2.0, 100.0, 30.0)) theButton1.title = "Toggle" theButton1.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton1.action = Selector("buttonAction083_toggle:") theButton1.target = self theWindow.contentView.addSubview(theButton1) //ボタンを作成 let theButton2 : NSButton = NSButton(frame: NSMakeRect(150.0, 2.0, 100.0, 30.0)) theButton2.title = "Custom" theButton2.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton2.action = Selector("buttonAction083_custom:") theButton2.target = self theWindow.contentView.addSubview(theButton2) //ツールバーを作成 let theToolBar : MyToolbar083 = MyToolbar083(identifier: "mainToolBar") theToolBar.delegate = self //ツールバーの表示モード theToolBar.displayMode = NSToolbarDisplayMode.IconAndLabel //アイコントラベル //theToolBar.displayMode = NSToolbarDisplayMode.IconOnly //アイコンのみ //theToolBar.insertItemWithItemIdentifier("toolBarItem1", atIndex: 0) theWindow.toolbar = theToolBar //ウインドウの表示 theWindow.center()//ウインドウをスクリーンの中心に theWindow.title = "ウインドウタイトル"//タイトル設定 theWindow.orderFront(self)//前面に theWindow.makeKeyAndOrderFront(self)//表示 }