TweaKit

TweaKit,也称为 "Tweak It",是一个纯 Swift 库,用于调整参数和功能标记。

特性

要求

安装

CocoaPods

pod 'TweaKit', '~> 1.0'

Carthage

github "Alpensegler/TweaKit" ~> 1.0

Swift Package Manager

.package(url: "https://github.com/Alpensegler/TweaKit.git", .upToNextMajor(from: "1.0.0"))

开始使用

声明调整项

import TweaKit

enum Tweaks {
    @Tweak<CGFloat>(name: "Line Width", defaultValue: 1, from: 0.5, to: 2, stride: 0.05)
    static var sketchLineWidth
    @Tweak(name: "Line Color", defaultValue: UIColor(red: 0.227, green: 0.529, blue: 0.992, alpha: 1))
    static var sketchLineColor
    @Tweak(name: "Order", defaultValue: SketchAction.allCases)
    static var sketchActionsOrder
    @Tweak(name: "Name", defaultValue: "My Sketch")
    static var sketchName
    
    @Tweak(name: "Navigation Title", defaultValue: "Demo", options: ["Demo", "Example", "Guide"])
    static var rootViewNavigationTitle
    @Tweak(name: "Shake To Show Tweaks", defaultValue: true)
    static var rootViewEnableShake
    
    static let context = TweakContext {
        TweakList("Sketch") {
            TweakSection("Line") {
                $sketchLineWidth
                $sketchLineColor
            }
            TweakSection("Info") {
                $sketchName
            }
            TweakSection("Actions") {
                $sketchActionsOrder
            }
        }
        TweakList("Root View") {
            TweakSection("UI") {
                $rootViewNavigationTitle
            }
            TweakSection("Interaction") {
                $rootViewEnableShake
            }
        }
    }
}

您可以调整以下类型

除了直接更改值之外,您还可以从给定的选项中选择值。

初始化 Tweak 上下文

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    _ = Tweaks.context
    return true
}

您可以随时初始化调整上下文,但应确保在使用调整项之前初始化上下文。

使用调整项

myViewController.title = Tweaks.rootViewNavigationTitle
mySketchView.lineWidth = Tweaks.sketchLineWidth

显示 Tweak UI

Tweaks.context.show()

Screenshot1 Screenshot2 Screenshot3 Screenshot4

Screenshot5 Screenshot6 Screenshot7 Screenshot8

就是这样。现在您已经对 TweaKit 有了足够的了解。

请随意试用演示应用程序或查看 wikidocumentation 以获取更多使用信息。

鸣谢

关于 Logo

TweaKit 的 Logo 是一只可爱的小鼬,一种可以在夏季和冬季调整皮毛颜色的鼬科动物。