@IBOutlet var btnNext: UIButton!
self.btnNext.backgroundColor = hexStringToUIColor(hex:"#1994fc")
func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.characters.count) != 6) {
return UIColor.gray
}
var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
'iOS Swift' 카테고리의 다른 글
swift3 add touch event to uitextfield editingDidBegin/editingDidEnd (0) | 2017.01.02 |
---|---|
swift3 save image to UserDefaults (0) | 2017.01.02 |
resign keyboard textfield (0) | 2016.12.31 |
Swift3 UITextField border bottom (0) | 2016.12.31 |
swift3 textFieldDidChange 텍스트필드 이벤트 감지 (0) | 2016.12.13 |