[英]Scroll the text in UITextview when texts are less and height of UITextview is large
我有一個UITextView
其高度為568(表示適合屏幕尺寸),如果我在其中寫50行,那么它肯定會垂直滾動。
但是,當只有一行文本時,我想滾動(或只是彈跳)。
當用戶垂直滾動時, 文本將在UITextView中反彈 。
在我的應用程序中, UITextView
是不可編輯的。
任何想法,代碼,鏈接都會有很大的幫助...
編輯:
UITextView的高度僅為568。
它不會更改(意味着不更改UITextView的高度,請設置此內容)。
[txtView setContentOffset:CGPointMake(0, 1000)];
它也不起作用...
設置UITextView的框架
CGRect frame = textView.frame;
frame.size = textView.contentSize;
textView.frame = frame;
請參閱: UITextView更改高度而不是滾動
如果要滾動不大的TextView
文本,則為height。 那你就做不到 如果textView's
Text不大於其框架高度,則不會獲得滾動條。
設置[txtView setContentOffset:CGPointMake(0, 1000)];
如果該數據的停留時間不超過textView的高度,它將不再起作用。
更新: -
這是我的把戲。 如果textview是不可編輯的,而您只想滾動,請嘗試將Textview添加到一個scrollviw中。 像貝婁一樣,我也能做到。
在.h類中
@property(nonatomic,retain)IBOutlet UITextView *textvie;
@property(nonatomic,retain)IBOutlet UIScrollView *sceoll;
在.m類中
- (void)viewDidLoad
{
[sceoll setContentSize:CGSizeMake(0, 500)];
[textvie setTextAlignment:NSTextAlignmentCenter];
textvie.editable = FALSE;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
textvie.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
} else {
textvie.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
}
[super viewDidLoad];
}
在xib
其結果是:-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.