macOS/iOS API解説

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

目次

initWithContentSize:preferredEdge:

INDEX>AppKit>NSDrawer

サイズとエッジで引き出しを作ります

Objective-C

- (instancetype)initWithContentSize:(NSSize)contentSize
                      preferredEdge:(NSRectEdge)edge

Swift

init(contentSize contentSize: NSSize,
   preferredEdge edge: NSRectEdge)

解説

サイズとエッジで引き出しを作ります。
作った後、親ウインドウをセットしないと表示されません。
【NSRectEdge】ウインドウの端
● NSMinXEdge 左
● NSMinYEdge 下
● NSMaxXEdge 右
● NSMaxYEdge 上

Swift
0=左、1=下、2=右、3=上

返り値

Objective-C

- (instancetype)initWithContentSize:(NSSize)contentSize
                      preferredEdge:(NSRectEdge)edge

Swift

init(contentSize contentSize: NSSize,
   preferredEdge edge: NSRectEdge)

引き出し

引数

サイズ
Objective-C

(NSSize)contentSize

Swift

contentSize: NSSize,

エッジ
Objective-C

(NSRectEdge)edge

Swift
0=左、1=下、2=右、3=上

edge: NSRectEdge

フレームワーク

ApplicationKit

クラス

NSDrawer

使用可能

10.0

参照

更新時のバージョン

OS X 10.10

関連記事(外部サイト)

例文

#import "MyObject.h"

@implementation MyObject
NSDrawer *dra;
- (IBAction)myAction1:(id)sender
{
dra = [[NSDrawer alloc] initWithContentSize:NSMakeSize(10,50)
preferredEdge:NSMaxYEdge
];
[dra setParentWindow:[sender window]];

[dra open:nil];
}

- (IBAction)myAction2:(id)sender
{
[dra close:nil];
}

@end

Swift

    //NSDrawer drawers
    var theDrawer001 : NSDrawer = NSDrawer(contentSize: NSMakeSize(100.0, 100.0),
        preferredEdge: 1 )
    //preferredEdge 1=下、2=右、3=上、4=右
    func buttonAction001(sender: AnyObject){
        
        var theWindow : NSWindow = (sender as NSButton).window!
        
        if ((theWindow.drawers) != nil){
            NSLog("%@", theWindow.drawers!.description)
        }
        //drawerを表示/非表示
        theDrawer001.toggle(theWindow)
        
    }
    @IBAction func function001(sender: AnyObject) {
        var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false)
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        
        //ボタンを作成
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 2.0, 100.0, 30.0))
        theButton.title = "Toggle"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("buttonAction001:")
        theButton.target = self

        aWindow.contentView.addSubview(theButton)
        
        //引き出しのウインドウを設定
        theDrawer001.parentWindow = aWindow
        
        //ウインドウの表示
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }