setFrameUsingName:
指定したフレーム名でユーザーデフォルトに保存されている設定をセットします
- (BOOL)setFrameUsingName:(NSString *)frameNamefunc setFrameUsingName(_ frameName: String) -> Bool
解説
指定したフレーム名でユーザーデフォルトに保存されている設定をセットします。
セットできれば、YESを返します。
うまくいかない場合はNOを返します。
デリゲートにwindowDidResize(notification: NSNotification)メッセージが送られます。
下記サンプルでは、当初ユーザーデフォルトにウインドウフレームは保存されていないのですが、saveボタンでウインドウフレームが保存され、その後はsetボタンで保存されたウインドウフレームにセットするという事をしています。
返り値
成功したかYES/NO(true/false)
Objective-C- (BOOL)setFrameUsingName:(NSString *)frameNamefunc setFrameUsingName(_ frameName: String) -> Bool
引数
フレームの保存名
Objective-C- (BOOL)setFrameUsingName:(NSString *)frameNamefunc setFrameUsingName(_ frameName: String) -> Bool
フレームワーク
ApplicationKit
クラス
NSWindow
使用可能
10.0
参照
- setFrameAutosaveName:
+ removeFrameUsingName:
- stringWithSavedFrame
- setFrameFromString:
更新時のバージョン
OS X 10.10
関連記事(外部サイト)
例文
#import "Controller.h" @implementation Controller - (IBAction)pushButton:(id)sender { if ([myWindow setFrameUsingName: @"MainWindow"]){ NSLog(@"YES"); }else{ NSLog(@"NO"); } } @end
//NSWindow saveFrameUsingName //NSWindow setFrameUsingName //NSWindow frameAutosaveName() //NSWindow setFrameAutosaveName() //NSWindow removeFrameUsingName func buttonAction078_save(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! aWindow.setFrameAutosaveName("")//自動保存中止 //NSWindow.removeFrameUsingName("window078") aWindow.saveFrameUsingName("window078") aWindow.title = "フレームを保存しました" } func buttonAction078_set(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! if (aWindow.setFrameUsingName("window078")){ aWindow.title = "保存したフレームにしました" }else{ aWindow.title = "保存なし" } } func buttonAction078_auto(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! aWindow.setFrameAutosaveName("window078") aWindow.title = "自動保存" NSLog("frameAutosaveName %@", aWindow.frameAutosaveName()!) } func buttonAction078_remove(sender: AnyObject){ var aWindow : NSWindow = (sender as NSButton).window! NSWindow.removeFrameUsingName("window078") aWindow.title = "フレームを保存をクリア" } @IBAction func function078(sender: AnyObject) { var theWindow : MyWindow078 = MyWindow078(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false) windowArray.addObject(theWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 theWindow.center()//ウインドウをスクリーンの中心に theWindow.title = "フレーム未保存"//タイトル設定 theWindow.orderFront(self)//前面に theWindow.makeKeyAndOrderFront(self)//表示 theWindow.delegate = theWindow //ボタンを作成 var theButton1 : NSButton = NSButton(frame: NSMakeRect(0.0, 2.0, 70.0, 30.0)) theButton1.title = "Save" theButton1.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton1.action = Selector("buttonAction078_save:") theButton1.target = self theWindow.contentView.addSubview(theButton1) //ボタンを作成 var theButton2 : NSButton = NSButton(frame: NSMakeRect(70.0, 2.0, 70.0, 30.0)) theButton2.title = "Set" theButton2.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton2.action = Selector("buttonAction078_set:") theButton2.target = self theWindow.contentView.addSubview(theButton2) //ボタンを作成 var theButton3 : NSButton = NSButton(frame: NSMakeRect(140.0, 2.0, 70.0, 30.0)) theButton3.title = "auto" theButton3.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton3.action = Selector("buttonAction078_auto:") theButton3.target = self theWindow.contentView.addSubview(theButton3) //ボタンを作成 var theButton4 : NSButton = NSButton(frame: NSMakeRect(210.0, 2.0, 70.0, 30.0)) theButton4.title = "remove" theButton4.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton4.action = Selector("buttonAction078_remove:") theButton4.target = self theWindow.contentView.addSubview(theButton4) }