Label line break not working properly in xcode

浪子不回头ぞ 提交于 2020-06-29 03:59:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!