Created
March 25, 2020 15:42
-
-
Save ryo-takahashi/94dcd87db77113d3fd46211c4139ffa4 to your computer and use it in GitHub Desktop.
UIColorで使っているRGBの値を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
UIColor.red.ciColor.red | |
UIColor.red.ciColor.green | |
UIColor.red.ciColor.blue | |
UIColor.red.ciColor.alpha | |
// 2 | |
UIColor.yellow.cgColor.alpha | |
// 3 | |
extension UIColor { | |
var redColor: CGFloat? { | |
return self.cgColor.components?[0] | |
} | |
var greenColor: CGFloat? { | |
return self.cgColor.components?[1] | |
} | |
var blueColor: CGFloat? { | |
return self.cgColor.components?[2] | |
} | |
var alpha: CGFloat { | |
return self.cgColor.alpha | |
} | |
} | |
// 4 | |
print(UIColor.red.redColor) // Optional(1.0) | |
print(UIColor.red.blueColor) // Optional(0.0) | |
print(UIColor.red.greenColor) // Optional(0.0) | |
print(UIColor.red.alpha) // 1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment