【发布时间】:2015-11-06 02:55:49
【问题描述】:
我在this tutorial 之后创建了一个自定义调色板。
如何以编程方式使用我的自定义颜色?
【问题讨论】:
-
如果oyu自己破解并发布您尝试的代码,您将获得更好的响应。如果不是这样,您可能需要发布更多详细信息
我在this tutorial 之后创建了一个自定义调色板。
如何以编程方式使用我的自定义颜色?
【问题讨论】:
首先只需将样本文件复制(添加)到您的项目资源中。
// get plist file URL
if let plistURL = NSBundle.mainBundle().URLForResource("NSColorPanelSwatches", withExtension: "plist") {
// load plist data
if let plistData = NSData(contentsOfURL: plistURL) {
// decode the colors stored at your swatches plist file
if let colorsArray = NSKeyedUnarchiver(forReadingWithData: plistData).decodeObjectForKey("NSSwatchColorArray") as? [UIColor] {
for color in colorsArray {
print(color.description)
}
}
}
}
【讨论】:
我猜你想阅读.clr 文件而不是~/Library/Colors 的plist。如果是这样,请使用NSColorList:
let colorList = NSColorList(name: "mylist", fromFile: "/path/to/file.clr")!
let color = colorList.colorWithKey("my color name") // return an NSColor
my color name 是您在该颜色井中时给出的名称。
【讨论】: