/// UIColorの拡張
extension UIColor {
/// 16進数での色指定
///
/// - Parameter rgb: 16進数での指定色
convenience init(rgb: Int32) {
let r = CGFloat((rgb & 0xFF0000) >> 16) / 255.0
let g = CGFloat((rgb & 0x00FF00) >> 8) / 255.0
let b = CGFloat(rgb & 0x0000FF) / 255.0
self.init(red: r, green: g, blue: b, alpha: 1.0)
}
//-----------------------------------------------------------------------------
/// 16進数での色指定(アルファチャンネル付)
///
/// - Parameter rgba: 16進数での指定色
convenience init(rgba: Int64) {
let r: CGFloat = CGFloat((rgba & 0xFF000000) >> 24) / 255.0
let g: CGFloat = CGFloat((rgba & 0x00FF0000) >> 16) / 255.0
let b: CGFloat = CGFloat((rgba & 0x0000FF00) >> 8) / 255.0
let a: CGFloat = CGFloat(rgba & 0x000000FF) / 255.0
self.init(red: r, green: g, blue: b, alpha: a)
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme