26
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swiftでUIColorではなくCGColorを使いたい時

Last updated at Posted at 2016-05-06

問題

UIButtonの枠線の色を指定する際に

button.layer.borderColor = UIColor.greenColor()

のようにすると

cannot assign value of type "UIColor" to type "CGColor?"

というエラーで怒れました。

これは、

「ボタンのボーダーカラーにはCGColorは使えるけど、UIColorは使えないよっ!」

ってことなので、CGColorの型を使う必要があります。

解決策

こんなときは

button.layer.borderColor = UIColor.greenColor().CGColor

として、後ろに.CGColorをつけるだけで解決できました!!!

26
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?