extension UIColor {
convenience init(hexCode: String, alpha: CGFloat = 1.0) {
var hexFormatted: String = hexCode.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased()
if hexFormatted.hasPrefix("#") {
hexFormatted = String(hexFormatted.dropFirst())
}
assert(hexFormatted.count == 6, "Invalid hex code used.")
var rgbValue: UInt64 = 0
Scanner(string: hexFormatted).scanHexInt64(&rgbValue)
self.init(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> :선글라스: / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: alpha)
}
}
segmentControl.backgroundColor = UIColor(hexCode: "A4BB94", alpha: 1.0)
'🍎 Swift > iOS 학습 노트' 카테고리의 다른 글
[강의노트👩🏻💻] ViewController 생명주기 이론 (0) | 2024.07.09 |
---|---|
[🍎 Swift 문법] sort 와 sorted (0) | 2024.07.09 |
[Xcode] Preview 내가만든 인터페이스 미리보기 (1) | 2024.07.03 |
[Git 활용법] 터미널로 깃 클론 받기 (0) | 2024.07.02 |
[XCode] 단축키 모음😎 (1) | 2024.07.01 |