在IOS正交断字的字(Orthographic hyphenation word in IOS)

2019-09-02 15:49发布

有正字连字符单词的方法是什么?

事情是这样的:

NSStiring *string = @"In June 2010 at the World Wide Developers Conference, Apple announced version 4 of Xcode during the Developer Tools State of the Union address.";
UILabel *label = [[UILabel alloc] init];
label.text = string;

如果框架的UILabel会窄,取得下:

在2010年6月
万维网
开发商CON-
扰,苹果
宣布版本 -
的Xcode 4锡永
在德弗尔期间
OPER国家的工具
联盟AD-的
连衣裙。

Answer 1:

使用与NSParagraphStyle的NSAttributedString与hyphenationFactor 1。



Answer 2:

Objective-C的

NSString *string = @"In June 2010 at the World Wide Developers Conference, Apple announced version 4 of Xcode during the Developer Tools State of the Union address.";
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.hyphenationFactor = 1.0;
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:string];
UILabel *label = [[UILabel alloc] init];
label.attributedText = attributedString;

斯威夫特4

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.hyphenationFactor = 1.0
let attributedString = NSMutableAttributedString(string: "Your String", attributes: [NSAttributedStringKey.paragraphStyle:paragraphStyle])
self.yourLabel.attributedText = attributedString

斯威夫特3

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.hyphenationFactor = 1.0
let attributedString = NSMutableAttributedString(string: "Your String", attributes: [NSParagraphStyleAttributeName:paragraphStyle])
self.yourLabel.attributedText = attributedString


Answer 3:

这将帮助你。 请更改的UILabel文本平原归因我试过的Xcode 7+



文章来源: Orthographic hyphenation word in IOS