热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

UILabel在ios11中出现了错误的词包-UILabelwrongwordwrapiniOS11

IhaveproblemwithapplicationusingXIBswithoutautolayout.Idontknowifthisisimportantinf

I have problem with application using XIBs without autolayout. I don't know if this is important information.

我对使用XIBs而不使用autolayout有问题。我不知道这是不是重要的信息。

I have UILabel with 2 lines using word wrap. In iOS 10 word wrap was working correctly, and first line contained one word + special character, for example ampersand. Example:

我有UILabel和2行使用word wrap。在ios10中,换行是正确的,第一行包含一个单词+特殊字符,例如&符号。例子:

UiLabel on ios 10

Then on iOS 11 word wrap is working somehow wrong and puts ampresand to the second line:

然后在ios11中,换行有点问题,把ampresand放到了第二行:

UiLabel on ios 11

This is problematic as longer words, that normally fitted on second line now are not being shown correctly. Any idea what has changed? I know about safeArea but it doesn't look like reason. Any ideas how to move that ampersand to the top where is plenty of space for it?

这是有问题的,因为通常在第二行的较长的单词现在没有被正确显示。知道什么改变了吗?我知道有关安全的知识,但这似乎不是个理由。你知道怎么把这个&符号移到上面有足够的空间吗?

Rest of the settings: size inspector

其他设置:

5 个解决方案

#1


26  

This could very likely be an intentional change by Apple to prevent widowed lines. From a design perspective, it is preferred to avoid having a single word on a line of text. So it seems that UILabel now breaks the line in a way that a the second line of text always has at least 2 words on it.

这很可能是苹果公司为防止丧偶生产线而故意做出的改变。从设计的角度来看,最好避免在一行文本中出现一个单词。看来UILabel现在打破了这条线,因为第二行总是至少有两个词。

It is surprising that there is no documentation or way to disable this behavior though.

令人惊讶的是,没有文档或方法禁用这种行为。

enter image description here

Also here's a good article about "widowed"and "orphaned text.

这里还有一篇关于“寡妇”和“孤儿文本”的好文章。

#2


7  

This is not really an answer, but I want to add an illustration of how it is a general problem, not at all related to ampersands.

这并不是一个真正的答案,但我想要说明的是它是一个普遍的问题,而不是与ampersands相关的。

two UILabels

Both of these UILabels have identical width constraints, and the text is almost identical. But the second has the word wrap I would expect. The first is incorrect, the "about" can clearly stay on the first line.

这两个UILabels都有相同的宽度限制,而且文本几乎相同。但是第二个词是“wrap”这个词。第一个是不正确的,“about”可以明显地停留在第一行。

#3


3  

Launching the app with the arguments -NSAllowsDefaultLineBreakStrategy NO (an undocumented defaults setting) seems to force back to the old behavior. Alternatively, you can set NSAllowsDefaultLineBreakStrategy to NO in NSUserDefaults at startup (Apple registers a default of YES for that value when UILabel or the string drawing code is initialized, it appears, so you would need to register an overriding value after that, or insert it into the NSArgumentDomain, or just set the default persistently).

使用参数- nsallowsdefaultbreakstrategy NO(一个未文档化的默认设置)启动应用程序,似乎会迫使您回到旧的行为。另外,你可以设置在NSUserDefaults NSAllowsDefaultLineBreakStrategy没有启动(苹果注册是的的一个默认值UILabel或初始化字符串绘图代码时,它出现了,你需要注册一个压倒一切的价值之后,或将其插入到NSArgumentDomain,或者只是设置默认持续)。

Apple may consider that private API and reject apps that use it; I'm not sure. I have not tried this in a shipping app. However, it does work in quick testing -- saw the setting in NSUserDefaults and found changing it altered the behavior.

苹果可能会考虑这个私有API,拒绝使用它的应用;我不确定。我还没有在一个航运应用程序中尝试过这一点。但是,它确实可以在快速测试中使用——查看了NSUserDefaults中的设置,发现改变会改变它的行为。

#4


1  

It seems that replacing the space before the ampersand with a non-breaking space (U+00A0) keeps the ampersand on the same line. Depending on how you are generating the text for the label, this might not be easy to automate (maybe you really do need the ampersand to be on the second line in some cases).

似乎用一个不间断的空格(U+00A0)替换了与号之前的空格,使与号保持在同一条线上。根据如何为标签生成文本,这可能不容易自动化(在某些情况下,可能确实需要在第二行中使用&号)。

#5


0  

An option may be to use a UITextView instead -- that does not seem to have this behavior. If you set the NSTextContainer.lineFragmentPadding to 0, the textContainerInset to UIEdgeInsetsZero, and turn off all scrolling (scrollEnabled, bounces, scroll indicators, etc.) it will display similarly to a UILabel, though not with as much constraint flexibility. It's not a drop-in replacement, but in some situations it's acceptable.

一个选项可能是使用UITextView,而不是这种行为。如果您设置了NSTextContainer。行分割填充为0,textContainerInset设置为uiedgeinsets0,并关闭所有滚动(启用scrollEnabled、bounces、滚动指示器等),它将显示与UILabel类似的内容,但没有那么大的约束灵活性。这并不是替代,但在某些情况下是可以接受的。


推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • [论文笔记] Crowdsourcing Translation: Professional Quality from Non-Professionals (ACL, 2011)
    Time:4hoursTimespan:Apr15–May3,2012OmarZaidan,ChrisCallison-Burch:CrowdsourcingTra ... [详细]
  • Docker的安全基准
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 数据管理权威指南:《DAMA-DMBOK2 数据管理知识体系》
    本书提供了全面的数据管理职能、术语和最佳实践方法的标准行业解释,构建了数据管理的总体框架,为数据管理的发展奠定了坚实的理论基础。适合各类数据管理专业人士和相关领域的从业人员。 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • c# – UWP:BrightnessOverride StartOverride逻辑 ... [详细]
author-avatar
hareleemu_699
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有