2015-11-25 35 views
1

我提出一个应用程序添加一个新行,我想添加一个新行,在Teach.text如何在迅速label.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

是一个UILabel? – Peyman

回答

6

如果它是一个UILabel,设置numberOfLines场0

Teach.numberOfLines = 0 
Teach.text = "Line1\nLine2" 

并确保它的高度足以显示两条线。

+0

谢谢,它工作! – Hacker4Lifes

+0

如果它回答你的问题,请不要忘记接受它。 – Peyman

+0

这是用于swift 2.X版本吗?它不适用于Swift 3.0?你能建议我要添加什么吗? –

2

只需添加以下代码

textLabel.lineBreakMode = .ByWordWrapping 
textLabel.numberOfLines = 0 // 0 = unlimited lines, you can also set the in your storyboard 

希望帮助