原生iOS应用程序中的连字符 [英] Hyphenation in native iOS app

查看:142
本文介绍了原生iOS应用程序中的连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS中激活自动连字?

How can I activate automatic hyphenation in iOS?

我试图在UILabel的属性文本选项中将连字因子设置为1,但是我没有得到任何连字符。

I have tried to set the hyphenation factor to 1 in the attributed text options of an UILabel, however I don't get any hyphens though.

推荐答案


  1. iOS 7方式。使用 UITextView 而不是 UILabel hyphenationFactor (作为 NSParagraphStyle 属性或作为 NSLayoutManager 属性)应该工作(感谢新的TextKit)。

  2. Web方式。使用 UIWebView -webkit-hyphens CSS属性。

  3. 核心文本或艰难的方式。使用您在评论中提到的 CFStringGetHyphenationLocationBeforeIndex()函数。此函数仅为您提供有关在特定语言的字符串中将连字符放在何处的提示。然后你必须使用Core Text函数(比如 CTLineCreateWithAttributedString()和all)来破坏你的文本行。请参阅了解TextKit (称为Hyphenation的段落解释核心文本流程的逻辑,没有代码)和在iPad上使用核心文本连接 (给出一些代码示例,但网站现在似乎已经关闭了)。它可能比你想要的更多工作!

  1. The iOS 7 way. Use an UITextView instead of an UILabel. The hyphenationFactor (either as a NSParagraphStyle attribute or as a NSLayoutManager property) should work then (thanks to the new TextKit).
  2. The Web way. Use an UIWebView and the -webkit-hyphens CSS properties.
  3. The Core Text or the hard way. Use the CFStringGetHyphenationLocationBeforeIndex() function that you mentioned in a comment. This function only gives you a hint about where to put hyphens in a string for a specific language. Then you have to break your lines of text yourself using the Core Text functions (like CTLineCreateWithAttributedString() and all). See Getting to Know TextKit (the paragraph called Hyphenation explains the logic of the Core Text process, with no code) and Hyphenation with Core Text on the iPad (gives some code sample, but the website seems to be down right now). It's probably going to be more work than you want!

这篇关于原生iOS应用程序中的连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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