Latest 0.2.1
Homepage https://github.com/zelic91/ZText
License MIT
Platforms ios 8.0
Authors

[![CI Status](http://img.shields.io/travis/Thuong Nguyen/ZText.svg?style=flat)](https://travis-ci.org/Thuong Nguyen/ZText)
Version
License
Platform

alt text

Overview

If you ever used NSAttributedString for special font and color formatting for text, you can feel the pain of the lengthy code. Moreover, the attributes are really hard to remember, especially when you rarely use them. To eliminate the above headache, ZText provides an easy way to use NSAttributedString with simple syntax that you almost don’t need to remember anything.

Usage

Just import ZText and you are good to go. Simply begin the text with begin(), then add some more texts, and finally call end() to return a NSAttributedString.

For instance:

        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()

There are couples of attributes that you might want to customize:

    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 

Full list of methods that you can call:

    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

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

ZText is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "ZText"

Author

Thuong Nguyen, [email protected]

License

ZText is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ZText",
    "version": "0.2.1",
    "summary": "A cooler way to use NSAttributedString.",
    "description": "Tired of using NSAttributedString the old way? ZText provides you with a simple way to apply NSAttributedString to your app",
    "homepage": "https://github.com/zelic91/ZText",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Thuong Nguyen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/zelic91/ZText.git",
        "tag": "0.2.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ZText/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This