向UITextView添加左边距 [英] Adding left margin to UITextView

查看:501
本文介绍了向UITextView添加左边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向UITextView添加左边距。

I'm trying to add a left margin to a UITextView.

我尝试过设置属性contentInset,见下文:

I've tried setting the property contentInset, see below:

UITextView *textView = [[UITextView alloc] initWithFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
textView.editable = YES;
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
textView.backgroundColor = [UIColor clearColor];
textView.opaque = NO;
textView.contentInset = UIEdgeInsetsMake(0, 15.0f, 0, 0);

这似乎有效,虽然它会导致TextView上我不想要的水平滚动。

This seems to work though it causes horizontal scrolling on the TextView which I don't want.

我只想让左侧的文本插入而不使textview更宽。

I just want the text inset on the left without making the textview any wider.

推荐答案

如果您只想移动文本,请尝试

If you only want to move the text, try

[textView setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

如果正数将文本框架移向中间,则负数将其移出中间。

Where a positive number moves the "text frame" towards the middle, a negative moves it out from the middle.

例如, [textView setContentInset:UIEdgeInsetsMake(0,20,0,-20)] ,将文本向右移动20个像素!

For example, [textView setContentInset:UIEdgeInsetsMake(0, 20, 0,-20)], will move the text 20 pixels to the right!

这篇关于向UITextView添加左边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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