iOS 标签:AttributedLabel

ynnc 9年前

AttributedLabel 比 UILabel 更容易使用,更快,性能更好。

Graph

Graph

Label

Customization is easy.

Customize

Left tab is customizable label. The center tab AttributedLabel So fast. Right tab is UILabel So slow. Fast more than 10 times from 5 times.

  • use the UIlabel

UILabel

  • use the AttributedLabel

AttributedLabel

How to Install AttributedLabel

iOS 8+

Cocoapods

Add the following to yourPodfile:

pod "AttributedLabel" use_frameworks!

Note: theuse_frameworks!is required for pods made in Swift.

Carthage

Add the following to yourCartfile:

github "KyoheiG3/AttributedLabel"

iOS 7

Just add everything in theAttributedLabel.swiftfile to your project.

Usage

import

If target is ios8.0 or later, please import theAttributedLabel.

import AttributedLabel

Variable

var numberOfLines: Int
  • Same asnumberOfLinesofUILabel.
  • Default is0.
var contentAlignment: AttributedLabel.ContentAlignment
  • Alignment of content.
  • Default isLeft.
var font: UIFont
  • Text font.
  • Default is system font 17 plain.
var lineBreakMode: NSLineBreakMode
  • Same aslineBreakModeofUILabel.
  • Default isByTruncatingTail.
var textColor: UIColor?
  • Default is nil (text draws black).
var paragraphStyle: NSParagraphStyle?
  • Default is nil.
var shadow: NSShadow?
  • Default is nil.
var attributedText: NSAttributedString?
  • Default is nil.
var text: String?
  • Default is nil.

Function

override func sizeThatFits(size: CGSize) -> CGSize
  • Same assizeThatFitsofUILabel.
override func sizeToFit()
  • Same assizeToFitofUILabel.
  • Autolayout doesn't work withsizeToFit.

项目主页:http://www.open-open.com/lib/view/home/1438093819675