macOS/iOS API解説

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

目次

setAssociatedPoints:atIndex:

INDEX>AppKit>NSBezier

指定したエレメントを修正します

Objective-C

- (void)setAssociatedPoints:(NSPointArray)points
                    atIndex:(NSInteger)index

Swift

func setAssociatedPoints(_ points: NSPointArray,
                 atIndex index: Int)

解説

点であるインデックスでエレメントと結合される点を修正します。
このメソッドは、レシーバーを修正する。
NSBezierPathは、ラインエレメントから成る。

返り値

なし

引数

位置
Objective-C

(NSPointArray)points

Swift

points: NSPointArray

インデックス
Objective-C

(NSInteger)index

Swift

atIndex index: Int)

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

例文

Objective-C

#import "MyView.h"

@implementation MyView

// NSViewのサブクラスであるMyViewのdrawRectメソッドをオーバーライド
- (void)drawRect:(NSRect)rect {
    // 新しいベジェパスを作成
    NSBezierPath *thePath = [NSBezierPath bezierPath];
    
    // 描画するためのポイントを定義
    NSPoint points = NSMakePoint(20.0, 20.0);

    // 指定された矩形内に円を描く
    [thePath appendBezierPathWithOvalInRect:NSMakeRect(50, 50, 100, 100)];

    // 青色を設定して円を描画
    [[NSColor blueColor] set];
    [thePath stroke];

    // 3つ目のポイントをpointsに近づける
    [thePath setAssociatedPoints:&points atIndex:3];

    // 赤色を設定して変更後の円を描画
    [[NSColor redColor] set];
    [thePath stroke];
}

@end

Swift

import Cocoa

// MyViewクラスはNSViewを継承してカスタム描画を行う
class MyView: NSView {

    // draw(_:)メソッドをオーバーライドして描画処理を定義
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect) // 親クラスの描画処理を呼び出す

        // 新しいベジェパスを作成
        let thePath = NSBezierPath()
        
        // 描画するためのポイントを定義
        let points = NSPoint(x: 20.0, y: 20.0)

        // 指定された矩形内に円を描く
        thePath.appendOval(in: NSRect(x: 50, y: 50, width: 100, height: 100))

        // 青色を設定して円を描画
        NSColor.blue.set()
        thePath.stroke()

        // 3つ目のポイントをpointsに近づける
        thePath.setAssociatedPoints(&points, at: 3)

        // 赤色を設定して変更後の円を描画
        NSColor.red.set()
        thePath.stroke()
    }
}