从UITextView中删除所有填充

从UITextView中删除所有填充

本文介绍了IOS - 从UITextView中删除所有填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多很好的例子可以删除UITextView的左侧填充。

There are many great examples on SO to remove the left padding of a UITextView.

How to lose margin/padding in UITextView?

但是,我需要删除正确的填充。

However, I need to remove the right padding too.

我试过......

[tv setContentInset: UIEdgeInsetsMake(-4,-8,-8,-X)];//where X is any integer

以及最后两个值的每个其他排列,以删除填充,似乎没有任何效果。还尝试了

and just about every other permutation of the last two values to remove the padding and nothing seems to work. Have also tried

[tv sizeToFit];
[tv setTextAlignment:[NSTextAlignmentRight]];

Textview中的以下文字说00

The following Text in the Textview says "00"

推荐答案

虽然它只是iOS 7,但是一个非常干净的解决方案是将textView的textContainerInsets设置为:

Although it is iOS 7 only, an extremely clean solution is to set the textView's textContainerInsets as such:

[textView setTextContainerInset:UIEdgeInsetsZero];
textView.textContainer.lineFragmentPadding = 0; // to remove left padding

这将有效删除文本内部文本周围的所有填充(插入)视图。如果您的部署目标是iOS 7+,那么这是迄今为止最好的解决方案。

This will effectively remove all padding (insets) around the text inside the text view. If your deployment target is iOS 7+ then this is the best solution thus far.

这篇关于IOS - 从UITextView中删除所有填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!