SwiftResponsiveLabel - A UILabel subclass which responds to touch on specified patterns

Overview

Version License Documentation

SwiftResponsiveLabel

A UILabel subclass which responds to touch on specified patterns. It has the following features:

  1. It can detect pattern specified by regular expression and apply style such as font, color etc.
  2. It allows to replace default ellipse with tappable attributed string to mark truncation
  3. Convenience methods are provided to detect hashtags, username handler and URLs

#Installation

Add following lines in your pod file

pod 'SwiftResponsiveLabel', '2.3'

#Usage

The following snippets explain the usage of public methods. These snippets assume an instance of ResponsiveLabel named "customLabel".

import SwiftResponsiveLabel

In interface builder, set the custom class of your UILabel to SwiftResponsiveLabel.

Username Handle Detection

let userHandleTapAction = PatternTapResponder{ (tappedString)-> (Void) in
let messageString = "You have tapped user handle:" + tappedString
self.messageLabel.text = messageString
}
let dict = [NSForegroundColorAttributeName: UIColor.greenColor(), 
NSBackgroundColorAttributeName: UIColor.blackColor()]
self.customLabel.enableUserHandleDetection([NSForegroundColorAttributeName:UIColor.grayColor(),
RLHighlightedAttributesDictionary: dict, RLTapResponderAttributeName:userHandleTapAction])

URL Detection

let URLTapAction = PatternTapResponder{(tappedString)-> (Void) in
let messageString = "You have tapped URL: " + tappedString
self.messageLabel.text = messageString
}
self.customLabel.enableURLDetection([NSForegroundColorAttributeName:UIColor.blueColor(), RLTapResponderAttributeName:URLTapAction])

HashTag Detection

let hashTagTapAction = PatternTapResponder { (tappedString)-> (Void) in
let messageString = "You have tapped hashTag:" + tappedString
self.messageLabel.text = messageString
}
let dict = [NSForegroundColorAttributeName: UIColor.redColor(), NSBackgroundColorAttributeName: UIColor.blackColor()]
customLabel.enableHashTagDetection([RLHighlightedAttributesDictionary : dict, NSForegroundColorAttributeName: UIColor.cyanColor(),
RLTapResponderAttributeName:hashTagTapAction])

Custom Truncation Token

Set attributed string as truncation token
let action = PatternTapResponder {(tappedString)-> (Void) in
print("You have tapped token string")
}
let dict = [RLHighlightedBackgroundColorAttributeName:UIColor.blackColor(),
RLHighlightedForegroundColorAttributeName:UIColor.greenColor(), RLTapResponderAttributeName:action]
let token = NSAttributedString(string: "...More", attributes: [NSFontAttributeName: customLabel.font, 
NSForegroundColorAttributeName:UIColor.brownColor(), RLHighlightedAttributesDictionary: dict])
customLabel.attributedTruncationToken = token
Set image as truncation token

The height of image size should be approximately equal to or less than the font height. Otherwise the image will not be rendered properly

let action = PatternTapResponder {(tappedString)-> (Void) in
print("You have tapped token image")
}
self.customLabel.setTruncationIndicatorImage(UIImage(named: "check")!, withSize: CGSize(width: 20.0, height: 20.0), andAction: action)
Set from interface builder

Screenshots

References

The underlying implementation of SwiftResponsiveLabel is based on KILabel(https://github.com/Krelborn/KILabel). SwiftResponsiveLabel is made flexible to enable detection of any pattern specified by regular expression.

The following articles were helpful in enhancing the functionalities.

You might also like...
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

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

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

UILabel subclass to perform text effects
UILabel subclass to perform text effects

CharacterText uses NSLayoutManager to position CATextLayers for each glyph in your string. This gives you the power to create some neat text effect using all the attributes of CATextLayer.

This is Github user search demo app which made by many variety of design patterns.
This is Github user search demo app which made by many variety of design patterns.

iOSDesignPatternSamples This is Github user search demo app which made by many variety of design patterns. Application Structure SearchViewController.

iPhone and iPod Touch version of Skeleton Key: is an addictive and unique puzzle game in which you shift keys around the board unlocking treasure chests. Made with cocos2d-iphone.

Skeleton Key (iOS) Skeleton Key is an addictive and unique puzzle game in which you shift keys around the board unlocking treasure chests. It's availa

Squares - a toy drum machine which you can control by multi touch capabilities of your track pad
Squares - a toy drum machine which you can control by multi touch capabilities of your track pad

Squares Squares is a toy drum machine which you can control by multi touch capab

Card Decks is a small utility application for your iPhone, iPod touch and iPad which brings you simple, configurable, colored, multi-line text cards that are grouped into card decks

Card Decks is a small utility application for your iPhone, iPod touch and iPad which brings you simple, configurable, colored, multi-line text cards that are grouped into card decks.

A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.
A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.

A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code. Preview You'll be

A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.
A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.

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

SMNumberWheel is a subclass of UIControl written in Swift, which is ideal for picking numbers using a rotating wheel.

SMNumberWheel version: 1.0.3 [![CI Status](http://img.shields.io/travis/Sina Moetakef/SMNumberWheel.svg?style=flat)](https://travis-ci.org/Sina Moetak

An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code

Deprecated This library is no longer maintained and is deprecated. The repository might be removed at any point in the future. MBAutoGrowingTextView A

AutoKeyboardScrollView is an UIScrollView subclass which makes showing and dismissing keyboard for UITextFields much easier. So called keyboard avoidance.
AutoKeyboardScrollView is an UIScrollView subclass which makes showing and dismissing keyboard for UITextFields much easier. So called keyboard avoidance.

AutoKeyboardScrollView AutoKeyboardScrollView is a smart UIScrollView which can: Scroll to proper position and make sure the active textField is visib

FancyGradient is a UIView subclass which let's you animate gradients in your iOS app. It is purely written in Swift.
FancyGradient is a UIView subclass which let's you animate gradients in your iOS app. It is purely written in Swift.

FancyGradient is a UIView subclass which let's you animate gradients in your iOS app. It is purely written in Swift. Quickstart Static gradient let fa

πŸ“– Design Patterns implemented in Swift 5.0

Design Patterns implemented in Swift 5.0 A short cheat-sheet with Xcode 10.2 Playground (Design-Patterns.playground.zip). πŸ‡¨πŸ‡³ δΈ­ζ–‡η‰ˆ πŸ‘· Project started

πŸ“– Design Patterns implemented in Swift 5.0

πŸ“– Design Patterns implemented in Swift 5.0

Models UI navigation patterns using TCA

Composable Navigation The Composable Navigation is a Swift Package that builds on top of The Composable Architecture (TCA, for short). It models UI na

An app to count stitches in crochet patterns. Multiplatform.
An app to count stitches in crochet patterns. Multiplatform.

An app to count your crochet patterns' stitches! Made with 100% SwiftUI, no UIKit, and no 3rd party dependencies. Powered by regular expressions. Down

Comments
  • Not work with new line string

    Not work with new line string

    The label does not work with new line string. Example: string = "a\nb\nc\nd\n\e\n\f\n" and numberOfLines = 3 For UITableViewAutomaticDimension in UITableView.

    opened by datnm-apv 0
  • Last hashtag not detected

    Last hashtag not detected

    When there are multiple hashtags, the last hashtag doesn't detect fully. Say if its #problem, it detects till #prob and the rest is normal string. Same problems with links too, gets cut in between.

    Screenshots https://drive.google.com/file/d/1zzfAUoTz4rjzRhaHiACUlYEwmd1v-9jf/view?usp=sharing https://drive.google.com/file/d/1baPWGKCVNiAKUURi6JgKW4fGtYNcu0JB/view?usp=sharing

    opened by sameersyd 1
Owner
Susmita Horrow
Susmita Horrow
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.

Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm . Stop inheriting from Object! Go for Protocol-Oriented program

Artur  Mkrtchyan 518 Dec 13, 2022
Shows the issue with swift using an ObjC class which has a property from a swift package.

SwiftObjCSwiftTest Shows the issue with swift using an ObjC class which has a property from a swift package. The Swift class (created as @objc derived

Scott Little 0 Nov 8, 2021
Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: get real changes, without the noise.

ContactsChangeNotifier Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: Get real changes, without the noise.

Yonat Sharon 5 Oct 31, 2022
ResponsiveLabel A UILabel subclass which responds to touch on specified patterns.

#ResponsiveLabel A UILabel subclass which responds to touch on specified patterns. It has the following features: It can detect pattern specified by r

Susmita Horrow 219 Nov 16, 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
IHTypeWriterLabel - A simple, UILabel subclass which poulates itself as if being typed

IHTypeWriterLabel A simple, UILabel subclass which poulates itself as if being typed. HighLights Written purely in SWIFT. Very simple and lightweight.

Md Ibrahim Hassan 24 May 7, 2019
A container view that responds to scrolling of UIScrollView

FlexibleHeader A container view that responds to scrolling of UIScrollView. normal threshold FlexibleHeaderExecutantType Getting Started Progressive I

DongHee Kang 69 May 2, 2022
SnackBar that responds to the keyboard and shows a message at the bottom of the screen.

DGSnackBar Requirements Installation Usage Properties DGSnackBar SnackBar that responds to the keyboard and shows a message at the bottom of the scree

donggyu 11 Aug 6, 2022
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 2022
A simple to use iOS app with clean UI to calculate time until a specified date

A simple to use iOS app with clean UI to calculate time until a specified date.Added new feature that is now you can measure time from a specified date as well. Like time spent from the day you were born.

Dishant Nagpal 2 Feb 28, 2022