fillRect:
aRectで塗りつぶし四角形を描画します
+ (void)fillRect:(NSRect)aRectclass func fillRect(_ aRect: NSRect)
解説
aRectで塗りつぶし四角形を描画します。
現在描画対象のグラフィックスコンテキストに保管されている現在のカラーで、aRectによって指定される矩形のパスを塗ります。
返り値
なし
引数
塗る範囲
Objective-C(NSRect)aRect(_ aRect: NSRect)
フレームワーク
ApplicationKit
クラス
NSBezierPath
使用可能
10.0
参照
appendBezierPathWithRect: - Cocoa API解説(iOS/OS X)
bezierPathWithRect: - Cocoa API解説(iOS/OS X)
strokeRect: - Cocoa API解説(iOS/OS X)
- set (NSColor)
関連記事(外部サイト)
例文
#import "MyView.h" @implementation MyView //NSViewのサブクラス MyViewのDrawRectに上書き -(void)drawRect:(NSRect)rect { NSBezierPath *thePath1 = [NSBezierPath bezierPath]; [thePath1 setWindingRule:NSEvenOddWindingRule]; [thePath1 moveToPoint:NSMakePoint(20,20)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(50,50,100,100)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(20,20,80,80)]; [[NSColor redColor] set]; [thePath1 fill]; [[NSColor blueColor] set]; [NSBezierPath fillRect:NSMakeRect(0,0,30,30)]; } @end//NSBezierPath fillRect() //NSBezierPath strokeRect() var aButton032 : NSButton? var aView032 : NSView? //実験用ビューのボタンを押した時に実行されるところ func viewAction032(sender : AnyObject?){ //準備 let aButton = aButton032 let aView = aView032 var theWindow : NSWindow = aButton!.window! //準備ここまで //ビューにフォーカスを当てる aView?.lockFocus() //バックグラウンドカラーを描画 let backgroundColor = NSColor.whiteColor() backgroundColor.setFill() NSRectFill(NSMakeRect(0, 20, 300.0, 200.0)) NSColor.redColor().setStroke() NSColor.magentaColor().setFill() NSBezierPath.fillRect(CGRect(x: 50.0, y: 50.0, width: 100.0, height: 100.0)) NSBezierPath.strokeRect(CGRect(x: 50.0, y: 50.0, width: 100.0, height: 100.0)) //ビューからフォーカスを外す aView?.unlockFocus() } @IBAction func function032(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("viewAction032:") 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.aButton032 = theButton //ボタン self.aView032 = theView //テストビュー aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }
更新時バージョン
10.10