Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将UILabel文本分隔为三个不同的UILabel_Ios_Swift - Fatal编程技术网

Ios 将UILabel文本分隔为三个不同的UILabel

Ios 将UILabel文本分隔为三个不同的UILabel,ios,swift,Ios,Swift,我不确定标题是否符合我的要求,但我有一个标签,上面有一堆句子,我想把它们分别放在不同的UILabel 这是我的密码 var s: [String] = [] for (i, pred) in results.enumerated() { let latLongArr = pred.0.components(separatedBy: "\t") myLatitude = latLongArr[1] myLongitude = latLongArr[2]

我不确定标题是否符合我的要求,但我有一个
标签
,上面有一堆句子,我想把它们分别放在不同的
UILabel

这是我的密码

   var s: [String] = []
   for (i, pred) in results.enumerated() {
    let latLongArr = pred.0.components(separatedBy: "\t")
    myLatitude = latLongArr[1]
    myLongitude = latLongArr[2]
    s.append(String(format: "%d: %@ %@ (%3.2f%%)", i + 1, myLatitude, myLongitude, pred.1 * 100))
    places[i].title = String(i+1)
    places[i].coordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(myLatitude)!, longitude: CLLocationDegrees(myLongitude)!)
}
predictionLabel.text = s.joined(separator: "\n") // one label
UILabel文本看起来像这样

Prediction 1: latitude longitude // first sentence
(probability%)
Prediction 2: latitude longitude // second
(probability%)
Prediction 3: latitude longitude // third
(probability%)
多谢各位

编辑 我已经创建了三个标签并尝试了这段代码,不幸的是它给出了第一个结果

    self.predict1.text = s.joined(separator: "\n")
    self.predict2.text = s.joined(separator: "\n")
    self.predict3.text = s.joined(separator: "\n")
您可以将标签上的设置为0和。或者创建一个垂直statckview,为每个字符串实例化一个标签,然后将标签添加到stackview的视图中

编辑 现在我看一下您的代码,真正的问题是行让latLongArr=pred.0.components(由“\t”)分隔。最有可能的情况是,数据中有尾随的换行符,您需要删除经度之后的尾随换行符

   var s: [String] = []
   for (i, pred) in results.enumerated() {
    let latLongArr = pred.0.components(separatedBy: "\t").replacingOccurrences(of: "\n", with: "")
    myLatitude = latLongArr[1]
    myLongitude = latLongArr[2]
    s.append(String(format: "%d: %@ %@ (%3.2f%%)", i + 1, myLatitude, myLongitude, pred.1 * 100))
    places[i].title = String(i+1)
    places[i].coordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(myLatitude)!, longitude: CLLocationDegrees(myLongitude)!)
}

为每个字符串实例化一个标签
我是swift的新手,你能告诉我关于这个的更多信息吗