All Projects → optonaut → Activelabel.swift

optonaut / Activelabel.swift

Licence: mit
UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Activelabel.swift

Tweetie
Simple jQuery Twitter feed plugin
Stars: ✭ 314 (-92.03%)
Mutual labels:  twitter
Socialreaper
Social media scraping / data collection library for Facebook, Twitter, Reddit, YouTube, Pinterest, and Tumblr APIs
Stars: ✭ 338 (-91.43%)
Mutual labels:  twitter
Marqueelabel
Charles Powell
Stars: ✭ 3,741 (-5.1%)
Mutual labels:  uilabel
Rainbowstream
A smart and nice Twitter client on terminal written in Python.
Stars: ✭ 3,344 (-15.17%)
Mutual labels:  twitter
Snowflake
Twitter的分布式自增ID雪花算法snowflake (Java版)
Stars: ✭ 336 (-91.48%)
Mutual labels:  twitter
Miranda Ng
Miranda NG: Next Generation of Miranda IM
Stars: ✭ 341 (-91.35%)
Mutual labels:  twitter
Hybridauth
Open source social sign on PHP Library. HybridAuth goal is to act as an abstract api between your application and various social apis and identities providers such as Facebook, Twitter and Google.
Stars: ✭ 3,223 (-18.24%)
Mutual labels:  twitter
Yotter
Youtube and Twitter with privacy.
Stars: ✭ 376 (-90.46%)
Mutual labels:  twitter
Socialbox Termux
SocialBox is a Bruteforce Attack Framework [ Facebook , Gmail , Instagram ,Twitter ] , Coded By Belahsan Ouerghi Edit By init__0 for termux on android
Stars: ✭ 324 (-91.78%)
Mutual labels:  twitter
Privacy Redirect
A simple web extension that redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.
Stars: ✭ 342 (-91.32%)
Mutual labels:  twitter
Social Media Profiles Regexs
📇 Extract social media profiles and more with regular expressions
Stars: ✭ 324 (-91.78%)
Mutual labels:  twitter
Sockethub
A protocol gateway for the Web.
Stars: ✭ 329 (-91.65%)
Mutual labels:  twitter
Rrssb
RRSSB is a KNI Labs freebie crafted by @dbox and @joshuatuscan.
Stars: ✭ 3,443 (-12.66%)
Mutual labels:  twitter
Mastodon Twitter Poster
Crossposter to post statuses between Mastodon and Twitter
Stars: ✭ 317 (-91.96%)
Mutual labels:  twitter
Tweetbotornot
🤖 R package for detecting Twitter bots via machine learning
Stars: ✭ 355 (-90.99%)
Mutual labels:  twitter
Twitter Api V2 Sample Code
Sample code for the Twitter API early access endpoints (Python, Java, Ruby, and Node.js).
Stars: ✭ 306 (-92.24%)
Mutual labels:  twitter
Twitter Together
🐦 A GitHub action to tweet from a repository
Stars: ✭ 340 (-91.37%)
Mutual labels:  twitter
Play Pac4j
Security library for Play framework 2 in Java and Scala: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 375 (-90.49%)
Mutual labels:  twitter
Treeverse
A browser extension for navigating burgeoning Twitter conversations
Stars: ✭ 365 (-90.74%)
Mutual labels:  twitter
Advertools
advertools - online marketing productivity and analysis tools
Stars: ✭ 341 (-91.35%)
Mutual labels:  twitter

ActiveLabel.swift Carthage compatible Build Status

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

Features

  • Swift 5.0 (1.1.0+) and 4.2 (1.0.1)
  • Default support for Hashtags, Mentions, Links, Emails
  • Support for custom types via regex
  • Ability to enable highlighting only for the desired types
  • Ability to trim urls
  • Super easy to use and lightweight
  • Works as UILabel drop-in replacement
  • Well tested and documented

Install (iOS 10+)

Carthage

Add the following to your Cartfile and follow these instructions

github "optonaut/ActiveLabel.swift"

CocoaPods

CocoaPods 0.36 adds supports for Swift and embedded frameworks. To integrate ActiveLabel into your project add the following to your Podfile:

platform :ios, '10.0'
use_frameworks!

pod 'ActiveLabel'

Usage

import ActiveLabel

let label = ActiveLabel()
label.numberOfLines = 0
label.enabledTypes = [.mention, .hashtag, .url, .email]
label.text = "This is a post with #hashtags and a @userhandle."
label.textColor = .black
label.handleHashtagTap { hashtag in
    print("Success. You just tapped the \(hashtag) hashtag")
}

Custom types

let customType = ActiveType.custom(pattern: "\\swith\\b") //Regex that looks for "with"
label.enabledTypes = [.mention, .hashtag, .url, .email, customType]
label.text = "This is a post with #hashtags and a @userhandle."
label.customColor[customType] = UIColor.purple
label.customSelectedColor[customType] = UIColor.green
label.handleCustomTap(for: customType) { element in
    print("Custom type tapped: \(element)")
}

Enable/disable highlighting

By default, an ActiveLabel instance has the following configuration

label.enabledTypes = [.mention, .hashtag, .url, .email]

But feel free to enable/disable to fit your requirements

Batched customization

When using ActiveLabel, it is recommended to use the customize(block:) method to customize it. The reason is that ActiveLabel is reacting to each property that you set. So if you set 3 properties, the textContainer is refreshed 3 times.

When using customize(block:), you can group all the customizations on the label, that way ActiveLabel is only going to refresh the textContainer once.

Example:

label.customize { label in
    label.text = "This is a post with #multiple #hashtags and a @userhandle."
    label.textColor = UIColor(red: 102.0/255, green: 117.0/255, blue: 127.0/255, alpha: 1)
    label.hashtagColor = UIColor(red: 85.0/255, green: 172.0/255, blue: 238.0/255, alpha: 1)
    label.mentionColor = UIColor(red: 238.0/255, green: 85.0/255, blue: 96.0/255, alpha: 1)
    label.URLColor = UIColor(red: 85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
    label.handleMentionTap { self.alert("Mention", message: $0) }
    label.handleHashtagTap { self.alert("Hashtag", message: $0) }
    label.handleURLTap { self.alert("URL", message: $0.absoluteString) }
}

Trim long urls

You have the possiblity to set the maximum lenght a url can have;

label.urlMaximumLength = 30

From now on, a url that's bigger than that, will be trimmed.

https://afancyurl.com/whatever -> https://afancyurl.com/wh...

API

mentionColor: UIColor = .blueColor()
mentionSelectedColor: UIColor?
hashtagColor: UIColor = .blueColor()
hashtagSelectedColor: UIColor?
URLColor: UIColor = .blueColor()
URLSelectedColor: UIColor?
customColor: [ActiveType : UIColor]
customSelectedColor: [ActiveType : UIColor]
lineSpacing: Float?
handleMentionTap: (String) -> ()
label.handleMentionTap { userHandle in print("\(userHandle) tapped") }
handleHashtagTap: (String) -> ()
label.handleHashtagTap { hashtag in print("\(hashtag) tapped") }
handleURLTap: (NSURL) -> ()
label.handleURLTap { url in UIApplication.shared.openURL(url) }
handleEmailTap: (String) -> ()
label.handleEmailTap { email in print("\(email) tapped") }
handleCustomTap(for type: ActiveType, handler: (String) -> ())
label.handleCustomTap(for: customType) { element in print("\(element) tapped") }
filterHashtag: (String) -> Bool
label.filterHashtag { hashtag in validHashtags.contains(hashtag) }
filterMention: (String) -> Bool
label.filterMention { mention in validMentions.contains(mention) }

Alternatives

Before writing ActiveLabel we've tried a lot of the following alternatives but weren't quite satisfied with the quality level or ease of usage, so we decided to contribute our own solution.

  • 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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].