ios - 获取 TTTAttributedLabel 以粗体打印

标签 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

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

最佳答案

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

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/

相关文章:

ios - 如何使用 avfoundation 合并视频剪辑?

ios - TTTAttributedLabel 截断文本问题

ios - 如何在 Swift iOS 中同时使用 UITableView 和 NSLink?

objective-c - 预期的说明符限定符列表 - 为什么?

ios - 在App Store Connect上不可用的在App Store上查看选项

ios - 如何测试 UIControlEvents 是否已被触发

ios - 如何找到手机屏幕距离眼睛直线的距离

ios - Swift 将 UITextView 文本保存到 .Pdf、.Doc 和 .Txt 文件格式并显示

ios - 关闭 UISearchController 时 UINavigationBar 覆盖 UITableView

ios - TTTAttributedLabel 添加操作以截断 ("Read more"文本)