macOS/iOS API解説

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

目次

lineCapStyle

INDEX>AppKit>NSBezier

ベジエパスのラインキャップスタイルを返します

Objective-C

@property NSLineCapStyle lineCapStyle

Swift

var lineCapStyle: NSLineCapStyle

解説

ベジエパスのラインキャップスタイルを返します。
【NSLineCapStyle】
● NSButtLineCapStyle すぱっと切れた端
● NSRoundLineCapStyle 丸い端
● NSSquareLineCapStyle 四角い端

設定値

Objective-C

@property NSLineCapStyle lineCapStyle

Swift

var lineCapStyle: NSLineCapStyle

線端形状

引数

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照


setLineCapStyle: - Cocoa API解説(iOS/OS X)


defaultLineCapStyle - Cocoa API解説(iOS/OS X)


setDefaultLineCapStyle: - Cocoa API解説(iOS/OS X)

関連記事(外部サイト)

例文

Objective-C

#import "MyView.h"

@implementation MyView

//NSViewのサブクラス MyViewのDrawRectに上書き
-(void)drawRect:(NSRect)rect
{

NSBezierPath *thePath = [NSBezierPath bezierPath];

[thePath moveToPoint:NSMakePoint(200,200)];
[thePath lineToPoint:NSMakePoint(200,200)];


[thePath appendBezierPathWithArcFromPoint:NSMakePoint(250,250) toPoint:NSMakePoint(0,250) radius:100];

[[NSColor blueColor] set];

[thePath stroke];
if([thePath lineCapStyle] ==NSButtLineCapStyle){
    NSLog(@"NSButtLineCapStyle");
}else{
    NSLog(@"other");
}

}

@end

Swift

    //NSBezierPath lineCapStyle
    var aButton025 : NSButton?
    var aView025 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction025(sender : AnyObject?){
        //準備
        let aButton = aButton025
        let aView   = aView025
        var theWindow : NSWindow = aButton!.window!
        //準備ここまで
        
        //ビューにフォーカスを当てる
        aView?.lockFocus()
        //バックグラウンドカラーを描画
        let backgroundColor = NSColor.whiteColor()
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        
        //ここ
        //NSBezierPath.setDefaultLineCapStyle(.ButtLineCapStyle)
        //NSBezierPath.setDefaultLineCapStyle(.RoundLineCapStyle)
        NSBezierPath.setDefaultLineCapStyle(.SquareLineCapStyle)
        NSColor.magentaColor().setStroke()
        //空のベジェパスを作成
        let aBezier : NSBezierPath = NSBezierPath()
        aBezier.moveToPoint(CGPoint(x: 95.00,y: 45.00))
        //線を引く
        aBezier.lineToPoint(CGPoint(x: 185.00,y: 60.00))
        aBezier.lineToPoint(CGPoint(x: 130.00,y: 150.00))
        
        //SquareLineCapStyleで描画
        aBezier.lineWidth = 40.0
        aBezier.stroke()
        
        //同じ線をButtLineCapStyleで描画
        NSColor.yellowColor().setStroke()
        aBezier.lineCapStyle = .ButtLineCapStyle
        aBezier.stroke()
        
        //ガイド
        aBezier.appendBezierPathWithOvalInRect(NSMakeRect(130-30.0, 150.0-30.0, 60.0, 60.0))
        aBezier.lineWidth = 2.0
        NSColor.redColor().setStroke()
        aBezier.stroke()
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        switch (aBezier.lineCapStyle ){
        case .ButtLineCapStyle:
            NSLog("ButtLineCapStyle")
        case .RoundLineCapStyle:
            NSLog("RoundLineCapStyle")
        case .SquareLineCapStyle:
            NSLog("SquareLineCapStyle")
        default:
            NSLog("default")
        }
        
        NSLog("!!! %@",aBezier.description)
    }
    //実験用ウインドウ作成、実験用ビュー、実行ボタンを作成してウインドウに貼り付けるところまで
    @IBAction func function025(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("viewAction025:")
        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.aButton025 = theButton    //ボタン
        self.aView025 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

更新時バージョン

10.10