Welcome to the documentation for STTweetLabel, a custom UILabel subclass that makes hashtags, mentions, and hyperlinks tappable!
Features
- Create tappable hashtags, mentions, and hyperlinks within a UILabel
- Customizable appearance and behavior
- Supports both Swift and Objective-C
Installation
- Using CocoaPods, add the following line to your Podfile:
pod 'STTweetLabel'
- Run
pod install
to install the dependency - Import the library into your project:
Swift:import STTweetLabel
Objective-C:#import <STTweetLabel/STTweetLabel.h>
Usage
Basic Usage
- Create an instance of
STTweetLabel
- Set the label’s text
- Use the methods provided by
STTweetLabel
to customize the appearance and behavior of hashtags, mentions, and hyperlinks
// Swift example
let tweetLabel = STTweetLabel()
tweetLabel.text = "Hello, @username! Check out #CocoaDocs for awesome documentation."
tweetLabel.hashtagColor = UIColor.blue
tweetLabel.mentionColor = UIColor.green
tweetLabel.URLColor = UIColor.purple
tweetLabel.configure()
// Objective-C example
STTweetLabel *tweetLabel = [[STTweetLabel alloc] init];
[tweetLabel setText:@"Hello, @username! Check out #CocoaDocs for awesome documentation."];
[tweetLabel setHashtagColor:[UIColor blueColor]];
[tweetLabel setMentionColor:[UIColor greenColor]];
[tweetLabel setURLColor:[UIColor purpleColor]];
[tweetLabel configure];
Advanced Usage
- Override the delegate methods provided by
STTweetLabel
to handle the tap events for hashtags, mentions, and hyperlinks - Set the attributes for the tappable elements using the
attributedTextForString
method - Call the
configure
method after setting the attributed text
// Swift example
tweetLabel.attributedText = tweetLabel.attributedTextForString(string: "Hello, @username! Check out #CocoaDocs for awesome documentation.")
tweetLabel.hashtagSelectedColor = UIColor.yellow
tweetLabel.mentionSelectedColor = UIColor.orange
tweetLabel.URLSelectedColor = UIColor.red
tweetLabel.configure()
// Objective-C example
[tweetLabel setAttributedText:[tweetLabel attributedTextForString:@"Hello, @username! Check out #CocoaDocs for awesome documentation."]];
[tweetLabel setHashtagSelectedColor:[UIColor yellowColor]];
[tweetLabel setMentionSelectedColor:[UIColor orangeColor]];
[tweetLabel setURLSelectedColor:[UIColor redColor]];
[tweetLabel configure];
That’s it! You are now ready to use STTweetLabel to create tappable hashtags, mentions, and hyperlinks within your UILabel!