LabelTextFormatter 1.0.0

LabelTextFormatter 1.0.0

Bohdan 维护。



  • IDAP 团队

LabelTextFormatter

UILabel 和 NSAttributedString 扩展,允许您简单地将文本设置到标签中。

您可以直接从 String 设置文本

self.someLabel.setText(text: "some text", font: .systemFont(ofSize: 15), color: .black)

或者从 NSAttributedString

self.someLabel.setTextFrom(value: someAttributedString, font: .systemFont(ofSize: 15), color: .black)

您也可以将多个 AttributedString 合并成一个

self.someLabel.setTextFrom(values: [firstPartAttributedString, secondPartAttributedString])

您还可以从具有特定参数的字符串设置标签的文本

self.someLabel.setAttributedText(
    "some text",
    font: .systemFont(ofSize: 15),
    color: .black,
    lineSpacing: 8,
    leterSpacing: 4,
    minimumLineHeight: 8,
    lineHeightMultiple: 4,
    underlied: false,
    alignment: .center
)

或者可以创建具有特定参数的 AttributedString 实例

let someAttributedString = NSAttributedString.create(
    from: "some text",
    font: .systemFont(ofSize: 15),
    color: .black,
    lineSpacing: 8,
    leterSpacing: 4,
    minimumLineHeight: 8,
    lineHeightMultiple: 4,
    underlied: false,
    alignment: .center
)

要求

iOS 9+。Swift 3.0。

安装

通过 CocoaPods 可以使用 LabelTextFormatter。要安装它,请简单地将以下行添加到您的 Podfile 中:

pod "LabelTextFormatter"

通过 Carthage 可以使用 LabelTextFormatter。要安装它,请简单地将以下行添加到您的 Cartfile 中:

github "idapgroup/LabelTextFormatter"

许可协议

LabelTextFormatter 使用新 BSD 许可协议。有关更多信息,请参阅 LICENSE 文件。