LNKLabel 0.2.0

LNKLabel 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by asashin227.



LNKLabel 0.2.0

  • By
  • asashin227




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.