以编程方式禁用水平滚动到UITextView [英] Disable Horizontal Scrolling to UITextView Programmatically

查看:108
本文介绍了以编程方式禁用水平滚动到UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种以编程方式禁用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆