將文本以編程方式添加到UILabel。隨着更多文本的添加,文本將包裝並增加標籤的高度。添加文本後UILabel反彈
的問題是,當文本換行在一行的末尾,整個標籤會跳起來1線的高度和動畫本身回落到它的正確位置。最終的結果很好,但你如何擺脫奇怪的跳躍動畫。同樣,每當UILabel的高度因另一行換行而增加時,就會發生這種情況。
示例代碼:
var eventCount = 0;
func someEvent(sender:AnyObject){
eventCount += 1;
if(eventCount == 1){
lbl.text = "this"
}else if(eventCount == 2){
lbl.text = "this is some"
}else if(eventCount == 3){
lbl.text = "this is some sample text"
}else if(eventCount == 4){
// this is where text wraps to line 2
// the label jumps up 20px or so and
// animates back down to it's original position
lbl.text = "this is some sample text that causes the label to wrap"
}
}
自動版式約束
0
|
0 - UILabel - 0
標籤屬性
lines = 0
郵政編碼請 – Jatin 2014-10-30 20:57:08
增加示例代碼;謝謝參觀! – bgolson 2014-10-30 21:13:59
當你添加文本時你是否嘗試過'[self.view layoutIfNeeded]'? – 2014-10-30 21:25:28