我正在处理通知 View ,我希望用户名是粗体,而消息的其余部分不是粗体。目前,用户名变为粗体,但在此过程之后,其余文本变得非常小,我无法弄清楚为什么。
let fromUser:PFUser = friendRequests.objectAtIndex(indexPath.row).objectForKey("from") as! PFUser
cell.notificationMessage.text = fromUser.objectForKey("Name") as! String + " has sent you a friend request."
let boldText: NSMutableAttributedString = NSMutableAttributedString(string: cell.notificationMessage.text)
let stringCount = fromUser.objectForKey("Name") as? String
boldText.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(14)], range: NSRange(location: 0, length: (stringCount?.characters.count)!))
cell.notificationMessage.attributedText = boldText
最佳答案
你是说长度字符串计数吗?这是用户名的长度而不是整个文本,尝试更改长度,它应该可以工作
希望对你有帮助
关于swift - 自定义 UITableViewCell : UITextView being reset after adding attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34607176/