【问题标题】:Swift - How to create line breaks in an array (Displayed in a UILabel)Swift - 如何在数组中创建换行符(在 UILabel 中显示)
【发布时间】:2015-07-24 21:22:14
【问题描述】:

我正在尝试创建一个显示随机著名历史名言的应用程序。我使用 UIlabel 随机显示数组中的引号。 但是对于长引号,它们看起来像这样:

http://i.stack.imgur.com/5j7at.png

代码如下:

var quoteArray: [String] = [ "We are not makers of history, we are made by history - Martin Luther King Jr", "Without education you're not going anywhere in this world - Malcolm X"]

所以我从这个数组中随机选择,但我找不到在不破坏代码的情况下创建换行符的方法(因此可以看到整个引号)。 知道怎么做吗?

我应该从 UILabel 更改为其他东西吗? 或者有没有办法添加换行符

非常感谢

【问题讨论】:

    标签: ios arrays xcode swift


    【解决方案1】:

    将标签的行数设置为0,将换行符设置为“自动换行”。

    【讨论】:

    • 天才。非常感谢。
    【解决方案2】:

    要换行,请输入"\r\n",所以在你的情况下,我建议说:

    var quoteArray: [String] = ["We are not makers of history, we are made by history - Martin Luther King Jr", "\r\n", "Without education you're not going anywhere in this world - Malcolm X"]

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多