Sephiroth87 / ODMultiColumnLabel

A UILabel replacement that renders text on multiple columns, comes in both Objective-C and Swift versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ODMultiColumnLabel

ODMultiColumnLabel is a UILabel replacement that renders text on multiple columns, without any major hassle, available in both Objective-C and Swift

Requirements

Since it’s based on TextKit, ODMultiColumnLabel requires iOS 7.0 or greater

Installation

Objective-C

Important note if your project doesn’t use ARC: you must add the -fobjc-arc compiler flag to ODMultiColumnLabel.m in Target Settings > Build Phases > Compile Sources.

  • Drag ODMultiColumnLabel.h and ODMultiColumnLabel.m from the ODMultiColumnLabel folder into your project
  • #import "ODMultiColumnLabel.h"

Swift

  • Drag ODMultiColumnLabel.swift from the ODMultiColumnLabel folder into your project

Usage

(see sample Xcode project in /Demo)

Create the label as normal, via code or Interface Builder

Customization

The ODMultiColumnLabel can be customized using all normal UILabel properties, using normal or attributed strings, plus the following properties:

Objective-C

@property (nonatomic, assign) NSUInteger numberOfColumns;   // default is 1
@property (nonatomic, assign) CGFloat columnsSpacing;       // default is 14.0

Swift

var numberOfColumns: UInt = 2
var columnsSpacing: CGFloat = 14.0

Known limitations

  • Currently, ODMultiColumnLabel works best if the label has no fixed height, either using Autolayout’s intrinsic content size or -sizeToFit. Forcing a smaller height to the label will currently crop the bottom part
  • lineBreakMode is currently ignored, partially for the reason above, but also because there seems to be a bug with NSLayoutManager

Credits

ODMultiColumnLabel is brought to you by Fabio Ritrovato and contributors to the project. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you’re using ODMultiColumnLabel in your project, attribution would be nice.

About

A UILabel replacement that renders text on multiple columns, comes in both Objective-C and Swift versions

License:MIT License


Languages

Language:Objective-C 53.4%Language:Swift 42.5%Language:Ruby 4.1%