2016-02-08 105 views
1

有什么办法打印出字符串到的UILabel数组没有任何特殊字符,如[“数字1”,“数字2”,“number3的”]打印字符串数组UILabels

我希望它看起来像这样在我的UILabel输出:

 
number1 
number2 
number3 

这里是我的代码:

let addInputs = quantityField.text! + "x " + descriptionField.text! 
var listArray: [String] = [] 
listArray.append("\(addInputs)") 

for addInputs in listArray { 
      //itemListLabel.text = "\n\(addInputs)" 
      print("\(addInputs)") 
      itemListLabel.text = "\(listArray)" 
     } 

回答

2

您可以\n加盟项目一起添加硬回车:

itemListLabel.text = listArray.joinWithSeparator("\n") 
+0

谢谢!这是我需要的工作! – the1

0

你需要做两件事情:

itemListLabel.numberOfLines = listArray.count 
itemListLabel.text = listArray.joinWithSeparator("\n") 

第一行设置线在标签中显示的数字。如果你事先知道你想要什么,你可以在Interface Builder中设置它。第二行将字符串数组与每行之间的换行符分隔开来。