5
5

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.

UIColorは == で比較できる

Last updated at Posted at 2015-01-28

色を作成するロジックのテスト中に、比較できることに気づいたのでメモ。
RGBaすべてが等しいと同一とみなしてくれるみたい。

// 適当な色を作って
let c1 = UIColor(red: 1.0, green: 0.8, blue: 0.4, alpha: 0.2)
// 同じ
let c2 = UIColor(red: 1.0, green: 0.8, blue: 0.4, alpha: 0.2)
// red違い
let c3 = UIColor(red: 0.9, green: 0.8, blue: 0.4, alpha: 0.2)
// green違い
let c4 = UIColor(red: 1.0, green: 0.9, blue: 0.4, alpha: 0.2)
// blue違い
let c5 = UIColor(red: 1.0, green: 0.8, blue: 0.3, alpha: 0.2)
// alpha違い
let c6 = UIColor(red: 1.0, green: 0.8, blue: 0.4, alpha: 0.1)

c1 == c2 // true
c1 == c3 // false
c1 == c4 // false
c1 == c5 // false
c1 == c6 // false

// 規定で取得できる色も可能
let red = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
red == UIColor.redColor() // true
5
5
4

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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?