2010-10-11 104 views
0

我有一行文字太長,無法顯示在UILabel的單行中,所以我切換到UITextView。我想要將文本仍然顯示在一行中,並且能夠水平滾動,但UITextView會將文本包裝成多行,並允許我垂直滾動。因此,對於文本「這是一條非常長的路線」,而不是像「This is a」那樣顯示它,然後如果水平滾動,它會顯示剩餘的部分,它實際上顯示爲「This is a \非常長\ n行「。我怎樣才能得到我想要的行爲?UITextView只能水平滾動

感謝, 米哈伊

回答

3

如果你想要的行爲,你應該把一個滾動視圖內側的標籤。這是您能夠以任何方向滾動標籤的唯一方法。

+0

感謝您的答覆! – 2010-10-11 20:21:54

0

使用梅里馬克的意見,這個工作對我來說:

self.dishNameLabel.text = @"Here is some very longgggg text to test with"; 
float width = ceil([self.dishNameLabel.text sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"WorkSans-SemiBold" size:15.0]}].width); 
self.dishNameLabel.frame = CGRectMake(self.dishNameLabel.frame.origin.x, self.dishNameLabel.frame.origin.y, width, self.dishNameLabel.frame.size.height); 
self.dishNameScrollView.contentSize = CGSizeMake(width, self.dishNameScrollView.frame.size.height); 

當然,你會與你相應的規範,以取代文本和字體