Latest 0.1.0
Homepage https://github.com/hlfcoding/UITextExtensions
License MIT
Platforms ios 10.3
Frameworks UIKit
Authors

TextExtensions

Version
License
Platform
Code Climate

:label:   UIKit convenience extensions for text styling in code.

Example

let label = UILabel()
label.font = .preferredFont(forTextStyle: .title1)
label.numberOfLines = 0
label.textAlignment = .center
label.textColor = .darkText
label.hlf_updateText("Hello, playground. You are looking okay.")

label.hlf_setKerning(-0.5)
label.hlf_setLineHeight(label.hlf_pointsByEms(1.1))
// ...
label.hlf_updateText("Hello, playground. You are looking good.")

let width = label.hlf_pointsByEms(9)
label.frame.size.width = width
label.sizeToFit()
// ...

Compare the above with the (less flexible) below:

let label = UILabel()
label.numberOfLines = 0

var attributes = [String : Any]()
let font = UIFont.preferredFont(forTextStyle: .title1)
attributes[NSFontAttributeName] = font
attributes[NSForegroundColorAttributeName] = UIColor.darkText
attributes[NSKernAttributeName] = -0.5
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.center
paragraphStyle.maximumLineHeight = round(1.1 * font.pointSize)
attributes[NSParagraphStyleAttributeName] = paragraphStyle
label.attributedText = NSAttributedString(
  string: "Hello, playground. You are looking okay.", attributes: attributes
)
// ...
label.attributedText = NSAttributedString(
  string: "Hello, playground. You are looking good.", attributes: attributes
)

let width = round(9 * font.pointSize)
label.frame.size.width = width
label.sizeToFit()
// ...

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

Requirements

Swift 3+

Installation

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

pod "HLFUITextExtensions"

Author

Peng Wang, [email protected]

License

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

Latest podspec

{
    "name": "HLFUITextExtensions",
    "version": "0.1.0",
    "summary": "UIKit convenience extensions for text styling.",
    "description": "Supports UILabel, UITextField, and UITextView.",
    "homepage": "https://github.com/hlfcoding/UITextExtensions",
    "screenshots": "https://user-images.githubusercontent.com/100884/27258670-9f75ec7a-53b5-11e7-8866-b8dff74393ff.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Peng Wang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hlfcoding/UITextExtensions.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/hlfcoding",
    "platforms": {
        "ios": "10.3"
    },
    "source_files": "HLFUITextExtensions/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This