到合適的按鈕我都試過,但沒有奏效,文字離開按鈕的邊界。自動更改字體大小在迅速
button.titleLabel!.adjustsFontSizeToFitWidth = true
button.titleLabel!.numberOfLines = 0
button.titleLabel!.minimumScaleFactor = 0.1
當我嘗試以下方法,所有的文本適合,但文本保持在一個小字體:
button.titleLabel!.font = UIFont(name: "Heiti TC", size: 9)
我怎樣才能獲得字體自動適應按鈕的尺寸?
func nextQuestion() {
let currentQuestion = mcArray![questionIdx]
answers = currentQuestion["Answers"] as! [String]
correctAnswer = currentQuestion["CorrectAnswer"] as? String
question = currentQuestion["Question"] as? String
titlesForButtons()
}
func titlesForButtons() {
for (idx,button) in answerButtons.enumerate() {
button.titleLabel!.lineBreakMode = .ByWordWrapping
button.titleLabel!.font = UIFont(name: "Heiti TC", size: 5)
button.titleLabel!.numberOfLines = 0
button.titleLabel!.minimumScaleFactor = 0.1
button.titleLabel!.baselineAdjustment = .AlignCenters
button.titleLabel!.textAlignment = NSTextAlignment.Center
button.setTitle(answers[idx], forState: .Normal)
button.enabled = true
button.backgroundColor = UIColor(red: 83.0/255.0, green: 184.0/255.0, blue: 224.0/255.0, alpha: 1.0)
}
questionLabel.text = question
startTimer()
}
這是我迄今它從一個plist文件的答案
'adjustsFontSizeToFitWidth = TRUE'爲我工作。 – keithbhunter
它沒有工作文本是相同的大小,並走出了按鈕界限 – acekidd