UILabel换行在iOS 11上为时过早 [英] UILabel line breaks too early on iOS 11

查看:96
本文介绍了UILabel换行在iOS 11上为时过早的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有单元格表格的iOS 11应用程序.

I have an iOS 11 app with a table with cells.

在此单元格中,我有一个UILabel.

In this cells, I have a UILabel.

UILabel似乎决定"以使底行至少包含2个字的方式来断行(无论BreakLineMode是什么!).

The UILabel seems to "decide" to break the line in a way that keeps the bottom line with at least 2 words (no matter what the BreakLineMode is!).

我知道使用-添加不间断空格(U + 00A0)-过于昂贵

I know about using - Adding non-breaking space (U+00A0) - TOO EXPENSIVE

在NSUserDefaults上使用NSAllowsDefaultLineBreakStrategy NO-不允许苹果使用

Using NSAllowsDefaultLineBreakStrategy NO on NSUserDefaults - NOT ALLOWED BY APPLE

我该怎么做才能解决此问题?

What can I do to fix this problem?

在此图像中,您可以看到第二行中的第一个单词可能出现在第一行中,但由于某种原因而下降到第二行...

In this image, you can see that the first word in the second line, could appear on the first line but got down to the second for some reason...

这不是宽度问题,这是iOS 11 NEW UILabel逻辑(!)的问题,该逻辑不允许换行上的孤立词(一个词),因为他们认为更好,所以只能输入两个词.没有.但是必须有一种方法可以使UILabel在iOS 11上起作用,就像在iOS 10及更低版本上一样.

This is NOT a width issue, this is an issue with iOS 11 NEW UILabel logic(!) that doesn't allow orphans words (one word) on a new line, Only two word because they think it looks better. It doesn't. But there must be a way to make a UILabel act on iOS 11 like it did on iOS 10 and under.

推荐答案

我发现了黑客-

在字符串的末尾添加很多空格(例如10-20)将使UILabel认为"该行足够长,因此将在底行留下一个单词.(而不是2,因此第一行不会提前中断)

Adding a lot of spaces (like 10 - 20) to the end of the string will make the UILabel "think" that the line is long enough so it will leave one word on the bottom line. (instead of 2 so the first line will not break early)

我不喜欢黑客,但这是我目前所拥有的,如果有人有不同的答案,我会很乐意接受它而不是这个答案

I don't like hacks but this is all I've got at the moment, if anybody has a different answer i will gladly accept it instead of this one

这篇关于UILabel换行在iOS 11上为时过早的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆