热门标签 | 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类似的内容,但没有那么大的约束灵活性。这并不是替代,但在某些情况下是可以接受的。


推荐阅读
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • [转载]从零开始学习OpenGL ES之四 – 光效
    继续我们的iPhoneOpenGLES之旅,我们将讨论光效。目前,我们没有加入任何光效。幸运的是,OpenGL在没有设置光效的情况下仍然可 ... [详细]
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • IpreparediOSappincordova,IusedoriginalCordovaPluginforLocalNotifications.Imschedulin ... [详细]
  • ImusingURLSessiontoperformadatatask,whenIrunitoniOS11,Igetaconsoleerror:我使用URLSe ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • macOS Big Sur全新设计大版本更新,10+个值得关注的新功能
    本文介绍了Apple发布的新一代操作系统macOS Big Sur,该系统采用全新的界面设计,包括图标、应用界面、程序坞和菜单栏等方面的变化。新系统还增加了通知中心、桌面小组件、强化的Safari浏览器以及隐私保护等多项功能。文章指出,macOS Big Sur的设计与iPadOS越来越接近,结合了去年iPadOS对鼠标的完善等功能。 ... [详细]
  • Summarize function is doing alignment without timezone ?
    Hi.Imtryingtogetsummarizefrom00:00otfirstdayofthismonthametric, ... [详细]
  • 我收到这个错误.我怎么能在我的情况下解决这个问题?Bitmapcannotberesolvedtoatype发生错误的行publicvoidonPageStart ... [详细]
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社区 版权所有