CostumeKit 🎩
  • March 11, 2024

Base types for theming an app.

CostumeKit is made of up a set of Swift protocols. They are meant to be implemented by you in your app.

Featured in Little Bites of Cocoa Bite #270: Implementing Theming with CostumeKit

Color 🎨


Includes Color and ColorPalette protocols.

Usage:

public enum MyAppColors : Color, ColorPalette {
case white = “FFFFFF”
case lightTeal = “3CB39E”
case forestGreen = “216055”
case black = “000000”
}

Font 🔠


Includes Font protocol, and one concrete SystemFont implementation for iOS system fonts.

Usage:

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 🌠


Includes SVG Protocol and SVGMetadata type.

Usage:

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)
}
}
}

What you do with SVGMetadata is up to you. I recommend SwiftSVG from Michael ChoeRead more here to learn how to use it.

CostumeKit‘s goals are to be a generic solution, so no assumptions are made about how something should be retrieved from disk, parsed, etc. You’ll need to implement these anyways, so nothing is forced on you.

Costume 🎩


Includes Costume protocol. Usage:

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() { }
}

GitHub


View Github

#carthage #colors #fonts #images #ios #ios-lib #protocol #svg #swift #themes
YOU MIGHT ALSO LIKE...
exyte

     

camerakit-ios

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service ...

HybridCamera

[video width="192" height="416" mp4="https://swiftgit.com/wp-content/uploads/2024/12/68747470733a2f2f7261776769742e636f6d2f7374796c656b69742f696d672f6d61737465722f7669645f6564697465645f325f326d622e676966.mp4"][/video]

TakeASelfie

An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front ...

iOS-Depth-Sampler

Code examples of Depth APIs in iOS