问题描述
我正在寻找一种以编程方式禁用UITextView水平滚动的方法,通过Interface Builder很容易,但由于我以编程方式设计视图,我找不到这样做的方法,我已经谷歌搜索它,但我得到的最多是:
I'm looking for a way to disable horizontal scrolling of a UITextView programmatically, it was easy via the Interface Builder, but since I'm designing the view programmatically I can't find a way to do this, I've googled it as well but the most I got was this:
并且它无效。
任何提示?
and it is not working.Any hints?
self.textViewOpenedRect = CGRectMake(20, 20, 280, 130);
self.textView = [[UITextView alloc] initWithFrame: self.textViewOpenedRect];
self.textView.contentInset = UIEdgeInsetsMake(5, 5, 5, 5);
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.contentSize = CGSizeMake( self.textView.frame.size.height, self.textView.contentSize.height);
self.textView.alwaysBounceHorizontal = NO;
self.textView.bounces = NO;
更新:显然问题是因为这行代码:
UPDATE: apparently the problem is because of that line of code:
self.textView.contentInset = UIEdgeInsetsMake(5, 5, 5, 5);
我用它在框架和文本之间留出一点空间。 。 .am我做得好吗?
wich I use to have a bit of space between the frame and the text. . .am I doing it properly?
推荐答案
这应该有帮助......
UITextView
是 UIScrollView
的子类,所以这很容易实现。
This should help...UITextView
is a subclass of UIScrollView
, so this is pretty easy to implement.
mytextView.contentSize = CGSizeMake(mytextView.frame.size.height,mytextView.contentSize.height);
mytextView.showsHorizontalScrollIndicator = NO;
这篇关于以编程方式禁用水平滚动到UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!