2014-01-14 52 views
1

我正在使用UITextView並在我的代碼中分配一些文本,但由於某種原因,它總是在5-6行之後開始。 UITextViewAttributedTextView或允許屬性字符串。將UITextView文本設置爲UITextView的開始

enter image description here

self.bodyTextView.selectedRange = NSMakeRange(0, 0); 
self.bodyTextView.font = [UIFont fontWithName:@"Cochin" size:17]; 
self.bodyTextView.text = @"This is written by Joe. This is written by Moo. This is written by Qoo"; 
+0

嘗試將UITextView的'automaticallyAdjustsScrollViewInsets'設置爲NO。看看有沒有做任何事情。 – Putz1103

+0

UITextView控件上沒有這樣的屬性。 –

+0

井漏。我從http://stackoverflow.com/a/19468461/1671729得到了答案。仔細觀察一下,看它是否會回答你。 – Putz1103

回答

2

引述this answer:

A text view is a scroll view. iOS 7 will add a content offset automatically to scroll views, as it assumes they will want to scroll up behind the nav bar and title bar.

To prevent this, override the new method on UIViewController, automaticallyAdjustsScrollViewInsets, and return NO.

它與導航欄重疊UIViewController的視圖的框架協議。當它設置爲no時,UIViewController不會調整任何內容以避開頂部導航欄。

而不是子類和重載,你可以將屬性設置爲no。

(UIViewController).automaticallyAdjustsScrollViewInsets = NO;