我有一个UILabel,它在垂直线上显示一个数字数组;然而,它将两个或更多个数字分成不同的数字。我该如何解决这个问题?
syllableArr = ["6", "5", "5", "11"]
func updateSyllableLabel() {
//Updates content of syllable label
let multiLineString = self.syllableArr.joined(separator: "\n")
syllableLabel.text = multiLineString
syllableLabel.numberOfLines = 0
syllableLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
syllableLabel.sizeToFit()
}
非常感谢任何帮助。
提前致谢。
答案 0 :(得分:0)
设置标签宽度,高度和设置行数
let syllableArr = ["6", "5", "5", "11"]
let multiLineString = syllableArr.joined(separator: "\n")
let syllableLabe = UILabel(frame: CGRect(x: 10, y: 20, width: 10, height: 80)) x,y width and height set according you
syllableLabe.text = multiLineString
syllableLabe.numberOfLines = 4
syllableLabe.lineBreakMode = NSLineBreakMode.byWordWrapping
print(“label text ===%@",syllableLabe.text!)
Out Put是
label text ===%@6
5
5
11
if you want to break 11
let str: String = syllableArr[3]
str = ""11"
let digits = String(str).characters.map { Int(String($0))! }
print("digits is ---%@",digits) and create new array as this
let newsyllableArr = ["6", "5", "5", "1","1"] and use same logic above