Swift 2 Solution:
Specifically, need to set activeLinkAttributes
, see below example:
private func subscriptionNoticeWithDelegate(delegate:TTTAttributedLabelDelegate) -> TTTAttributedLabel {
let subscriptionNotice:String = "To turn on all notifications, subscribe to our monthly " +
"service ($0.99/month). If you have already subscribed, please restore your purchase."
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 1.2
let subscriptionNoticeAttributedString = NSAttributedString(string:subscriptionNotice, attributes: [
NSFontAttributeName: UIFont(name:"HelveticaNeue-Light", size:15)!,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: UIColor.grayColor().CGColor,
])
let subscriptionNoticeLinkAttributes = [
NSForegroundColorAttributeName: UIColor.grayColor(),
NSUnderlineStyleAttributeName: NSNumber(bool:true),
]
let subscriptionNoticeActiveLinkAttributes = [
NSForegroundColorAttributeName: UIColor.grayColor().colorWithAlphaComponent(0.80),
NSUnderlineStyleAttributeName: NSNumber(bool:true),
]
let subscriptionNoticeLabel:TTTAttributedLabel = TTTAttributedLabel(frame:CGRectZero)
subscriptionNoticeLabel.delegate = delegate
subscriptionNoticeLabel.numberOfLines = 0
subscriptionNoticeLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
subscriptionNoticeLabel.textInsets = UIEdgeInsets(top:10, left:15, bottom:0, right:15)
subscriptionNoticeLabel.setText(subscriptionNoticeAttributedString)
subscriptionNoticeLabel.linkAttributes = subscriptionNoticeLinkAttributes
subscriptionNoticeLabel.activeLinkAttributes = subscriptionNoticeActiveLinkAttributes
let subscribeLinkRange = (subscriptionNotice as NSString).rangeOfString("subscribe")
let subscribeURL = NSURL(string:kSubscriptionNoticeSubscribeURL)!
subscriptionNoticeLabel.addLinkToURL(subscribeURL, withRange:subscribeLinkRange)
let restoreLinkRange = (subscriptionNotice as NSString).rangeOfString("restore")
let restoreURL = NSURL(string:kSubscriptionNoticeRestoreURL)!
subscriptionNoticeLabel.addLinkToURL(restoreURL, withRange:restoreLinkRange)
return subscriptionNoticeLabel
}