ZText 0.2.1

ZText 0.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布2016年12月
Swift版本Swift版本3.0
SPM支持SPM

Thuong Nguyen 维护。



ZText 0.2.1

  • Thuong Nguyen

ZText

alt text

概述

如果您曾经使用过 NSAttributedString 来进行特定的字体和颜色格式化文本,那么您一定会感受到漫长代码的痛苦。此外,属性难以记忆,尤其是当您很少使用它们时。为了解决上述难题,ZText 提供了一种方便的方式来使用 NSAttributedString,语法简单,几乎不需要记住任何内容。

用法

只需import ZText,开始使用。简单地以begin()开始文本,然后添加更多的文本,最后调用end()来返回一个 NSAttributedString。

例如

        ZText.boldFont         = UIFont(name: "GillSans-Bold", size: 42)!
        ZText.italicFont       = UIFont(name: "GillSans-Italic", size: 18)!
        ZText.defaultAlignment = NSTextAlignment.Center

        lbTitle.attributedText = ZText.begin()
            .addBoldText("Z", color: UIColor.whiteColor())
            .addBoldText("Text", color: UIColor.yellowColor())
            .end()

        lbDescription.attributedText = ZText.begin()
            .addItalicText("'Cause ", color: UIColor.yellowColor())
            .addItalicText("NSAttributedString ", color: UIColor.whiteColor())
            .addItalicText("is ", color: UIColor.yellowColor())
            .addItalicText("damn ", color: UIColor.whiteColor())
            .addItalicText("sexy ", color: UIColor.yellowColor())
            .end()

有几个属性您可能想要自定义

    public static var generalFont:              UIFont  
    public static var boldFont:                 UIFont  
    public static var italicFont:               UIFont  
    public static var generalColor:             UIColor 
    public static var boldTextColor:            UIColor 
    public static var italicTextColor:          UIColor 
    public static var backgroundColor:          UIColor 
    public static var boldBackgroundColor:      UIColor 
    public static var italicBackgroundColor:    UIColor 
    public static var defaultUnderlineStyle:    NSUnderlineStyle 
    public static var defaultUnderlineColor:    UIColor 
    public static var defaultAlignment:         NSTextAlignment 

您可以调用的方法的全列表

    public class func begin() -> ZText.ZText
    public func addText(text: String, color: UIColor?, background: UIColor?, font: UIFont?, underlineStyle: NSUnderlineStyle, underlineColor: UIColor?) -> ZText.ZText
    public func addText(text: String, color: UIColor?, background: UIColor?, font: UIFont?) -> ZText.ZText
    public func addText(text: String, color: UIColor?, font: UIFont?) -> ZText.ZText
    public func addText(text: String, font: UIFont?) -> ZText.ZText
    public func addText(text: String, color: UIColor?) -> ZText.ZText
    public func addText(text: String) -> ZText.ZText
    public func addText(text: String, underlineStyle: NSUnderlineStyle, underlineColor: UIColor?) -> ZText.ZText
    public func addText(text: String, underlineStyle: NSUnderlineStyle) -> ZText.ZText
    public func addBoldText(text: String, underlineStyle: NSUnderlineStyle, underlineColor: UIColor?) -> ZText.ZText
    public func addBoldText(text: String) -> ZText.ZText
    public func addBoldText(text: String, color: UIColor) -> ZText.ZText
    public func addBoldText(text: String, underlineStyle: NSUnderlineStyle) -> ZText.ZText
    public func addItalicText(text: String, underlineStyle: NSUnderlineStyle, underlineColor: UIColor?) -> ZText.ZText
    public func addItalicText(text: String, underlineStyle: NSUnderlineStyle) -> ZText.ZText
    public func addItalicText(text: String, color: UIColor) -> ZText.ZText
    public func addItalicText(text: String) -> ZText.ZText
    public func end() -> NSMutableAttributedString

示例

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

安装

通过CocoaPods可获取 ZText。要安装它,只需将以下行添加到您的Podfile中即可:

pod "ZText"

作者

Thuong Nguyen,[email protected]

许可证

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