Basistypen für das Thema einer App.
Costumekit besteht aus einer Reihe von Swift -Protokollen. Sie sollen von Ihnen in Ihrer App implementiert werden.
In Little Bissen Kakao -Biss #270: Implementierung von Themen mit Costumekit
Enthält Color und ColorPalette -Protokolle.
Verwendung:
public enum MyAppColors : Color , ColorPalette {
case white = " FFFFFF "
case lightTeal = " 3CB39E "
case forestGreen = " 216055 "
case black = " 000000 "
} Beinhaltet Font und eine konkrete SystemFont -Implementierung für iOS -Systemschriften.
Verwendung:
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 ) !
}
} Beinhaltet SVG -Protokoll und SVGMetadata -Typ.
Verwendung:
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 )
}
}
} Was Sie mit SVGMetadata machen, liegt bei Ihnen. Ich empfehle SwiftSVG von Michael Choe. Lesen Sie hier mehr, um zu lernen, wie man es benutzt.
Costumekits Ziele sind es, eine generische Lösung zu sein, sodass keine Annahmen darüber getroffen werden, wie etwas von der Festplatte, analysiert usw. abgerufen werden sollte. Sie müssen diese sowieso implementieren, sodass Sie Ihnen nichts erzwingen müssen.
Beinhaltet Costume . Verwendung:
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 ( ) { }
}Prost.