我正在创建一个应用程序,我想在Teach.text中添加一个新行
func RandomQuestions(){
var RandomNumber = arc4random() % 1
RandomNumber += 1
switch(RandomNumber){
case 1:
QuestionLbl.hidden = false
QuestionLbl.text = "2x + 4 = 14"
Button1.setTitle("x = 5", forState: UIControlState.Normal)
Button2.setTitle("x = 4", forState: UIControlState.Normal)
Button3.setTitle("x = 9", forState: UIControlState.Normal)
Button4.setTitle("y = 5", forState: UIControlState.Normal)
Teach.text = "2x + 4 = 14"
CorrectAnswer = "1"
break
default:
break
}
}
换句话说,我需要添加另一行,所以当我测试我的应用时,'教'应该说
2x + 4 = 14
2x = 10
答案 0 :(得分:11)
如果是UILabel,请将 numberOfLines 字段设为0
Teach.numberOfLines = 0
Teach.text = "Line1\nLine2"
并确保它足够高以显示两条线。
答案 1 :(得分:2)
只需添加以下代码
即可textLabel.lineBreakMode = .ByWordWrapping
textLabel.numberOfLines = 0 // 0 = unlimited lines, you can also set the in your storyboard
希望有所帮助