colorWithCatalogName:colorName:
カタログ名とカラー名でカラーを作って返します
Swift4.2
init?(catalogName listName: NSColorList.Name, colorName: NSColor.Name)
+ (NSColor *)colorWithCatalogName:(NSString *)listName colorName:(NSString *)colorName
解説
カタログ名とカラー名でカラーを作って返します。
引数
( NSString * )listName
Swift
NSColorList
カラーリスト
( NSString * )colorName
Swift
NSColorList.Name
カラー名
フレームワーク
ApplicationKit
クラス
NSColor
使用可能
10.0
編集時のバージョン
10.14.5
Swift4.2
例文
#import "Controller.h" @implementation Controller - (IBAction)myAction:(id)sender { //NSColor *theColor = [NSColor colorWithCatalogName:@"System" colorName:@"controlAlternatingRowColor"];//カラー作成 NSColor *theColor = [NSColor colorWithCatalogName:@"System" colorName:@"scrollBarColor"];//カラー作成 NSLog(@"%@",[theColor colorSpaceName]); [name setStringValue:@"controlAlternatingRowColor"];//outlet nameに文字をセット [name setTextColor:theColor];//outlet name(text field)の文字色をtheColorにする } @end
Swift4.2
class MyView004: NSView { override func draw(_ rect: CGRect) { // let cLists : Array = NSColorList.availableColorLists for cList : NSColorList in cLists { print(cList.name as Any) let colorKeyArray : [NSColor.Name] = cList.allKeys for value in colorKeyArray { let color : NSColor = cList.color(withKey: value)! print(value) //->e.g. selectedControlColor print(color.description) //->e.g. Catalog color: System selectedControlColor } } // let rectColor = NSColor(catalogName: "System", colorName: "scrollBarColor") let path = NSBezierPath() path.move(to: CGPoint(x: 100, y: 100)) path.appendRect(NSMakeRect(0.0, 0.0, 1500.0, 900.0)) path.lineWidth = 5.0 // 線の太さ rectColor?.setFill() // 色をセット path.fill() } }
Swift
//NSColor
//colorWithCatalogName:colorName:
var aButton007 : NSButton?
var aView007 : NSView?
//実験用ビューのボタンを押した時に実行されるところ
func viewAction007(sender : AnyObject?){
//準備
let aView = aView007
//準備ここまで
aView?.lockFocus()
//システムカラーのcontrolAlternatingRowColor
let backgroundColor = NSColor(catalogName: "System", colorName: "controlAlternatingRowColor")!
//新しいパレット「NewPalette」に新しい色「new1」を作っている
//let backgroundColor = NSColor(catalogName: "NewPalette", colorName: "new1")!
//
backgroundColor.setFill()
NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
aView?.unlockFocus()
}
@IBAction func function007(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("viewAction007:")
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.aButton007 = theButton //ボタン
self.aView007 = theView //テストビュー
aWindow.orderFront(self)//前面に
aWindow.makeKeyAndOrderFront(self)//表示
}
