获取 TTTAttributedLabel 打印粗体
Getting a TTTAttributedLabel to print bold
第一次尝试使用 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
这是现在的样子:
但是我不想要蓝色和带下划线的字体,我只想获得黑色和粗体字体。我该怎么做呢?
能够通过以下方式做我想做的事:
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
第一次尝试使用 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
这是现在的样子:
但是我不想要蓝色和带下划线的字体,我只想获得黑色和粗体字体。我该怎么做呢?
能够通过以下方式做我想做的事:
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