标签换行符在 xcode 中无法正常工作 [英] Label line break not working properly in xcode

查看:23
本文介绍了标签换行符在 xcode 中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,显示屏幕上的粉红色区域. 但是,即使有足够的空间,性别"一词也不会显示在顶行.为什么它没有出现在第一行本身?我需要什么

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";

标签

推荐答案

UILabel 通过防止 孤立词,因此更具可读性.这是在 iOS 11 中引入的.Apple 必须为 iMessage 禁用它,因为他们可能打算将这种行为用于长文章,而不是短信.

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

  • 在设置文本后在标签上调用 sizeToFit
  • setting UserDefaults.standard.set(false, forKey: "NSAllowsDefaultLineBreakStrategy")//使用这个私密的棘手快捷方式可能会导致应用商店被拒绝.

但这些都不适用于 iOS 13 模拟器(未在设备上测试).

But none of these are working on iOS 13, simulator (Not tested on devices).

修复

一个棘手的解决方案是 - 在文本中附加一些空格或两个制表符("\t\t")并以编程方式设置.

One tricky solution is - append some spaces or two tabs("\t\t") to the text and set programatically.

这篇关于标签换行符在 xcode 中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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