CostumeKit
1.0.0
主題應用程序的基本類型。
Costumekit由一組Swift協議組成。它們本來應該在您的應用程序中實現。
可可叮咬的小叮咬#270:用costumekit實施主題
包括Color和ColorPalette協議。
用法:
public enum MyAppColors : Color , ColorPalette {
case white = " FFFFFF "
case lightTeal = " 3CB39E "
case forestGreen = " 216055 "
case black = " 000000 "
} 包括Font協議和iOS系統字體的一個混凝土SystemFont實現。
用法:
public struct MyAppFont : Font {
public init ( size : FontSize = . textStyle ( . body ) ) {
self . size = size
}
// Font
public var size : FontSize
// FontConvertible
public var FontValue : UIFont {
return UIFont ( name : " SomeCustomFont " , size : pointSize ) !
}
} 包括SVG協議和SVGMetadata類型。
用法:
enum MyAppSVGs {
case clockGlyph
case bird
}
extension MyAppSVGs : SVG {
public func metadata ( ) -> SVGMetadata {
switch self {
case . clockGlyph : return SVGMetadata ( name : " clock " , size : CGSize ( width : 100 , height : 100 ) , fullColor : false )
case . bird : return SVGMetadata ( name : " bird " , size : CGSize ( width : 58 , height : 28 ) , fullColor : true )
}
}
}您對SVGMetadata的作用取決於您。我推薦Michael Choe的Swiftsvg。在此處閱讀更多信息,以了解如何使用它。
Costumekit的目標是成為一個通用的解決方案,因此沒有假設應該從磁盤,解析等方面檢索某些東西。
包括Costume方案。用法:
open class MyAppCostume : Costume {
let spacing = CGFloat ( 8 )
public func wearRootBackground ( _ view : UIView ) {
view . backgroundColor = Color . black . colorValue
}
public func wearHeadline ( _ label : UILabel ) {
label . font = MyAppFont ( size : . textStyle ( . title1 ) ) . fontValue
label . textColor = MyAppColors . forestGreen . colorValue
}
public var name : String { return " Default " }
public var description : String { return " The default costume. " }
public init ( ) { }
}乾杯。