Custom UILabel replacement to recognize, colorize and allow custom action handlers for Hashtags (#), Mentions (@) and URLs (http/https).
- Swift 2+
- Support
#Hashtags
,@Mentions
and http://links - Replacement for
UILabel
to use in Posts - Easy installation and customization
import ActionLabel
let label = ActionLabel()
//Custom Label Setup
label.text = "Post text #with #multiple #hashtags and some users like @carlosalcala or @twitter. Links are also supported like http://www.apple.com or http://www.twitter.com/carlosalcala"
label.textColor = .blackColor()
label.hashtagColor = .blueColor()
label.linkColor = .blueColor()
label.mentionColor = .blueColor()
//hashtag custom handler
label.hashtagHandler { hashtag in
print("Tapped the \(hashtag) hashtag")
}
//set frame
label.frame = CGRect(x: 10, y: 100, width: view.frame.width - 20, height: 500)
//add to current view
view.addSubview(label)
Add the following to your Cartfile
and follow these instructions
github "devcarlos/ActionLabel"
To integrate ActionLabel into your project add the following to your Podfile
:
platform :ios, '8.0'
use_frameworks!
pod 'ActionLabel'
ActionLabel
is based mostly on ActiveLabel
project but most of the recognition and regular expression logic has been rewritten, moved and improved to be a more DRY Pattern, module and single class to make this is a more simple control ready for customization.
- ActiveLabel (Swift) - UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
- TTTAttributedLabel (ObjC) - A drop-in replacement for UILabel that supports attributes, data detectors, links, and more
- STTweetLabel (ObjC) - A UILabel with #hashtag @handle and links tappable
- AMAttributedHighlightLabel (ObjC) - A UILabel subclass with mention/hashtag/link highlighting
- KILabel (ObjC) - A simple to use drop in replacement for UILabel for iOS 7 and above that highlights links such as URLs, twitter style usernames and hashtags and makes them touchable
ActionLabel
is available under the MIT license. See the LICENSE file for more info.