TapLabel 0.1.0

TapLabel 0.1.0

测试测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2015年11月
SPM支持SPM

Daiwei Lu维护。



TapLabel 0.1.0

  • 作者:
  • Daiwei Lu

TapLabel

这是一个无耻的分支,由Krelborn/KILabel演变而来,用手动添加链接代替自动链接检测。

使用方法

使用TapLabel.LinkContentName将链接应用到富文本,并使用TapLabel.SelectedForegroudColorName来指定所选前景颜色。TapLabel不会应用任何其他自定义颜色到文本。您必须自己定义。

let text = NSMutableAttributedString(string: "something contains a link http://google.com")

text.addAttribute(TapLabel.LinkContentName,
    value: "test",
    range: NSMakeRange(26, 42))
text.addAttribute(NSForegroundColorAttributeName,
    value: UIColor.blueColor(),
    range: NSMakeRange(26, 42))
text.addAttribute(TapLabel.SelectedForegroudColorName,
    value: UIColor.redColor(),
    range: NSMakeRange(26, 42))

let label = TapLabel(frame: CGRect(x: 20, y: 40, width: 280, height: 100))
label.attributedText = text

TapLabelDelegate

必须分配label上的代理属性才能实现点击操作。

  • func tapLabel(tapLabel: TapLabel, didSelectLink link: String)

    当指定了TapLabel.LinkContentName的文本被点击时,将会被调用一次。其中link将等于TapLabel.LinkContentName的值。