简体   繁体   English

Swift - 如何在数组中创建换行符(显示在UILabel中)

[英]Swift - How to create line breaks in an array (Displayed in a UILabel)

I'm trying to create an app that displays random famous historical quotes. 我正在尝试创建一个显示随机着名历史报价的应用程序。 I use a UIlabel to display quotes from an array randomly. 我使用UIlabel随机显示数组中的引号。 However with long quotes, they look like this: 但是对于长引号,它们看起来像这样:

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

Here's the code: 这是代码:

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"]

So i select randomly from this array, but i can't find a way to create line breaks (so the whole quote can be seen) without disrupting the code. 所以我从这个数组中随机选择,但我找不到创建换行符的方法(所以可以看到整个引用)而不会中断代码。 Any idea how to do it? 知道怎么做吗?

Should i change from a UILabel to something else? 我应该从UILabel改为其他吗? or is there a way to add line breaks 或者有没有办法添加换行符

Thanks a lot 非常感谢

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

要进行换行,请键入"\\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"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM