从图像中可以看出,UILabel
的背景设置为黄色。在包装到下一行之前,属性文本不会使用所有空格("在"应该在第一行)。有什么办法解决吗?
标签的构造如下。它位于UICollectionView
标题内,并通过自动布局定位
let astring = NSMutableAttributedString(string: "You asked friends, and people at ")
astring.append(NSAttributedString(string:"Pittsburgh",
attributes: [.font: UIFont.boldSystemFont(ofSize: 15)]))
let label = UILabel()
label.attributedText = astring
答案 0 :(得分:1)
是的,奇怪的错误......
一个解决方法,虽然我没有对它进行任何测试,只是看到它适用于你的情况。
附加"无宽度空间"最后的角色:
let astring = NSMutableAttributedString(string: "You asked friends, and people at ")
astring.append(NSAttributedString(string:"Pittsburgh",
attributes: [.font: UIFont.boldSystemFont(ofSize: 15)]))
astring.append(NSAttributedString(string:"\u{200b}",
attributes: [.font: UIFont.systemFont(ofSize: 15)]))
结果:
答案 1 :(得分:0)
附加"" \ u {200b}" in Attributed String in End。希望它能起作用,