Last active
August 7, 2017 22:50
-
-
Save MTattin/da88677e9d5785a116494c1e5091e86e to your computer and use it in GitHub Desktop.
iOS11のColor Setを使いたいので、UIColorにextensionを追加してみた ref: http://qiita.com/MTattin/items/c4031fb6c2799baf005c
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
extension UIColor { | |
/// | |
/// UIColor.init(named: String)がiOS11以降からしか使えないのでiOS10用処理 | |
/// | |
static func Init(named: String) -> UIColor { | |
if #available(iOS 11.0, *) { | |
guard let _0_c: UIColor = UIColor.init(named: named) else { | |
return UIColor.clear | |
} | |
return _0_c | |
} else { | |
switch named { | |
case "Accent": return #colorLiteral(red: 0.3490196078, green: 0.2431372549, blue: 0.9764705882, alpha: 1) | |
case "Base": return #colorLiteral(red: 0.01176470588, green: 0.662745098, blue: 0.9568627451, alpha: 1) | |
case "BaseD1": return #colorLiteral(red: 0.003921568627, green: 0.3411764706, blue: 0.6078431373, alpha: 1) | |
case "BaseD1A080": return #colorLiteral(red: 0.003921568627, green: 0.3411764706, blue: 0.6078431373, alpha: 0.8) | |
case "BaseD2": return #colorLiteral(red: 0.007843137719, green: 0.5333333611, blue: 0.8196078539, alpha: 1) | |
case "BaseL1": return #colorLiteral(red: 0.8823529412, green: 0.9607843137, blue: 0.9960784314, alpha: 1) | |
case "BaseL2": return #colorLiteral(red: 0.5058823529, green: 0.831372549, blue: 0.9803921569, alpha: 1) | |
case "Overlay": return #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.5) | |
case "FontD1": return #colorLiteral(red: 0.2588235294, green: 0.2588235294, blue: 0.2588235294, alpha: 1) | |
case "FontD2": return #colorLiteral(red: 0.4588235319, green: 0.4588235319, blue: 0.4588235319, alpha: 1) | |
case "FontL1": return #colorLiteral(red: 0.9333333373, green: 0.9333333373, blue: 0.9333333373, alpha: 1) | |
case "FontL2": return #colorLiteral(red: 0.741176486, green: 0.741176486, blue: 0.741176486, alpha: 1) | |
default: return UIColor.clear | |
} | |
} | |
} | |
} |
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
UIColor.Init(named: "FontD1") |
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
UIColor.Init(named: | |
UIColor.init(named: |
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
/// | |
// MARK: ------------------------------ extension UIStoryboard | |
/// | |
/// extension UIStoryboard | |
/// | |
extension UIStoryboard { | |
/// | |
// MARK: ------------------------------ static method | |
/// | |
/// UIColor.init(named: String)がiOS11以降からしか使えないのでiOS10用処理 | |
/// | |
static func IOS10(name: String, bundle: Bundle?) -> UIStoryboard { | |
if #available(iOS 11.0, *) { | |
return UIStoryboard(name: name, bundle: bundle) | |
} else { | |
return UIStoryboard(name: "\(name)iOS10", bundle: bundle) | |
} | |
} | |
} |
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
let sb: UIStoryboard = UIStoryboard.IOS10(name: "StoryboardName", bundle: nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment