LMTappableLabel
Overview
The LMTappableLabel
is a customizable label widget that extends LMLabel
and provides advanced support for tappable links, hashtags, and custom routes within text. It enables detection, highlighting, and interaction with links and hashtags, and allows delegation of tap events for custom handling.
File Location:
LMTappableLabel.swift
Functionality
UI Components
attributedText
: The label's attributed text supporting links, hashtags, and routesdelegate
: The delegate that handles tap events on links, hashtags, or routesisUserInteractionEnabled
: Enables user interaction for tap detection
Properties
NameWithRoute
: Struct representing a name and associated route for custom link handling
Methods
setText(_:)
: Sets the label's text and processes it for tappable links and hashtagsreplaceRouteToName(with:andPrefix:)
: Replaces route patterns in text with display names and attributesdetectAndHighlightURLs(in:)
: Detects and highlights URLs in the attributed stringdetectAndHighlightHashtags(in:)
: Detects and highlights hashtags in the attributed stringgetUserNames(in:)
: Extracts user names and routes from the texttouchesEnded(_:with:)
: Handles touch events and triggers delegate callbacks for detected links or hashtagscanPerformAction(_:withSender:)
: Restricts or allows text actions as neededpreparedTextStorage()
: Prepares text storage for layout and interactionurl(at:)
: Determines if a touch location corresponds to a tappable link or hashtagprocessInteraction(at:wasTap:)
: Processes tap or interaction at a given location
Delegate
LMTappableLabelDelegate
: Protocol for handling tap events on links, hashtags, or routesdidTapOnLink(_:linkType:)
: Called when a tappable link, hashtag, or route is tapped