Monet 2.0.0

Monet 2.0.0

Benoit BRIATTE 维护。



Monet 2.0.0

  • Digipolitan

Monet

Swift Version Build Status CocoaPods Compatible Carthage Compatible Platform Twitter

主题管理器,简化应用程序外观。

安装

CocoaPods

要使用 CocoaPods 安装 Monet,请将以下行添加到您的 Podfile 中。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'Monet'

Carthage

Carthage 是一个去中心化的依赖管理器,它构建您的依赖项并提供二进制框架。

您可以使用以下命令通过 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要将 Monet 集成到您的 Xcode 项目中,使用 Carthage,请在其 Cartfile 中指定

github 'Digipolitan/monet' ~> 2.0

运行 carthage update 以构建框架,并将构建好的 Monet.framework 拖到您的 Xcode 项目中。

基础

您需要在 json创建 您的主题模板。
在这个例子中,我们创建 default.json,它对应于应用程序的默认模板。

{
    "identifier": "com.digipolitan.theme.default",
    "@colors": {
        "primary": "#FF877F"
    },
    "@fonts": {
        "regular-body": {
            "name": "Optima-Regular",
            "size": 48
        },
        "bold-action": {
            "name": "Optima-Bold",
            "size": 15
        }
    },
    "appearances": {
        "views": {
            "scene" : {
                "backgroundColor": "#123456"
            }
        },
        "texts": {
            "body": {
                "backgroundColor": "@colors/primary",
                "foregroundColor": "#323233",
                "font": "@fonts/regular-body"
            },
            "action": {
                "backgroundColor": "@colors/primary",
                "foregroundColor": "#FFFFFF",
                "font": "@fonts/bold-action"
            }
        }
    }
}

然后您可以设置默认主题如下

Monet.shared.theme = try? Theme.from(jsonFile: "default")

然后您只需按照以下方式设置您应用程序的所有外观

self.label.setAppearance(theme.appearances.texts["body"])
self.view.setAppearance(theme.appearances.views["scene"])

现在,使用InterfaceBuilder,您可以为每个UIView子类设置外观,使用动态键appearanceIdentifier

贡献力量

有关更多详细信息,请参阅CONTRIBUTING.md

本项目遵循贡献者公约行为准则。通过参与,您应遵守此准则。如遇到不可接受的行为,请联系[email protected]

许可证

Monet遵循BSD 3项许可证