GYREdgeJustifiedLabel
EdgeJustifiedLabel is a UILabel subclass which allows two strings to be shown left and right justified on a single line, and equally scaled or truncated to fit the label bounds.
This capability is not possible using two separate UILabels and autolayout, as one will always scale before the other, nor is it possible via NSAttributedString, which does not allow left and right justified text to be displayed on a single line.
Additional options include minimum spacing between the strings, and truncation styles for each string once scaling options have been exhausted.
EdgeJustifiedLabel is also interoperable with Objective-C, and can be fully configured and previewed in Interface Builder.
Example
To run this example project for yourself, clone the repo, and run pod install
from the Example directory first.
Usage
var label = EdgeJustifiedLabel()
label.leftText = "Left justified text"
label.rightText = "Right justified text"
label.minimumSpacing = 40
label.truncationStyle = .rightTail
Requirements
Compatible with Swift 3.2, 4.0, 4.2, and 5.0. When installing with cocoapods, iOS 8 or later is required, though the source file itself will compile for iOS 7.
Installation
GYREdgeJustifiedLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'GYREdgeJustifiedLabel'
Author
Tom Jendrzejek ([email protected])
License
GYREdgeJustifiedLabel is available under the MIT license. See the LICENSE file for more info.