macOS/iOS API解説

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

目次

bezierPathWithRoundedRect:xRadius:yRadius:

INDEX>AppKit>NSBezierPath

角丸四角形のパスを作って返します

Objective-C

+ (NSBezierPath *)bezierPathWithRoundedRect:(NSRect)rect
                                    xRadius:(CGFloat)xRadius
                                    yRadius:(CGFloat)yRadius

Swift

init(roundedRect rect: NSRect,
         xRadius xRadius: CGFloat,
         yRadius yRadius: CGFloat) -> NSBezierPath

解説

角丸(かどまる)四角形のパスを作って返します
f:id:jjj777:20150301211548p:plain

返り値

Objective-C

Swift


フレームワーク

ApplicationKit

クラス

NSBezier

使用可能

10.0

更新時のバージョン

OS X 10.10

参照

関連記事(外部サイト)

例文

    //NSBezierPath init(roundedRect: )
    var aButton004 : NSButton?
    var aView004 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction004(sender : AnyObject?){
        //準備
        let aButton = aButton004
        let aView   = aView004
        var theWindow : NSWindow = aButton!.window!
        //準備ここまで
        
        //ビューにフォーカスを当てる
        aView?.lockFocus()
        //バックグラウンドカラーを描画
        let backgroundColor = NSColor.whiteColor()
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        
        NSColor.redColor().setStroke()
        NSColor.magentaColor().setFill()
        //角丸四角のベジェパスを作成
        let aBezier : NSBezierPath =
        NSBezierPath(roundedRect: NSMakeRect(90.0, 80.0, 120.0, 80.0),
            xRadius: 20.0,
            yRadius: 20.0)
        aBezier.fill()
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    @IBAction func function004(sender: AnyObject) {
        var 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.center()//ウインドウをスクリーンの中心に
        aWindow.title = "NSBezierPath"//タイトル設定
        //ボタン
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 0.0, 100.0, 30.0))
        theButton.title = "Action"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("viewAction004:")
        theButton.target = self
        
        aWindow.contentView.addSubview(theButton)
        //ビュー
        var theView : NSView = NSView(frame: NSMakeRect(0.0, 20.0, 300.0, 100.0))
        //レイヤーバックドにするのだ
        theView.wantsLayer = true
        aWindow.contentView.addSubview(theView)
        
        //実験ウインドウにUIパーツを渡す
        self.aButton004 = theButton    //ボタン
        self.aView004 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }