3
2

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 3 years have passed since last update.

【Swift】UIColorでカラーコードを指定する

Last updated at Posted at 2021-02-03

どういうことか

たとえばボタンの色を変更する場合、最初から用意されているカラーであればこのように指定する。

button.backgroundColor = UIColor.blue

カラーコードで細かい色を指定したい。

button.backgroundColor = UIColor.005192

こんなふうには書けない。

colorLiteralを使う

button.backgroundColor = UIColor {_ in return #colorLiteral()}

こんなふうに書くと

b3da9f855be521db0fb03e2d3bdbe04a.png

#colorLiteral() の部分がアイコンに変化する。
このアイコンをダブルクリックしてカラーコードやRGBなどいろいろ細かい指定ができる。Xcode8から使えるようになったみたいです。

【参考】
UIColorの定義はすべて#colorLiteral使ってみることにしてみた
https://medium.com/swift-column/color-literal-6223850f7e2c

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?