macOS/iOS API解説

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

目次

initWithAppearanceNamed:bundle:

INDEX>AppKit>NSAppearance

バンドルと名前でNSAppearanceオブジェクトのインスタンスを初期化して返します

Objective-C

- (instancetype)initWithAppearanceNamed:(NSString *)name
                                 bundle:(NSBundle *)bundle

Swift

init?(appearanceNamed name: String,
               bundle bundle: NSBundle?)

解説

指定のバンドルで指定された名前のアピアランスからNSAppearanceオブジェクトのインスタンスを初期化して返します。

返り値

初期化されたオブジェクト。
エラーが発生すればnil
Objective-C

instancetype

NSAppearance

Swift

NSAppearance 

引数

【name】
アピアランスファイル名
Objective-C

(NSString *)name

Swift

name: String,

【bundle】
アピアランスファイルが含まれるバンドル
Objective-C

(NSBundle *)bundle

Swift

bundle: NSBundle?

フレームワーク

ApplicationKit

クラス

NSAppearance

使用可能

10.9-

更新時のバージョン

OS X 10.11

参照

関連記事

例文

Objective-C

Swift
f:id:jjj777:20151103144730p:plain

    //NSAppearance initWithAppearanceNamed:bundle:
    //http://cocoaapi.hatenablog.com/entry/Appkit/NSAppearance/initWithAppearanceNamed_bundle_
    @IBAction func function001( sender: AnyObject) {
        //アピアランスの変更
        let ap : NSAppearance = NSAppearance(named: NSAppearanceNameVibrantDark)!
        
        let 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.appearance = ap
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        //
        let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0))
        theButton.title = "Change"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("buttonAction001:")
        theButton.target = self
        theButton.setButtonType(.MomentaryLightButton)
        //.SwitchButton
        //.PushOnPushOffButton
        aWindow.contentView!.addSubview(theButton)
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
        
    }