第一次尝试使用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
关于ios - 获取 TTTAttributedLabel 以粗体打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36885974/