Skip to content

asashin227/LNKLabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LNKLabel

CI Status Version License Platform

LNKLabel is customed UILabel that is linkable and highlighted.

Usage

Make linkale label

let label = LNKLabel()
label.linkPatterns = [MailPattern(), URLPattern(), PhonePattern()]
label.text = "https://github.com/asashin227/LNKLabel\n09012345678\n[email protected]\nhogehogefugafuga"
label.delegate = self
label.numberOfLines = 0
label.frame.size.width = UIScreen.main.bounds.size.width
label.sizeToFit()
label.center = self.view.center
view.addSubview(label)

Receive taped callback

extension YourClass: LNKLabelDelegate {
    
    func didTaped(label: LNKLabel, pattern: Pattern, matchText: String, range: NSRange) {
        switch pattern {
        case is URLPattern:
            print("taped url link: \(matchText)")
        case is MailPattern:
            print("taped mail address: \(matchText)")
        case is PhonePattern:
            print("taped phone number: \(matchText)")
        default:
            break
        }
    }
    
}

Make custom link pattern

public class CustomPattern: Pattern {
    override public var regString: String {
        return "hogehoge"
    }
}

and add for link

label.linkPatterns?.append(CustomPattern())

Installation

LNKLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LNKLabel'

License

LNKLabel is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published