MTLLinkLabel is linkable UILabel. Written in Swift.

Related tags

Label MTLLinkLabel
Overview

#MTLLinkLabel

Badge w/ Version Carthage compatible MIT License

MTLLinkLabel is linkable UILabel. Written in Swift.

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

Carthage

You can install Carthage with Homebrew.

$ brew update
$ brew install carthage

specify it in your Cartfile

github "recruit-mtl/MTLLinkLabel"

And run carthage

$ carthage update --platform ios

CocoaPods

$ pod init

specify it in your Podfile

platform :ios, '8.0'

target 'MTLLinkLabelExample' do

  use_frameworks!

  pod 'MTLLinkLabel', '~> 0.1.6'

end

And run CocoaPods

$ pod install

Usage

You can use MTLLinkLabel in Storyboard or XIB.

#####Drag and drop UILabel in your view.

#####Change UILabels custom class to 'LinkLabel', and Change module to 'MTLLinkLabel'.

You must change labels userInteractionEnabled property to true. Because, this labels properties default value is false.

label.userInteractionEnabled = true

#####Assign String to LinkLabels 'text' property.

label.text = "Hello. https://github.com/recruit-mtl/MTLLinkLabel"

Hello. https://github.com/recruit-mtl/MTLLinkLabel

--

Add custom link

You can add custom link in LinkLabel with range and Action at the time of the link selection.

Void in let alert = UIAlertController(title: nil, message: url.absoluteString, preferredStyle: UIAlertControllerStyle.ActionSheet) alert.addAction(UIAlertAction(title: "Go", style: .Default, handler: { (action) -> Void in UIApplication.sharedApplication().openURL(url) })) alert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) }">
let range = (text as NSString).rangeOfString("1829")
        
cell.label.addLink(
	NSURL(string: "https://www.google.co.jp/#q=1829")!, 
	range: range, 
	linkAttribute: [
		NSForegroundColorAttributeName: UIColor.redColor(),
		NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue
	]
) { (url) -> Void in
	
	let alert = UIAlertController(title: nil, message: url.absoluteString, preferredStyle: UIAlertControllerStyle.ActionSheet)
	alert.addAction(UIAlertAction(title: "Go", style: .Default, handler: { (action) -> Void in
		UIApplication.sharedApplication().openURL(url)
	}))
	alert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: nil))
	self.presentViewController(alert, animated: true, completion: nil)
}

--

Delegate

LinkLabelDelegate methods are optional method.

The default implementation is implemented in protocol extension.

[String: AnyObject] { return [ NSForegroundColorAttributeName: linkLabel.tintColor, NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue ] } func linkDefaultAttributeForCustomeLink(linkLabel: LinkLabel) -> [String: AnyObject] { return [ NSForegroundColorAttributeName: linkLabel.tintColor, NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue ] } func linkLabelCheckingLinkType() -> NSTextCheckingTypes { return NSTextCheckingType.Link.rawValue | NSTextCheckingType.PhoneNumber.rawValue } }">
public extension LinkLabelDelegate {
    
    func linkLabelExecuteLink(linkLabel: LinkLabel, text: String, result: NSTextCheckingResult) -> Void {
        
        if result.resultType.contains(.Link) {
            
            let pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]+"
            if NSPredicate(format: "SELF MATCHES '\(pattern)'").evaluateWithObject(text) {
                UIApplication.sharedApplication().openURL(NSURL(string: "mailto:" + text)!)
                return
            }
            
            let httpText = !text.hasPrefix("http://") && !text.hasPrefix("https://") ? "http://" + text : text
            
            guard let url = NSURL(string: httpText) else { return }
            UIApplication.sharedApplication().openURL(url)
            
        }
        else if result.resultType.contains(.PhoneNumber) {
            let telURLString = "tel:" + text
            UIApplication.sharedApplication().openURL(NSURL(string: telURLString)!)
        }
    }
    
    func linkAttributeForLinkLabel(linkLabel: LinkLabel, checkingType: NSTextCheckingType) -> [String: AnyObject] {
        return [
            NSForegroundColorAttributeName: linkLabel.tintColor,
            NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue
        ]
    }
    
    func linkDefaultAttributeForCustomeLink(linkLabel: LinkLabel) -> [String: AnyObject] {
        return [
            NSForegroundColorAttributeName: linkLabel.tintColor,
            NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue
        ]
    }
    
    func linkLabelCheckingLinkType() -> NSTextCheckingTypes {
        return NSTextCheckingType.Link.rawValue
            | NSTextCheckingType.PhoneNumber.rawValue
    }
}

Licence

MIT

Author

You might also like...
UILabel replacement with fine-grain appear/disappear animation

ZCAnimatedLabel UILabel-like view with easy to extend appear/disappear animation Features Rich text support (with NSAttributedString) Group aniamtion

Adds animated counting support to UILabel.
Adds animated counting support to UILabel.

UICountingLabel Adds animated counting support to UILabel. CocoaPods UICountingLabel is available on CocoaPods. Add this to your Podfile: pod 'UICount

A simple designable subclass on UILabel with extra IBDesignable and Blinking features.
A simple designable subclass on UILabel with extra IBDesignable and Blinking features.

JSLabel Demo pod try JSLabel ...or clone this repo and build and run/test the JSLabel project in Xcode to see JSLabel in action. If you don't have Coc

Lightweight library to set an Image as text background. Written in swift.
Lightweight library to set an Image as text background. Written in swift.

Simple and light weight UIView that animate text with an image.

 A triangle shaped corner label view for iOS written in Swift.
A triangle shaped corner label view for iOS written in Swift.

A triangle shaped corner label view for iOS written in Swift. This view is a subclass of UIView. It can be created and customized from the Storyboard

Swift TTTAttributedLabel replacement

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

NSData Detector with swift

NSDataDetector This playground demonstrates a weird difference in behaviour between Xcodes 12.5.1 and 13.1 regarding NSDataDetector. Try to run it usi

Swift UIView for sliding text with page indicator
Swift UIView for sliding text with page indicator

SlidingText for Swift Requirements Requires iOS 8 or later and Xcode 6.1+ Installation SlidingText is available through CocoaPods. To install it, simp

An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind
An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind

Composable Navigator An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind Vanilla S

An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind
An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind

Composable Navigator An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind Vanilla S

A morphing UILabel subclass written in Swift.
A morphing UILabel subclass written in Swift.

LTMorphingLabel A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphi

High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton
Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton

Highlighter Updates See CHANGELOG for details Intoduction 🖍 Highlight whatever you want! Highlighter will magically find UI objects such as UILabel,

UILabel drop-in replacement supporting Hashtags
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Simple countdown UILabel with morphing animation, and some useful function.
Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel Simple countdown UILabel with morphing animation, and some useful function. features Simple creation Easily get status of countdown fro

 Glitching UILabel for iOS 📺
Glitching UILabel for iOS 📺

Glitching UILabel for iOS 📺 Created by Lee Sun-Hyoup. Try the sample $ pod try GlitchLabel Requirements iOS 8.0+ Swift 3 Xcode 8 Installation CocoaP

Incrementable UILabel for iOS and tvOS
Incrementable UILabel for iOS and tvOS

IncrementableLabel IncrementableLabel is the easiest way to have incrementable numbers in an UILabel! Usage let myIncrementableLabel = IncrementableLa

KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.
KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.

KDEDateLabel KDEDateLabel is an UILabel subclass that saves you from refreshing it when using 'time ago' format. Installation You have multiple choice

Comments
  • Remove space while calling phone call API

    Remove space while calling phone call API

    In MTLLinkLabel/MTLLinkLabel/LinkLabel.swift linkLabelExecuteLink() method change let telURLString = "tel:" + text as let telURLString = "tel:" + text..stringByReplacingOccurrencesOfString(" ", withString: "")

    If any space is sent while calling phone call API application crashes. So for the where user wants to show spaced number in UI it won't crash.

    opened by usuf1990 0
Owner
Recruit Holdings. Media Technology Lab
Recruit Holdings. Media Technology Lab
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Optonaut 4.2k Dec 31, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel Simple countdown UILabel with morphing animation, and some useful function. features Simple creation Easily get status of countdown fro

keishi suzuki 903 Dec 29, 2022
Glitching UILabel for iOS 📺

Glitching UILabel for iOS ?? Created by Lee Sun-Hyoup. Try the sample $ pod try GlitchLabel Requirements iOS 8.0+ Swift 3 Xcode 8 Installation CocoaP

Lee Sun-Hyoup 1k Dec 14, 2022
Incrementable UILabel for iOS and tvOS

IncrementableLabel IncrementableLabel is the easiest way to have incrementable numbers in an UILabel! Usage let myIncrementableLabel = IncrementableLa

Tom Baranes 81 Feb 4, 2022
KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.

KDEDateLabel KDEDateLabel is an UILabel subclass that saves you from refreshing it when using 'time ago' format. Installation You have multiple choice

Kevin Delannoy 117 May 16, 2022
UILabel with image placed from left or right

SMIconLabel UILabel with possibility to place small icon on the left or on the right side. Take a look at preview image or build sample app to see how

Anatoliy Voropay 94 Apr 27, 2022
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.

MZTimerLabel Purpose MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple

Mines Chan 1.6k Dec 14, 2022
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more

TTTAttributedLabel A drop-in replacement for UILabel that supports attributes, data detectors, links, and more TTTAttributedLabel is a drop-in replace

TTTAttributedLabel 8.8k Dec 30, 2022
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.

THLabel THLabel is a subclass of UILabel, which additionally allows shadow blur, inner shadow, stroke text and fill gradient. Requirements iOS 4.0 or

Tobias Hagemann 654 Nov 27, 2022