Nantes
  • November 24, 2023

This library is a Swift port/fork of the popular Objective-C library TTTAttributedLabel. Much ❤️ and credit goes to Mattt for creating such a great UILabel replacement library.

Nantes is a pure-Swift UILabel replacement. It supports attributes, data detectors, and more. It also supports link embedding automatically and with NSTextCheckingTypes.

Come build awesome things with us here at Instacart!

Requirements

  • iOS 8.0+
  • Swift 4.2

Installation

Nantes is available through Carthage. To install it, add the following line to your Cartfile:

github “instacart/nantes”

CocoaPods

Nantes is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod ‘Nantes’

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Getting Started

Check out Nantes in the Example directory for more examples.

import Nantes

let label: NantesLabel = .init(frame: .zero)
label.attributedTruncationToken = NSAttributedString(string: “… more”)
label.numberOfLines = 3
label.labelTappedBlock = {
label.numberOfLines = label.numberOfLines == 0 ? 3 : 0 // Flip between limiting lines and not

UIView.animateWithDuration(0.2, animations: {
self.view.layoutIfNeeded()
})
}

label.text = “Nantes label is great! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ac urna et ante lobortis varius. Nunc rhoncus enim vitae sem commodo sodales. Morbi id augue id augue finibus tincidunt. Cras ac massa nisi. Maecenas elementum vitae elit eu mattis. Duis pretium turpis ut justo accumsan molestie. Mauris elit elit, maximus eu risus sed, vestibulum sodales enim. Sed porttitor vestibulum tincidunt. Maecenas mollis tortor quam, sed porta justo rhoncus id. Phasellus vitae augue tempor, luctus metus sit amet, dictum urna. Morbi sit amet feugiat purus. Proin vitae finibus lectus, eu gravida erat.”
view.addSubview(label)

let linkLabel: NantesLabel = .init(frame: .zero)
linkLabel.delegate = self // NantesLabelDelegate
linkLabel.linkAttributes = [NSAttributedString.Key.foregroundColor: UIColor.green]
linkLabel.text = “https://www.instacart.com”
view.addSubview(linkLabel)

// Link handling

func attributedLabel(_ label: NantesLabel, didSelectLink link: URL) {
print(“Tapped link: \(link)”)
}

 

GitHub


View Github

#attributedlabel #ios #swift #swiftframwork
YOU MIGHT ALSO LIKE...
CameraBackground

Features Both front and back camera supported. Flash modes: auto, on, off. Countdown timer. Tap to focus. Pinch to zoom. Usage  

DKCamera

Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so ...

HorizonSDK-iOS

Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...

LLSimpleCamera

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video ...

RSBarcodes_Swift

RSBarcodes allows you to read 1D and 2D barcodes using the metadata scanning capabilities introduced with iOS 7 and generate ...