问题
I have a label which shows the pink area on the screen. However, the word "gender " is not shown in the top line even if it has enough space. Why is it not showing up in the first line itself? What I need
label.text = @"Do you believe in gender equality";
Label
回答1:
The UILabel
is working as intended by preventing an orphaned word so it’s more readable. This was introduced in iOS 11. Apple must disable it for iMessage because they probably intend this behaviour for long articles of text, not text messages.
I've seen fixes including
- call
sizeToFit
on the label after the text has been set - setting
UserDefaults.standard.set(false, forKey: "NSAllowsDefaultLineBreakStrategy") // Using this private tricky shortcut may leads appstore rejection.
But none of these are working on iOS 13, simulator (Not tested on devices).
Fix
One tricky solution is - append some spaces or two tabs("\t\t"
) to the text and set programatically.
来源:https://stackoverflow.com/questions/62443434/label-line-break-not-working-properly-in-xcode