文本滚动到 UITextView 框边界之外

发布于 2024-12-07 05:50:09 字数 702 浏览 0 评论 0原文

我有一个 UITextView,里面有一些文本。问题是文本滚动到 UITextView 框的边界之外。 (UITextView 不可编辑。)

这是代码以及我尝试解决此问题的方法:

  - (void)viewDidLoad {

        textBG.contentInset = UIEdgeInsetsZero;

    //  textBG.layer.masksToBounds = NO;
        textBG.layer.cornerRadius = 10.0;
        textBG.layer.borderWidth = 0.0;
        [textBG setClipsToBounds:YES];

    [super viewDidLoad];
}

- (void)textViewDidBeginEditing:(UITextView*)textView
{

textBG.contentInset = UIEdgeInsetsZero;    
 [textBG setClipsToBounds:YES];   
}

- (void) shouldChangeTextInRange:(UITextView*)textView {

    textBG.contentInset = UIEdgeInsetsZero;    
    [textBG setClipsToBounds:YES];

}

感谢您的帮助

I have a UITextView that has some text in it. The problem is that the text scrolls outside of the boundaries of the UITextView box. (The UITextView is uneditable.)

here's the code and what I have tried to resolve this issue:

  - (void)viewDidLoad {

        textBG.contentInset = UIEdgeInsetsZero;

    //  textBG.layer.masksToBounds = NO;
        textBG.layer.cornerRadius = 10.0;
        textBG.layer.borderWidth = 0.0;
        [textBG setClipsToBounds:YES];

    [super viewDidLoad];
}

- (void)textViewDidBeginEditing:(UITextView*)textView
{

textBG.contentInset = UIEdgeInsetsZero;    
 [textBG setClipsToBounds:YES];   
}

- (void) shouldChangeTextInRange:(UITextView*)textView {

    textBG.contentInset = UIEdgeInsetsZero;    
    [textBG setClipsToBounds:YES];

}

thanks for any help

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青衫负雪 2024-12-14 05:50:09

将其写入 textView 委托方法中,例如

textBG.contentInset = UIEdgeInsetsZero;

viewDidload 中的textViewDidBeginEditing

[textBG setClipsToBounds:YES];

write this in textView delegate methods like textViewDidBeginEditing

textBG.contentInset = UIEdgeInsetsZero;

in viewDidload

[textBG setClipsToBounds:YES];
一向肩并 2024-12-14 05:50:09

尝试在 XIB 中为您的 TextView 进行更改,如下所示:在此处输入图像描述

Try to change in XIB for your TextView like below:enter image description here

以歌曲疗慰 2024-12-14 05:50:09

只需输入这一行代码即可解决问题。

yourTextView.clipsToBounds = true

Just put this one line code to solve problem.

yourTextView.clipsToBounds = true
听闻余生 2024-12-14 05:50:09

我遇到了同样的问题,所以我追踪了来源...这是因为在添加阴影时您以某种方式干扰了它的 ma​​sksToBounds 属性。因此,在添加更多文本时,它会溢出。我发现的简单解决方案是在添加阴影后编写这一简单的行。

[self.myTextView setClipsToBounds:YES];

通常应该在 viewDidLoad 方法中,但请记住仅应用shadow之后编写此行。

感谢您阅读本文。

I faced this same problem, so I track down the source ... this is because of while adding shadow somehow you disturbed it's masksToBounds property. Therefore, while adding more text it got overflowed. Simple solution which I found is to write this simple line after adding shadow.

[self.myTextView setClipsToBounds:YES];

usually should be in viewDidLoad method, but remember to write this line only after applying shadow.

Thanks for reading this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文