appendBezierPathWithPoints:count:
頂点の列で線を引きます
- (void)appendBezierPathWithPoints:(NSPointArray)points count:(NSInteger)countfunc appendBezierPathWithPoints(_ points: NSPointArray, count count: Int)
解説
頂点の列で線を引きます。
返り値
なし
引数
頂点の位置(NSPoint)の配列
Objective-C(NSPointArray)pointspoints: NSPointArray
頂点の数
Objective-Ccount:(NSInteger)countcount: Int
フレームワーク
ApplicationKit
クラス
NSBezierPath
使用可能
10.0
例文
#import "MyView.h" @implementation MyView //NSViewのサブクラス MyViewのDrawRectに上書き -(void)drawRect:(NSRect)rect { NSFont *font =[NSFont fontWithName:@"Osaka" size:36.0]; NSBezierPath *fontPath = [NSBezierPath bezierPath]; //NSGlyph glyph= [font glyphWithName:@"a"]; NSGlyph glyph= 8000; char *chars = "string"; NSBezierPath *thePath = [NSBezierPath bezierPath]; NSPoint point1 = NSMakePoint(100, 190); NSPoint point2 = NSMakePoint(80, 130); NSPoint point3 = NSMakePoint(30, 100); //NSPoint point4 = NSMakePoint(130, 120); //NSPoint point5 = NSMakePoint(140, 130); //NSPoint point6 = NSMakePoint(150, 130); [thePath moveToPoint:NSMakePoint(50,50)]; [thePath lineToPoint:NSMakePoint(150,120)]; //[thePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(150,120,3,3)]]; [thePath appendBezierPathWithPoints:&point1 count:1]; [thePath appendBezierPathWithPoints:&point2 count:2]; [thePath appendBezierPathWithPoints:&point3 count:3]; //[thePath appendBezierPathWithPoints:&point4 count:4]; //[thePath appendBezierPathWithPoints:&point5 count:5]; //[thePath appendBezierPathWithPoints:&point6 count:6]; //[thePath closePath]; [[NSColor redColor] set]; [thePath fill]; [NSBezierPath drawPackedGlyphs:chars atPoint:NSMakePoint(20,20)]; [fontPath moveToPoint:NSMakePoint(150,120)]; [fontPath appendBezierPathWithGlyphs:&glyph count:1 inFont:font ]; [[NSColor blueColor] set]; [fontPath stroke]; [fontPath fill]; } @end//NSBezierPath var aButton011 : NSButton? var aView011 : NSView? func blankof<T>(type:T.Type) -> T { var ptr = UnsafeMutablePointer<T>.alloc(sizeof(T)) var val = ptr.memory ptr.destroy() return val } //実験用ビューのボタンを押した時に実行されるところ func viewAction011(sender : AnyObject?){ //準備 let aButton = aButton011 let aView = aView011 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() aBezier.moveToPoint(CGPoint(x: 80.0,y: 50.0)) //ここから var points:[NSPoint] = [NSMakePoint(220.0, 50.0), NSMakePoint(220.0,120.0), NSMakePoint(150.0,180.0), NSMakePoint( 80.0,120.0), NSMakePoint( 80.0, 50.0)] aBezier.appendBezierPathWithPoints( &points, count: points.count) //ここまで aBezier.closePath() aBezier.fill() aBezier.lineWidth = 2.0 aBezier.stroke() //ビューからフォーカスを外す aView?.unlockFocus() NSLog("!!! %@",aBezier.description) } @IBAction func function011(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("viewAction011:") 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.aButton011 = theButton //ボタン self.aView011 = theView //テストビュー aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }
更新時バージョン
10.10