- Base on UITextView.
- A replacement of UILabel, but more.
- Support for
Mentions
,Links
,Phone Numbers
,Addresses
,Emoticons(images)
- Support custom
Regex
links - Support setting link color
- Support detections of
Sinle-Tap on links
,Single-Tap on Whole Text
,Long-Press on links
- Support automatic table view cell height calculation (autolayout)
var label = DZLabel()
label.dzFont = UIFont.systemFont(ofSize: 14)
label.dzTextColor = UIColor.blue
label.dzLinkColor = UIColor.red
label.dzText = "test" // do not use .attributedText or .text
label.dzEnabledTypes = [
.address,
.phone,
.mention,
.url,
.emoticon(pattern: nil, // By default: "[EmoticonName]"
bounds: CGRect(x: 0, y: -2, width: 10, height: 10), // Position and Size
imageNameBlock: ({ name in // Text -> Local Image Name
var imageName = name
if imageName.hasPrefix("[") { imageName.removeFirst() }
if imageName.hasSuffix("]") { imageName.removeLast() }
return imageName})),
.regex(pattern: "AM|PM"),
]
label.dzHandleMentionTap { result in
print("mention tapped" + result)
}
label.dzHandleURLTap { result in
print("url tapped" + result)
}
label.dzHandlePhoneTap { result in
print("phone tapped" + result)
}
label.dzHandleAddressTap { result in
print("address tapped" + result)
}
label.dzHandleKeywordLongPress {
print("keyword long pressed")
}
label.dzHandleRegexKeywordTap { result in
print("custom regex tapped" + result)
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 8+
- Swift 4
DZLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'DZLabel'
Darren Zheng, 623767307@qq.com
DZLabel is available under the MIT license. See the LICENSE file for more info.