Giter Club home page Giter Club logo

attributedlabel's Introduction

AttributedLabel

Build Status Carthage compatible Version License Platform

Graph

Higher performance than UILabel.

Label

Overview

This is a better performance than UILabel and can be used like a standard UI component. Also, Easier to use than UILabel.

Since UIView is inherited instead of UILabel, there is little wasteful processing. It uses the function of TextKit to draw characters.

However, please note that content layout is not done automatically. If want to automatically fix the height of the content, set usesIntrinsicContentSize to true.

Even if set it to true, the width of the content depends on the content frame. Even if specify an ambiguous width in Interface Builder, the width does not automatically fit.

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

Requirements

  • Swift 4.0
  • iOS 7.0 or later
  • tvOS 9.0 or later

How to Install AttributedLabel

iOS 8+, tvOS

CocoaPods

Add the following to your Podfile:

pod "AttributedLabel"

Carthage

Add the following to your Cartfile:

github "KyoheiG3/AttributedLabel"

iOS 7

Just add everything in the AttributedLabel.swift file to your project.

Usage

Variable

var numberOfLines: Int
  • Same as numberOfLines of UILabel.
  • Default is 0.
var contentAlignment: AttributedLabel.ContentAlignment
  • Alignment of content.
  • Default is left.
@IBInspectable var padding: CGFloat
  • lineFragmentPadding of NSTextContainer.
  • default is 0.
var font: UIFont
  • Text font.
  • Default is system font 17 plain.
var lineBreakMode: NSLineBreakMode
  • Same as lineBreakMode of UILabel.
  • Default is ByTruncatingTail.
@IBInspectable 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.
@IBInspectable var text: String?
  • Default is nil.
var usesIntrinsicContentSize: Bool
  • If need to use intrinsicContentSize set true.
  • Must specify width of Label yourself because this change only height automatically.
  • Should call invalidateIntrinsicContentSize when intrinsicContentSize is cached. When text was changed for example.
  • Default is false.

Function

override func sizeThatFits(size: CGSize) -> CGSize
  • Same as sizeThatFits of UILabel.
override func sizeToFit()
  • Fit like UILabel.
  • The width of the content depends on the content frame.

Author

Kyohei Ito

Follow me ๐ŸŽ‰

LICENSE

Under the MIT license. See LICENSE file for details.

attributedlabel's People

Contributors

kyoheig3 avatar jstart avatar mariotaku avatar readmecritic avatar hryk224 avatar

Watchers

James Cloos avatar Daniel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.