Hyphenation in native iOS app

前端 未结 3 1603
广开言路
广开言路 2020-12-25 08:40

How can I activate automatic hyphenation in iOS?

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

3条回答
  •  太阳男子
    2020-12-25 09:06

    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!

提交回复
热议问题