获取TTTAttributedLabel以打印粗体

时间:2016-04-27 09:39:45

标签: ios swift tttattributedlabel

第一次尝试使用TTTAttributedLabel框架。我想用它来制作我的UILabel的一部分用粗体打印而另一部分打印出来的光字体:

let messageLabelString = "\(notificationSenderName) would like to rent your \(notificationItem). Approve?"
cell.messageLabel.text = messageLabelString
let nsString = messageLabelString as NSString
let range = nsString.rangeOfString(notificationSenderName)
let url = NSURL(string: "test")
cell.messageLabel.addLinkToURL(url, withRange: range)
cell.messageLabel.delegate = self

这就是它现在的样子:

enter image description here

但是我不想要蓝色和带下划线的字体,我只想获得黑色和粗体字体。我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

能够做我想做的事情:

let messageLabelString = "\(notificationSenderName) would like to rent your \(notificationItem). Approve?"
            cell.messageLabel.text = messageLabelString
            let nsString = messageLabelString as NSString
            let range = nsString.rangeOfString(notificationSenderName)
            let url = NSURL(string: "test")

            let subscriptionNoticeLinkAttributes = [
                NSFontAttributeName: UIFont(name:"JohnstonITCPro-Bold", size:15)!
                ]

            cell.messageLabel.linkAttributes = subscriptionNoticeLinkAttributes
            cell.messageLabel.addLinkToURL(url, withRange: range)
            cell.messageLabel.delegate = self