第一次尝试使用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


这就是现在的样子:

ios - 获取一个TTTAttributedLabel以粗体显示-LMLPHP

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

最佳答案

能够通过以下方式做我想做的事情:

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

10-07 18:14