如何在UITextView中丢失margin / padding? [英] How to lose margin/padding in UITextView?

查看:135
本文介绍了如何在UITextView中丢失margin / padding?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iOS应用程序中有一个 UITextView ,它显示大量的文本。然后我使用 UITextView 的offset margin参数分页这段文本。我的问题是, UITextView 的填充混淆我的计算,因为它似乎是不同的,取决于我使用的字体大小和字体。

I have a UITextView in my iOS Application, which displays a large amount of text. I am then paging this text by using the offset margin parameter of the UITextView. My problem is that the padding of the UITextView is confusing my calculations as it seems to be different depending on the font size and typeface that I use.

因此,我提出了一个问题:是否可以删除 UITextView

Therefore, I pose the question: Is it possible to remove the padding surrounding the content of the UITextView?

期待您的回应!

推荐答案

我遇到了完全相同的问题,我不得不卷起来使用

I ran into the exact same problem, in the end I had to wind up using

nameField.contentInset = UIEdgeInsetsMake(-4,-8,0,0);

其中nameField是 UITextView 。我碰巧使用的字体是Helvetica 16点。它只是一个定制的解决方案为特定的字段大小我画的。这使得左偏移与左侧齐平,并且顶部偏移在我想要它的框中它的绘制。

where nameField is a UITextView. The font I happened to be using was Helvetica 16 point. Its only a custom solution for the particular field size I was drawing. This makes the left offset flush with the left side, and the top offset where I want it for the box its draw in.

此外,这似乎只适用于 UITextViews 您正在使用默认配置,即

In addition, this only seems to apply to UITextViews where you are using the default aligment, ie.

nameField.textAlignment = NSTextAlignmentLeft;

向右对齐例如和 UIEdgeInsetsMake 似乎对右边缘没有任何影响。

Align to the right for example and the UIEdgeInsetsMake seems to have no impact on the right edge at all.

至少,使用.contentInset属性可以让你的字段与正确的位置,并适应偏差而不抵消您的 UITextViews

At very least, using the .contentInset property allows you to place your fields with the "correct" positions, and accommodate the deviations without offsetting your UITextViews.

这篇关于如何在UITextView中丢失margin / padding?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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