ODMultiColumnLabel is a UILabel replacement that renders text on multiple columns, without any major hassle, available in both Objective-C and Swift
Since it’s based on TextKit, ODMultiColumnLabel requires iOS 7.0 or greater
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
andODMultiColumnLabel.m
from theODMultiColumnLabel
folder into your project #import "ODMultiColumnLabel.h"
- Drag
ODMultiColumnLabel.swift
from theODMultiColumnLabel
folder into your project
(see sample Xcode project in /Demo
)
Create the label as normal, via code or Interface Builder
The ODMultiColumnLabel
can be customized using all normal UILabel properties, using normal or attributed strings, plus the following properties:
@property (nonatomic, assign) NSUInteger numberOfColumns; // default is 1 @property (nonatomic, assign) CGFloat columnsSpacing; // default is 14.0
var numberOfColumns: UInt = 2 var columnsSpacing: CGFloat = 14.0
- 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
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.