如何添加 - 在ios swift 3的标签中

时间:2017-03-03 13:18:40

标签: ios swift xcode uilabel

我有一个多行标签,当标签转到我希望得到的新行时 - 在行尾。我是以编程方式进行的。怎么实现呢? 我已经尝试了这个,但它不起作用

phrase[phrase.length]

在这种情况下,标签变为多行,但是 - 不会在行尾添加。 提前谢谢。

2 个答案:

答案 0 :(得分:3)

如果您正在询问如何获取带连字符的文本,请参阅:

This is a hyphen-
ated word wrap.

看看这里:add hyphens on word break in a UILabel

答案 1 :(得分:-2)

以上代码工作正常尝试此代码只是增加标签的高度,宽度也增加。

enter image description here

 @IBOutlet var labelText: UILabel!
   override func viewDidLoad() {
    super.viewDidLoad()

    labelText.text = "if you know C or Objective-C then you might be familiar with Enums and Structs.However,if you don’t know either of those languages then you are probably"
    labelText.lineBreakMode = .byWordWrapping
    labelText.numberOfLines = 0
}