ZenCopy 1.3.6

ZenCopy 1.3.6

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年7月
SPM支持 SPM

JP McGlone 维护。



ZenCopy 1.3.6

ZenCopy

ZenCopy 是您需要的最后一个复制(文本)管理器。使用 ZenCopy,您可以

  • 轻松地对 NSAttributedStrings 进行样式设置(1 行!)
  • 使用正则表达式搜索,然后轻松地将样式添加到 NSAttributedString(1 行!)
  • 本地化 NSAttributedStrings
  • 将所有字符串存储在一个地方

安装

ZenCopy 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod "ZenCopy"

使用

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

复制

配置复制

请注意,复制可以包含参数。只需使用 $0、$1 等来设置您的参数。文本中的顺序无关紧要。

// english chat copy. prefix is for establishing context (optional)
ZenCopy.manager.config.addCopy("en", prefix: "chat") {
  return [
    "dance": ["@$0 dances with themself"], // note: this is chat.dance
  ]
}

// spanish chat copy
ZenCopy.manager.config.addCopy("sp", prefix: "chat") {
  return [
    "dance": ["@$0 baila con sí mismos"], // note: this is chat.dance
  ]
}

使用复制

NSAttributedString

myLabel.attributedText = ZenCopy.manager.attributedString(key: "global.fun", args: [sender, other])

样式

配置样式

ZenCopy.manager.config.setStyles {
    return [
        "action": Style(
            color: .lightGrayColor()
        ),
        "token": Style(
            color: .blueColor(),
            fontSize: 14
        ),
        "hulk": Style (
            color: .greenColor(),
            fontSize: 40
        )
    ]
}

使用正则表达式设置 NSAttributedString 的样式

let atUserRegex = "(@[A-Za-z0-9_]*)"
mutableAttributedString.regexFind(atUserRegex, addStyle: "token")

复制中的样式

在这个示例中,chat.poke 具有参数 $0 和 $1,它们的样式设置为“令牌”

ZenCopy.manager.config.addCopy("en", prefix: "chat") {
  return [
    ...
    "poke": ["@$0 ".style("token"), "pokes ", "@$1".style("token")] // note: this is chat.poke
  ]
}

附加说明

我建议在项目中的 Copy.swift(您可以取任何名称)文件中存储所有字符串。我还建议使用复制的“前缀”来根据上下文区分键(例如,“全局”、“配置文件”、“聊天”等)

如果你们有任何疑问!请提交反馈、问题和拉取请求 :D

即将到来

  • 可以选择从设备位置自动设置ZenCopy本地化。目前这是手工设置。
  • 帮助您工作和迁移NSLocalizedStrings的脚本
  • 与其他有用的NSAttributedString库干净集成

作者

JP McGlone,[email protected]

许可

ZenCopy可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。