macOS/iOS API解説

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

目次

colorWithDeviceHue:saturation:brightness:alpha:

INDEX>AppKit>NSColor

HSBとアルファでNSColorを作って返します
+(NSColor *)colorWithDeviceHue:(CGFloat)hue:
          saturation:(CGFloat)saturation:
          brightness:(CGFloat)brightness:
          alpha:(CGFloat)alpha:

解説

HSBとアルファでNSColorを作って返します。
0.0以下の値は0.0、1.0より上の値は1.0になります。

返り値

( NSColor * )

カラー

引数

( CGFloat )hue

H値0.0-1.0

( CGFloat )saturation

S(彩度)値0.0-1.0

( CGFloat )brightness

B(輝度)値0.0-1.0

( CGFloat )alpha

アルファ値0.0-1.0

フレームワーク

ApplicationKit

クラス

NSColor

使用可能

10.0

参照

+ colorWithCalibratedHue:saturation:brightness:alpha:
+ colorWithDeviceRed:green:blue:alpha:
- getHue:saturation:brightness:alpha:

例文

#import "Controller.h"

@implementation Controller

- (IBAction)myAction:(id)sender
{
	NSColor *theColor = [NSColor colorWithDeviceHue:1 saturation:0.3 brightness:0.8 alpha:1];//カラー作成
	
	[name setStringValue:@"HueColor"];//outlet nameに文字をセット
	[name setTextColor:theColor];//outlet name(text field)の文字色をtheColorにする
	[h setFloatValue:[theColor hueComponent]];//
	[s setFloatValue:[theColor greenComponent]];//
	[b setFloatValue:[theColor brightnessComponent]];//
	[alpha setFloatValue:[theColor alphaComponent]];//
}

@end
    // MARK: NSColor colorWithDeviceHue:saturation:brightness:alpha:
    // http://cocoaapi.hatenablog.com/entry/00120607/ApplicationKit_NSColor_colorWithDeviceHue_saturation_brightness_alpha_
    var aButton009 : NSButton?
    var aView009 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction009(sender : AnyObject?){
        //準備
        let aView   = aView009
        //準備ここまで
        
        aView?.lockFocus()
        //
        let backgroundColor = NSColor(deviceHue: 0.5,//0.0-1.0
                                    saturation: 0.8,//0.0-1.0
                                    brightness: 1.0,//0.0-1.0
                                    alpha: 1.0)     //0.0-1.0
        
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        aView?.unlockFocus()
        
    }
    @IBAction func function009(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("viewAction009:")
        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.aButton009 = theButton    //ボタン
        self.aView009 = theView        //テストビュー
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        
    }