Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UILabel属性文本不';在开始新生产线之前,不要填充整个生产线_Ios_Uilabel_Swift4_Nsattributedstring - Fatal编程技术网

Ios UILabel属性文本不';在开始新生产线之前,不要填充整个生产线

Ios UILabel属性文本不';在开始新生产线之前,不要填充整个生产线,ios,uilabel,swift4,nsattributedstring,Ios,Uilabel,Swift4,Nsattributedstring,如图所示,ui标签的背景设置为黄色。属性化文本在换行到下一行之前不会使用所有空格(“at”应在第一行)。有办法解决吗 标签的构造如下所示。它位于UICollectionView标题中,并通过自动布局定位 let astring = NSMutableAttributedString(string: "You asked friends, and people at ") astring.append(NSAttributedString(string:"Pittsburgh", at

如图所示,
ui标签的背景设置为黄色。属性化文本在换行到下一行之前不会使用所有空格(“at”应在第一行)。有办法解决吗

标签的构造如下所示。它位于
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
是的,奇怪的虫子

一个解决办法,虽然我没有做任何测试,除了看看它在您的情况下工作

在末尾附加一个“无宽度空格”字符:

    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)]))
结果:


附加“\u{200b}”“在结尾的属性字符串中。希望它能起作用,

根据下面的链接,这似乎是iOS 11中的一个bug-我在iOS 9和iOS 11上进行了测试。它在iOS 9中运行良好。我没有iOS10模拟器,但是,根据上面的链接注释,它也可以在iOS10中工作。它在iOS 11上不起作用。坦率地说,我没有任何解决这个问题的办法。有趣的是,它是有效的。不知道为什么。但是非常感谢你!