explaingit

optonaut/activelabel.swift

4,608SwiftAudience · developerComplexity · 2/5Setup · easy

TLDR

ActiveLabel is a Swift library for iOS that upgrades the standard text label to automatically detect and respond to taps on hashtags, @mentions, URLs, and email addresses, with customizable highlight colors and custom regex patterns.

Mindmap

mindmap
  root((activelabel.swift))
    What it does
      Detects tappable text
      Hashtags and mentions
      URLs and emails
      Custom regex patterns
    Tech stack
      Swift 5
      iOS
      CocoaPods
      Carthage
    Use cases
      Social feed cell labels
      Tappable mention links
      Clickable URL display
      Custom text triggers
    Audience
      iOS developers
      Swift app builders
      Social app teams
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add tappable hashtags and @mentions to a social media feed cell without building custom text parsing from scratch.

USE CASE 2

Display user-generated content in an iOS app that automatically highlights and makes URLs and email addresses clickable.

USE CASE 3

Define a custom tap pattern with a regular expression to detect and respond to any text format your app needs.

USE CASE 4

Replace UILabel with ActiveLabel in a Twitter- or Instagram-style app to get interactive text with minimal code.

Tech stack

SwiftiOSCocoaPodsCarthage

Getting it running

Difficulty · easy Time to first run · 30min

Requires iOS 10+ and Swift 5, add via CocoaPods or Carthage and swap UILabel for ActiveLabel in your code or storyboard.

In plain English

ActiveLabel is a Swift library for iOS that upgrades the standard text label component used in iPhone and iPad apps. The built-in UILabel in Apple's development framework displays plain or styled text, but it cannot detect and respond to taps on hashtags, usernames, or links within that text. ActiveLabel replaces it with a version that can. Out of the box, ActiveLabel highlights and makes tappable four types of content: hashtags (words starting with #), mentions (words starting with @), URLs, and email addresses. When a user taps on any of these, your app receives a callback with the tapped value so you can decide what to do, such as opening a profile page or launching a browser. You can also define custom patterns using regular expressions if you need to detect something beyond the four built-in types. The colors used for each type of highlighted text are configurable individually. Long URLs can be trimmed to a maximum display length so they do not overflow the label. The library includes a batch customization method that lets you set multiple properties at once without triggering a visual refresh for each individual change. Installation follows the standard iOS library process, supporting CocoaPods and Carthage, both of which are tools that manage third-party code in Apple platform projects. The library requires iOS 10 or newer and is written in Swift 5. This was built after the developers at Optonaut tried several existing alternatives and found them unsatisfactory in quality or ease of use. The README lists those alternatives at the bottom for reference.

Copy-paste prompts

Prompt 1
I'm building a social iOS app and want to detect taps on hashtags and @mentions in a label using ActiveLabel. Show me the Swift setup, how to configure highlight colors for each type, and how to handle the tap callback.
Prompt 2
Using ActiveLabel in Swift, how do I define a custom regex pattern to highlight and detect taps on support ticket numbers formatted like #TICKET-123?
Prompt 3
Show me how to install ActiveLabel via CocoaPods in my Xcode project and configure a label that trims long URLs to a maximum display length before showing them.
Prompt 4
I have a news feed in my iOS app. Using ActiveLabel, how do I make URLs open in an SFSafariViewController when tapped, while hashtags push a search results screen?
Open on GitHub → Explain another repo

← optonaut on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.