CGColorCreate
Core Graphicsカラーを作成します。
CGColorRef CGColorCreate ( CGColorSpaceRef colorspace, const CGFloat components[] );
Apple iPod nano 16GB スレート MD481J/A <第7世代>
- 出版社/メーカー: Apple Computer
- 発売日: 2012/10/09
- メディア: エレクトロニクス
- 購入: 3人 クリック: 170回
- この商品を含むブログ (15件) を見る
解説
返り値
引数
参照
- (void)drawRect:(CGRect)rect { #ifdef TARGET_OS_IPHONE // iPhone SDK の API を使用して CGContextRef を取得する CGContextRef context = UIGraphicsGetCurrentContext(); //アンチエイリアス //CGContextSetAllowsAntialiasing(context, false); #else CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; #endif //コンテキストに線のカラーをセットします。 float col[4]; col[0] = 1.0; col[1] = 1.0; col[2] = 0.5; col[3] = 0.5; CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); CGColorRef color = CGColorCreate(space,col); CGContextSetFillColorWithColor(context,color); //CGContextSetRGBFillColor(context, 0, 0, 0.5, 1); //弧の位置 CGPoint theLocation;// theLocation = CGPointMake(200.0, 200.0); //弧をパスに加える CGContextAddArc(context, theLocation.x, theLocation.y, 100, radians(0), radians(270), 0); CGContextFillPath(context); CGColorRelease(color); }
Swift
//CGColorRef CGColorCreate //http://cocoaapi.hatenablog.com/entry/00100520/ApplicationServices_CoreGraphics_CGColor_CGColorCreate var aButton001 : NSButton? var aView001 : NSView? //実験用ビューのボタンを押した時に実行されるところ func viewAction001(sender : AnyObject?){ //準備 //let aButton = aButton001 let aView = aView001 //var theWindow : NSWindow = aButton!.window! //準備ここまで let space : CGColorSpaceRef = CGColorSpaceCreateDeviceRGB()! let color : CGColorRef = CGColorCreate(space,[1.0,1.0,0.5,0.5])! aView?.lockFocus() let backgroundColor = NSColor(CGColor: color) backgroundColor!.setFill() NSRectFill(NSMakeRect(0, 20, 300.0, 178.0)) aView?.unlockFocus() NSLog("!!! %@",aView!.description) } @IBAction func function001(sender: AnyObject) { let 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 = "View アクション"//タイトル設定 //ボタン let theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 10.0, 100.0, 30.0)) theButton.title = "Color!" theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton.action = Selector("viewAction001:") theButton.target = self aWindow.contentView!.addSubview(theButton) //ビュー let theView : NSView = NSView(frame: NSMakeRect(0.0, 30.0, 300.0, 180.0)) theView.wantsLayer = true aWindow.contentView!.addSubview(theView) //実験ウインドウにUIパーツを渡す self.aButton001 = theButton //ボタン self.aView001 = theView //テストビュー aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }