3
私は、ユーザーが描画する色を選択できるボタン付きのiOS描画アプリケーションを持っています。私のブラシはRGB値を使用しますが、色定数はUIColorsなので、変換する必要があります。私は試しましたどのようにしてUIColorのRGB値にアクセスできますか?
private var currentButton: UIButton? {
willSet{
currentButton?.layer.borderWidth = 0
}
didSet{
currentButton?.layer.borderWidth = 2
let index = (currentButton?.tag)! - 1
drawView.brush.blue = colors[index].ciColor.blue //Here is where I get the error
drawView.brush.green = colors[index].ciColor.green
drawView.brush.red = colors[index].ciColor.red
}
}
私は別のStackOverflowの質問で見つけました。私は8行目のRGB値を取得しようとすると、しかし、私はこのエラーを取得する:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -CIColor not defined for the UIColor UIExtendedSRGBColorSpace 1 1 1 1; need to first convert colorspace.'
それは明らかに私は、色空間を変換する必要があると述べています。しかし、CIColor.colorSpace
は取得専用です。私は間違って何をしていますか?
'のvar ciColor:CIColorは、受信機に関連付けられ 説明\tコアイメージの色を{}得ます。 カラーオブジェクトがCore Imageカラーで初期化されていない場合、このプロパティは例外をスローします。 ' –
CoreImage.CIColor初期化子を使用して、UIColor CoreImage.CIColor(color:colors [index])から新しいカラーを作成できます。オプションで返さないという利点があります。 –