Skip to main content

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 routes
  • delegate: The delegate that handles tap events on links, hashtags, or routes
  • isUserInteractionEnabled: 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 hashtags
  • replaceRouteToName(with:andPrefix:): Replaces route patterns in text with display names and attributes
  • detectAndHighlightURLs(in:): Detects and highlights URLs in the attributed string
  • detectAndHighlightHashtags(in:): Detects and highlights hashtags in the attributed string
  • getUserNames(in:): Extracts user names and routes from the text
  • touchesEnded(_:with:): Handles touch events and triggers delegate callbacks for detected links or hashtags
  • canPerformAction(_:withSender:): Restricts or allows text actions as needed
  • preparedTextStorage(): Prepares text storage for layout and interaction
  • url(at:): Determines if a touch location corresponds to a tappable link or hashtag
  • processInteraction(at:wasTap:): Processes tap or interaction at a given location

Delegate

  • LMTappableLabelDelegate: Protocol for handling tap events on links, hashtags, or routes
    • didTapOnLink(_:linkType:): Called when a tappable link, hashtag, or route is tapped