2015-11-25 71 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 

希望幫助