Skip to content

A modern and highly customizable UILabel subclass for Swift, supporting hashtags, mentions, URLs, and custom patterns. Inspired by ActiveLabel.swift, powered by Combine and SwiftUI.

License

Notifications You must be signed in to change notification settings

silexKhan/InteractiveLabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡°πŸ‡· ν•œκ΅­μ–΄ Β Β |Β Β  πŸ‡ΊπŸ‡Έ English


πŸ‡°πŸ‡· ν•œκ΅­μ–΄

InteractiveLabel

SPM compatible

InteractiveLabel은 ν…μŠ€νŠΈ λ‚΄μ—μ„œ ν•΄μ‹œνƒœκ·Έ, λ©˜μ…˜, URL, 이메일, μ‚¬μš©μž μ •μ˜ νŒ¨ν„΄ 등을 κ°μ§€ν•˜μ—¬ μƒν˜Έμž‘μš©μ„ κ°€λŠ₯ν•˜κ²Œ ν•˜λŠ” κ°•λ ₯ν•˜κ³  μœ μ—°ν•œ UILabel μ„œλΈŒν΄λž˜μŠ€μž…λ‹ˆλ‹€.

이 ν”„λ‘œμ νŠΈλŠ” 더 이상 μœ μ§€λ³΄μˆ˜λ˜μ§€ μ•ŠλŠ” optonaut/ActiveLabel.swift의 쒋은 κΈ°λŠ₯κ³Ό 아이디어에 λͺ¨ν‹°λΈŒλ₯Ό μ–»μ–΄, ν˜„λŒ€μ μΈ Swift κΈ°λŠ₯(Combine, SwiftUI)κ³Ό 더 λ‚˜μ€ μ•„ν‚€ν…μ²˜λ₯Ό μ μš©ν•˜μ—¬ μƒˆλ‘­κ²Œ λ§Œλ“€μ–΄μ‘ŒμŠ΅λ‹ˆλ‹€.

✨ νŠΉμ§• (Features)

  • λ‹€μ–‘ν•œ νƒ€μž… 감지: ν•΄μ‹œνƒœκ·Έ(#), λ©˜μ…˜(@), URL, 이메일 κΈ°λ³Έ 지원
  • μ‚¬μš©μž μ •μ˜ νŒ¨ν„΄: μ •κ·œμ‹μ„ μ‚¬μš©ν•˜μ—¬ μ›ν•˜λŠ” λͺ¨λ“  νŒ¨ν„΄μ„ κ°μ§€ν•˜κ³  처리
  • μ„€μ • 객체 기반의 μ†μ‰¬μš΄ μ»€μŠ€ν„°λ§ˆμ΄μ§•: InteractiveLabelConfig 객체λ₯Ό 톡해 색상, 폰트, 쀄 간격 λ“± λͺ¨λ“  μ‹œκ°μ  μš”μ†Œλ₯Ό ν•œ κ³³μ—μ„œ 관리
  • ν˜„λŒ€μ μΈ 이벀트 처리: Combine PassthroughSubject (didTap)λ₯Ό 톡해 νƒ­ 이벀트λ₯Ό λ°˜μ‘ν˜•μœΌλ‘œ 처리
  • ν’λΆ€ν•œ ν„°μΉ˜ κ²½ν—˜: ν„°μΉ˜κ°€ μ‹œμž‘λ˜λŠ” μ¦‰μ‹œ ν•˜μ΄λΌμ΄νŠΈκ°€ 적용되고, ν„°μΉ˜ μœ„μΉ˜λ₯Ό λ²—μ–΄λ‚˜λ©΄ ν•΄μ œλ˜λŠ” λ“± μ„¬μ„Έν•œ μƒν˜Έμž‘μš© 제곡
  • SwiftUI 지원: InteractiveLabelViewλ₯Ό 톡해 SwiftUI ν”„λ‘œμ νŠΈμ—μ„œ μ†μ‰½κ²Œ μ‚¬μš© κ°€λŠ₯
  • κΉ”λ”ν•œ μ•„ν‚€ν…μ²˜: TextManager, TouchManager λ“± μ—­ν• λ³„λ‘œ μ±…μž„μ΄ λͺ…ν™•ν•˜κ²Œ λΆ„λ¦¬λ˜μ–΄ μœ μ§€λ³΄μˆ˜ 및 ν™•μž₯이 용이

πŸ“‹ μš”κ΅¬μ‚¬ν•­ (Requirements)

  • iOS: 13.0+
  • Xcode: 14.0+
  • Swift: 5.0+

πŸ“¦ μ„€μΉ˜ (Installation)

Swift Package Manager (SPM)

Xcodeμ—μ„œ File > Add Packages...λ₯Ό μ„ νƒν•˜κ³ , μ•„λž˜μ˜ μ €μž₯μ†Œ URL을 μΆ”κ°€ν•©λ‹ˆλ‹€.

https://github.com/silexKhan/InteractiveLabel.git

πŸš€ μ‚¬μš©λ²• (Usage)

import UIKit
import Combine
import InteractiveLabel

class ViewController: UIViewController {

    private var cancellables = Set<AnyCancellable>()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let label = InteractiveLabel()
        label.numberOfLines = 0
        label.text = "#ν•΄μ‹œνƒœκ·Έ, @λ©˜μ…˜, URL(https://github.com)을 λˆŒλŸ¬λ³΄μ„Έμš”."
        label.enabledTypes = [.hashtag, .mention, .url]
        
        view.addSubview(label)
        // ... μ˜€ν† λ ˆμ΄μ•„μ›ƒ μ„€μ • ...
        
        // νƒ­ 이벀트 처리
        label.didTap
            .sink { element in
                self.handleTap(on: element)
            }
            .store(in: &cancellables)
    }
    
    func handleTap(on element: InteractiveElement) {
        switch element {
        case .hashtag(let hashtag):
            print("Tapped hashtag: \(hashtag)")
        case .mention(let mention):
            print("Tapped mention: \(mention)")
        case .url(let url, _):
            print("Tapped URL: \(url)")
        default:
            break
        }
    }
}

βš™οΈ μ„€μ • (Configuration)

InteractiveLabel의 λͺ¨λ“  μ‹œκ°μ  μš”μ†Œμ™€ μ •κ·œμ‹ νŒ¨ν„΄μ€ config ν”„λ‘œνΌν‹°λ₯Ό 톡해 λ³€κ²½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

// InteractiveLabel μΈμŠ€ν„΄μŠ€ 생성 ν›„

// 색상 λ³€κ²½
label.config.hashtagColor = .systemPurple
label.config.hashtagSelectedColor = .systemIndigo
label.config.mentionColor = .systemOrange

// ν•˜μ΄λΌμ΄νŠΈ μ‹œ 폰트 λ³€κ²½
label.config.highlightFontName = "Helvetica-Bold"
label.config.highlightFontSize = label.font.pointSize

// URL μ΅œλŒ€ 길이 μ„€μ •
label.config.urlMaximumLength = 30

// μ‚¬μš©μž μ •μ˜ νŒ¨ν„΄ μΆ”κ°€
let customType = InteractiveType.custom(pattern: "silex")
label.enabledTypes.append(customType)
label.config.customColor[customType] = .systemGreen

label.handleCustom(for: customType) { customString in
    print("Custom type tapped: \(customString)")
}

🀝 κΈ°μ—¬ 방법 (Contributing)

이슈 제보 및 κΈ°λŠ₯ μ œμ•ˆ, Pull Request λ“± λͺ¨λ“  μ’…λ₯˜μ˜ κΈ°μ—¬λ₯Ό ν™˜μ˜ν•©λ‹ˆλ‹€.

πŸ”— λŒ€μ•ˆ 라이브러리 (Alternatives)

πŸ‘¨β€πŸ’» μž‘μ„±μž (Author)

πŸ“„ λΌμ΄μ„ μŠ€ (License)

InteractiveLabel은 MIT λΌμ΄μ„ μŠ€μ— 따라 λ°°ν¬λ©λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ LICENSE νŒŒμΌμ„ μ°Έκ³ ν•˜μ‹­μ‹œμ˜€.


πŸ‡ΊπŸ‡Έ English

InteractiveLabel

SPM compatible

InteractiveLabel is a powerful and flexible UILabel subclass that detects patterns like hashtags, mentions, URLs, emails, and custom patterns within text, enabling interaction.

This project was inspired by the great features and ideas of the no-longer-maintained optonaut/ActiveLabel.swift, and has been newly created with modern Swift features (Combine, SwiftUI) and a better architecture.

✨ Features

  • Multiple Type Detection: Default support for hashtags (#), mentions (@), URLs, and emails.
  • Custom Patterns: Detect and handle any custom pattern using regular expressions.
  • Easy Customization via Config Object: Manage all visual elements like colors, fonts, and line spacing in one place with the InteractiveLabelConfig object.
  • Modern Event Handling: Handle tap events reactively through a Combine PassthroughSubject (didTap).
  • Rich Touch Experience: Provides delicate interactions, such as highlighting immediately on touch-down and releasing when the touch moves away.
  • SwiftUI Support: Easily usable in SwiftUI projects with InteractiveLabelView.
  • Clean Architecture: Responsibilities are clearly separated by roles (TextManager, TouchManager), making it easy to maintain and extend.

πŸ“‹ Requirements

  • iOS: 13.0+
  • Xcode: 14.0+
  • Swift: 5.0+

πŸ“¦ Installation

Swift Package Manager (SPM)

In Xcode, select File > Add Packages... and add the repository URL below.

https://github.com/silexKhan/InteractiveLabel.git

πŸš€ Usage

import UIKit
import Combine
import InteractiveLabel

class ViewController: UIViewController {

    private var cancellables = Set<AnyCancellable>()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let label = InteractiveLabel()
        label.numberOfLines = 0
        label.text = "Tap on a #hashtag, @mention, or URL like https://github.com."
        label.enabledTypes = [.hashtag, .mention, .url]
        
        view.addSubview(label)
        // ... set up auto layout ...
        
        // Handle tap events
        label.didTap
            .sink { element in
                self.handleTap(on: element)
            }
            .store(in: &cancellables)
    }
    
    func handleTap(on element: InteractiveElement) {
        switch element {
        case .hashtag(let hashtag):
            print("Tapped hashtag: \(hashtag)")
        case .mention(let mention):
            print("Tapped mention: \(mention)")
        case .url(let url, _):
            print("Tapped URL: \(url)")
        default:
            break
        }
    }
}

βš™οΈ Configuration

All visual elements and regex patterns of InteractiveLabel can be changed via the config property.

// After creating an InteractiveLabel instance

// Change colors
label.config.hashtagColor = .systemPurple
label.config.hashtagSelectedColor = .systemIndigo
label.config.mentionColor = .systemOrange

// Change font on highlight
label.config.highlightFontName = "Helvetica-Bold"
label.config.highlightFontSize = label.font.pointSize

// Set max URL length
label.config.urlMaximumLength = 30

// Add a custom pattern
let customType = InteractiveType.custom(pattern: "silex")
label.enabledTypes.append(customType)
label.config.customColor[customType] = .systemGreen

label.handleCustom(for: customType) { customString in
    print("Custom type tapped: \(customString)")
}

🀝 Contributing

All kinds of contributions are welcome, including issue reports, feature suggestions, and Pull Requests.

πŸ”— Alternatives

πŸ‘¨β€πŸ’» Author

πŸ“„ License

InteractiveLabel is distributed under the MIT license. See LICENSE for more information.

About

A modern and highly customizable UILabel subclass for Swift, supporting hashtags, mentions, URLs, and custom patterns. Inspired by ActiveLabel.swift, powered by Combine and SwiftUI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages