简体   繁体   English

如何在 UITextView Swift 中删除文本的顶部填充

[英]How to remove top padding for text in UITextView Swift

I have a unusual problem.我有一个不寻常的问题。 First i have Nav Controller and as a one page i have view controller with top panel for back button.首先,我有导航控制器,作为一个页面,我有带有后退按钮顶部面板的视图控制器。 I added uiview and uitextview on it.我在上面添加了 uiview 和 uitextview 。 Then i make all needed constraints and after run and see top padding for text in textview about ~60 px .然后我做了所有需要的约束,然后在运行后看到 textview 中文本的顶部填充大约 ~60 px 。 And i dont really know how to remove it.而且我真的不知道如何删除它。

  1. I tried:我试过:

     textViewUserInput.contentInset = UIEdgeInsetsMake(-50, 5, 5, 5);

    it works but value -50 for top inset is not good for different devices and orientation它有效,但顶部插入的值 -50 不适用于不同的设备和方向

  2. I also tried:我也试过:

     textViewUserInput.textContainerInset = UIEdgeInsetsZero; textViewUserInput.textContainer.lineFragmentPadding = 0;

    doesn't change anything不会改变任何东西

In Main.storyboard, select your view controller the one that has the UITextView in and underneath your attributes inspector tab uncheck "Adjust scroll view insets".在 Main.storyboard 中,选择在属性检查器选项卡中和下方具有 UITextView 的视图控制器,取消选中“调整滚动视图插入”。 I had the same problem and that worked for me.我有同样的问题,这对我有用。

Or you can add [textView setTextContainerInset:UIEdgeInsetsZero]; or textView.textContainerInset = .zero或者你可以添加[textView setTextContainerInset:UIEdgeInsetsZero]; or textView.textContainerInset = .zero [textView setTextContainerInset:UIEdgeInsetsZero]; or textView.textContainerInset = .zero in your code. [textView setTextContainerInset:UIEdgeInsetsZero]; or textView.textContainerInset = .zero在您的代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM