uitextViewcontentintset

问题描述 投票:0回答:2

I的印象是ContentInset在不引起水平滚动条的情况下将UitextView挤压到UitextView,因此如何消除对水平滚动栏的需求并制作所有东西 - 插图 - iNSET和uitextview中的所有文本 - 无需对这个卷轴

N.B:我不是在询问防止水平滚动或不显示滚动条(从而切割文本)

非常感谢!

enter image description herefor atomk(uitextview称为ss)

NSLog(@"Content Size Before %f",self.ss.contentSize.width); Logs: 280 CGSize size=self.ss.contentSize; size.width=size.width-50; [self.ss setContentSize:size]; NSLog(@"Content Size After %f",self.ss.contentSize.width); Logs: 230

在添加之前添加的代码之间的视图之间有明显的区别,因此出了问题! (谢谢)

在iOS 7中是基于TextKit,并具有新的属性

UITextView
。它的行为就像您期望的那样:

textContainerInset

Swift4.2
ios objective-c uiscrollview uikit
2个回答
203
投票

UITextView *textView = ...;
// Left inset of 50 points
textView.textContainerInset = UIEdgeInsetsMake(0.0, 50.0, 0.0, 0.0);
*

swift5

textView.textContainerInset = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: 0)

update:此解决方案已过时截至iOS7.

请参见下面的答案。在iOS 7.0中,引入了

textView.textContainerInset.left = 50

属性。

对象-C:

textContainerInset

149
投票

UITextView swift 5.0:

textView.textContainerInset = UIEdgeInsetsMake(0, 50, 0, 0);

pre-ios 7解决方案:



I的印象是ContentInset在不引起此水平滚动条的情况下将uitextview挤压了...

我害怕这不是与

textView.textContainerInset = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: 0)

一起使用的方式。请参阅
apple的文档

textView.textContainerInset.left = 50

有关:

内容视图与封闭卷轴视图插入的距离...使用此属性添加到内容周围的滚动区域。 the the the the是围绕内容添加的。

您可以使用上述代码更改
contentInset

UITextView

contentInset

contentInset

,这导致文本在右侧被切断:


我能够在A中实现水平填充的最佳方法是将其放置在容器contentSize中。在您的情况下,只需创建一个与当前文本视图相同的大小,然后添加容器视图内50px的文本视图。
如果您有文本视图的背景,则此方法可能会引起问题,但是从上方的屏幕截图来看,这似乎对您来说并不是一个问题。

viewDidLayoutSubviews
(红色框架)内部

- (void)viewDidLayoutSubviews { self.textView.contentInset = UIEdgeInsetsMake(0, 50, 0, 0); NSLog(@"Content Size Before %f",self.textView.contentSize.width); //Logs: 280 CGSize size=self.textView.contentSize; size.width=size.width-50; [self.textView setContentSize:size]; NSLog(@"Content Size After %f",self.textView.contentSize.width); //Logs: 230 }

容器:


如果您的UITextView

确实有背景,请参见:

如何设置uitextview的内容插图,例如notesapp

您从反向工程注释中学到了App
(请参阅“ iPadding”部分)

UITextView cut off on right side

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.