2014-03-01 35 views
0

我有一個textview,我希望能夠滾動它並閱讀文本,但截至目前我無法滾動。我也啓用了用戶交互,這是我的第一個問題。我的第二個問題是文本偏離中心。如果您有任何建議,他們將不勝感激。UITextView偏離中心而不滾動

iPhone模擬器: http://gyazo.com/150b994584a2e7dc42f96b0f4d889587

我的代碼:除非文本內容超出了框架

_tv = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 320, 568)]; 
_tv.text = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."; 
_tv.userInteractionEnabled = YES; 
_tv.editable = NO; 
_tv.scrollEnabled = TRUE; 
[self.view addSubview:_tv]; 

回答

0

UITextView不會滾動。在這種情況下,我可以看到你的框架是568,因此除非文本超過這個高度,否則你不會有可滾動的文本。其次,您的文字偏離中心位置,因爲您可能沒有使用頂層佈局的contentInset。您需要設置contentInset,或者完全向下移動文本視圖。

順便說一句,它是一個好主意,一貫使用YES/NO布爾值,而不是滑倒TRUE。像這樣的不一致可能會導致很難發現錯誤。