swift - 自定义 UITableViewCell : UITextView being reset after adding attributes

标签 swift uitextfield uitableview

我正在处理通知 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/

相关文章:

ios - 如何在每次在自定义单元格中选择复选标记时更改按钮标题

ios - 我如何使用解析保存的数据来计算关注者的数量,如下所示:

class - swift 类 : reference cycle

ios - 输入新行时 UITextView 的偏移量错误

ios - 如何在 UITextField 和 UISearchBar 中禁用长按手势识别器?

iPhone:显示键盘且方向更改时定位多个 UITextField

ios - 分段控制 TableView 的自定义编辑按钮

ios - 如何通过从 Swift 中的 UIScrollView 继承它来制作垂直的 UITextView?

iphone - 当键盘显示时向上移动 UIView

ios - 防止为 STTweetLabel 调用 didSelectRowAtIndexPath