screens
利用可能なスクリーンの配列を返します
+ (NSArray *)screens
class func screens() -> [AnyObject]?
解説
利用可能なスクリーンの配列を返します。
スクリーンの情報を取得できなければNSWindowServerCommunicationExceptionを起こします。
スクリーンは動的に変更されることができるので配列は保持しません。
返り値
スクリーンの配列
Objective-C(NSArray *)[AnyObject]?
引数
なし
フレームワーク
ApplicationKit
クラス
NSScreen
使用可能
10.0
参照
更新時のバージョン
OS X 10.10.3
Swift1.2
関連記事(外部サイト)
例文
NSLog([[NSScreen screens] description]);
//NSWindow mainScreen() //NSWindow deepestScreen() //NSWindow screens() @IBAction func function001(sender: AnyObject) { let theScreen : NSScreen = NSScreen.mainScreen()! NSLog("main screen size= (%.2f✕%.2f)", Float(theScreen.frame.size.width), Float(theScreen.frame.size.height) ) //-> main screen size= (1366.00✕768.00) let deepestScreen : NSScreen = NSScreen.deepestScreen()! NSLog("deepestScreen screen depth= %d", NSBitsPerPixelFromDepth(deepestScreen.depth) ) //-> deepestScreen screen depth= 24 let screenArray : [AnyObject] = NSScreen.screens()! for value in screenArray { NSLog("screen size= (%.2f✕%.2f)", Float(value.frame.size.width), Float(value.frame.size.height) ) } //-> screen size= (1366.00✕768.00) //-> screen size= (1920.00✕1080.00) var window : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false, screen: theScreen ) windowArray.addObject(window) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 window.center()//ウインドウをスクリーンの中心に window.title = "ウインドウタイトル"//タイトル設定 window.orderFront(self)//前面に window.makeKeyAndOrderFront(self)//表示 }