0

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

这就是它现在的样子:

在此处输入图像描述

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

4

1 回答 1

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
于 2016-04-27T10:10:55.523 回答