macOS/iOS API解説

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

目次

setLineDash:count:phase:

INDEX>AppKit>NSBezier

ラインのパターン(点線など)をセットします

Objective-C

- (void)setLineDash:(const CGFloat *)pattern
              count:(NSInteger)count
              phase:(CGFloat)phase

Swift

func setLineDash(_ pattern: UnsafePointer<CGFloat>,
           count count: Int,
           phase phase: CGFloat)

解説

ラインのパターン(点線など)をセットします。
patternはfloatの配列で、塗り・空き・塗り・空き...を繰り返します。
countは上記の要素数で、「塗り・空き」なら2となる。
phaseはパターンを開始するポイント。

f:id:jjj777:20150313075146p:plain

返り値

なし

引数

塗り、空きの配列
Objective-C

(const CGFloat *)pattern

Swift

pattern: UnsafePointer<CGFloat>
( const float * )pattern

塗り、空きの配列の要素数
Objective-C

count:(NSInteger)count

Swift

count count: Int,

書き始め(ポイント)
Objective-C

phase:(CGFloat)phase

Swift

phase phase: CGFloat)

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

- getLineDash:count:phase:

関連記事(外部サイト)


Swift - NSBezierPathで点線を描画する - Qiita

例文

#import "MyView.h"

@implementation MyView

//NSViewのサブクラス MyViewのDrawRectに上書き
-(void)drawRect:(NSRect)rect
{
float array[5];
NSBezierPath *thePath = [NSBezierPath bezierPath];

[NSBezierPath setDefaultLineJoinStyle:NSBevelLineJoinStyle];

[thePath moveToPoint:NSMakePoint(20,20)];
[thePath lineToPoint:NSMakePoint(120,120)];
[thePath lineToPoint:NSMakePoint(40,20)];


[thePath appendBezierPathWithRect:NSMakeRect(50,50,100,100)];
[thePath setFlatness:0.5];
[thePath setLineWidth:5];
[[NSColor redColor] set];

array[0] = 8.0; //塗る
array[1] = 3.0; //塗らない
array[2] = 20.0; //塗る
array[3] = 3.0; //塗らない
[thePath setLineDash: array count: 4 phase: 0.0];

[thePath stroke];
//NSLog([NSString stringWithFormat:@"%.1f",[thePath flatness]]);

}

@end




更新時のバージョン

OS X 10.10