CommonLib.swift
iOS/XCode Swift//
// CommonLib.swift
// TodoBox
//
// Created by GANG WOOK KIM on 16/05/2018.
// Copyright © 2018 GANG WOOK KIM. All rights reserved.
//
import Foundation
import UIKit
public class CommonLib
{
init()
{
}
class public func UIColorFromRGB(_ rgbValue: UInt) -> UIColor
{
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)
)
}
class public func UIColorFromRGB(_ rgbValue:String) -> UIColor
{
var cString:String = rgbValue.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#"))
{
cString.remove(at: cString.startIndex)
}
if ((cString.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 > XCode Swift' 카테고리의 다른 글
Status Bar 숨기기 (Carrier/ Wifi/ BatteryIcon Bar) (0) | 2018.05.18 |
---|---|
Constraint 동적 추가 (0) | 2018.05.17 |
Class 정의 (0) | 2018.05.16 |
애플 Swift Standard Library (0) | 2018.05.16 |
Swift.org (0) | 2018.05.16 |