Description
A UILabel subclass which responds to touch on specified patterns. It has the following features: a. It can detect pattern specified by regular expression and apply style like font, color etc. b. It allows to replace default ellipse with tappable attributed string to mark truncation c. Convenience methods are provided to detect hashtags, username handler and URLs
ResponsiveLabel alternatives and similar libraries
Based on the "Label" category.
Alternatively, view ResponsiveLabel alternatives based on common mentions on social networks and blogs.
-
TTTAttributedLabel
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more -
LTMorphingLabel
[EXPERIMENTAL] Graceful morphing effects for UILabel written in Swift. -
ActiveLabel.swift
UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift -
ZCAnimatedLabel
UILabel replacement with fine-grain appear/disappear animation -
UICountingLabel
Adds animated counting support to UILabel. -
TOMSMorphingLabel
Configurable morphing transitions between text values of a label. -
MZTimerLabel
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App. -
NumberMorphView
A label view for displaying numbers which can transition or animate using a technique called number tweening or number morphing. -
CountdownLabel
Simple countdown UILabel with morphing animation, and some useful function. -
Preloader.Ophiuchus
Custom Label to apply animations on whole text or letters. -
THLabel
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient. -
TriLabelView
A triangle shaped corner label view for iOS written in Swift. -
MTLLinkLabel
MTLLinkLabel is linkable UILabel. Written in Swift. -
IncrementableLabel
Incrementable UILabel for iOS and tvOS -
SlidingText
Swift UIView for sliding text with page indicator -
SwiftResponsiveLabel
A UILabel subclass to highlight patterns -
NumericAnimatedLabel
Animate numeric value while setting new value to label -
AnimatedMaskLabel
Animated Mask Label is a nice gradient animated label. This is an easy way to add a shimmering effect to any view in your app. It is useful as an unobtrusive loading indicator. -
JSLabel
A simple designable subclass on UILabel with extra IBDesignable and Blinking features.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of ResponsiveLabel or a related project?
README
ResponsiveLabel
A UILabel subclass which responds to touch on specified patterns. It has the following features:
- It can detect pattern specified by regular expression and apply style like font, color etc.
- It allows to replace default ellipse with tappable attributed string to mark truncation
- Convenience methods are provided to detect hashtags, username handler and URLs
Installation
Add following lines in your pod file
pod 'ResponsiveLabel', '~> 1.0.11'
Usage
The following snippets explain the usage of public methods. These snippets assume an instance of ResponsiveLabel named "customLabel".
#import <ResponsiveLabel.h>
In interface builder, set the custom class of your UILabel to ResponsiveLabel. You may get an error message saying "error: IB Designables: Failed to update auto layout status: Failed to load designables from path (null)" This appears to be an issue with Xcode and Cocoapods and does not seem to cause any problems, but some have been able to fix it, see this Stackoverflow question for more details.
Pattern Detection
//Detects email in text
NSString *emailRegexString = @"[A-Z0-9._%+-][email protected][A-Z0-9.-]+\\.[A-Z]{2,4}";
NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:emailRegexString
options:0
error:&error];
PatternDescriptor *descriptor = [[PatternDescriptor alloc]initWithRegex:regex withSearchType:PatternSearchTypeAll
withPatternAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
[self.customLabel enablePatternDetection:descriptor];
String Detection
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder tapResponder = ^(NSString *string) {
NSLog(@"tapped = %@",string);
};
[self.customLabel enableStringDetection:@"text" withAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],
RLTapResponderAttributeName: tapResponder}];
Array of String Detection
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder stringTapAction = ^(NSString *tappedString) {
NSLog(@"tapped string = %@",tappedString);
};
[self.customLabel enableDetectionForStrings:@[@"text",@"long"] withAttributes:@{NSForegroundColorAttributeName:[UIColor brownColor],
RLTapResponderAttributeName:stringTapAction}];
HashTag Detection
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder hashTagTapAction = ^(NSString *tappedString) {
NSLog(@"HashTag Tapped = %@",tappedString);
};
[self.customLabel enableHashTagDetectionWithAttributes:
@{NSForegroundColorAttributeName:[UIColor redColor], RLTapResponderAttributeName:hashTagTapAction}];
Username Handle Detection
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder userHandleTapAction = ^(NSString *tappedString){
NSLog(@"Username Handler Tapped = %@",tappedString);
};
[self.customLabel enableUserHandleDetectionWithAttributes:
@{NSForegroundColorAttributeName:[UIColor grayColor],RLTapResponderAttributeName:userHandleTapAction}];
URL Detection
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder urlTapAction = ^(NSString *tappedString) {
NSLog(@"URL Tapped = %@",tappedString);
};
[self.customLabel enableURLDetectionWithAttributes:
@{NSForegroundColorAttributeName:[UIColor cyanColor],NSUnderlineStyleAttributeName:[NSNumber
numberWithInt:1],RLTapResponderAttributeName:urlTapAction}];
Highlight Patterns On Tap
To highlight patterns, one can set the attributes:
- RLHighlightedForegroundColorAttributeName
- RLHighlightedBackgroundColorAttributeName
- RLHighlightedBackgroundCornerRadius
self.customLabel.userInteractionEnabled = YES;
PatternTapResponder userHandleTapAction = ^(NSString *tappedString){
NSLog(@"Username Handler Tapped = %@",tappedString);
};
[self.customLabel enableUserHandleDetectionWithAttributes:
@{NSForegroundColorAttributeName:[UIColor grayColor],RLHighlightedForegroundColorAttributeName:[UIColor greenColor],RLHighlightedBackgroundCornerRadius:@5,RLHighlightedBackgroundColorAttributeName:[UIColor blackColor],RLTapResponderAttributeName:userHandleTapAction}];
Custom Truncation Token
Set attributed string as truncation token
Deprecated in 1.0.10
NSString *expansionToken = @"Read More ...";
NSString *str = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:kExpansionToken attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:self.customLabel.font}];
[self.customLabel setAttributedTruncationToken:attribString withAction:^(NSString *tappedString) {
NSLog(@"Tap on truncation text");
}];
[self.customLabel setText:str withTruncation:YES];
Latest introduced on 1.0.10
NSString *expansionToken = @"Read More ...";
NSString *str = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
PatternTapResponder tap = ^(NSString *string) {
NSLog(@"Tap on truncation text");
}
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:kExpansionToken attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:self.customLabel.font,RLTapResponderAttributeName:tap}];
[self.customLabel setAttributedTruncationToken:attribString];
[self.customLabel setText:str withTruncation:YES];
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
[self.customLabel setTruncationIndicatorImage:[UIImage imageNamed:@"more_image"] withSize:CGSizeMake(25, 5) andAction:^(NSString *tappedString) {
NSLog(@"tapped on image");
}];
Set from interface builder
Screenshots
References
The underlying implementation of ResponsiveLabel is based on KILabel(https://github.com/Krelborn/KILabel). ResponsiveLabel is made flexible to enable detection of any pattern specified by regular expression.
The following articles were helpful in enhancing the functionalities.
*Note that all licence references and agreements mentioned in the ResponsiveLabel README section above
are relevant to that project's source code only.