如何自动调整UITextView的大小?

发布于 2024-12-23 12:11:53 字数 104 浏览 2 评论 0原文

我想制作语音气泡,但在 UITextView 中调整气泡大小时出现问题。

根据文本的长度自动增加 Textview 的大小?

有没有办法使用 UITextView

I want to make speech bubbles but there is a problem adjusting size of the bubbles in UITextView.

is there a way to increase the size of the Textview automatically depending on the length of the

text by using UITextView?

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

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

发布评论

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

评论(2

晚风撩人 2024-12-30 12:11:54

我想我明白你的意思。前几天我遇到了这个问题。这段代码将调整 UITextView 的内容。创建一个新类并通过新类调用它。如果你想很好地调整视图,我仍在努力:-P

希望这会有所帮助

    - (void)drawRect:(CGRect)rect
{
    CGRect frame = self.frame;
    frame.size.height = self.contentSize.height;
    self.frame = frame;     // Drawing code
}

I think I understand what your getting at. I had this problem the other day. This bit of code will adjust the UITextView contents. Create a new class and call this into it via a new class. If you want to adjust the View well I'm still working on that :-P

Hope this helps

    - (void)drawRect:(CGRect)rect
{
    CGRect frame = self.frame;
    frame.size.height = self.contentSize.height;
    self.frame = frame;     // Drawing code
}
祁梦 2024-12-30 12:11:53

好吧,我找到了一种更好的方法来完成我的建议。而不是处理 UIView 并根据其中的文本调整大小。我刚刚使 UITextView 具有圆形边缘,现在看起来像一个面板。完美的。希望这对某人有帮助!

如果您对代码感兴趣

- (void)drawRect:(CGRect)rect
{
    CGRect frame = self.frame;
    frame.size.height = self.contentSize.height;
    self.frame = frame;     // Drawing code
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 10.0f;    
}

Okay I found a better way of doing what I was suggesting. Rather then deal with the UIView and resizing depending on the text inside it. I just made the UITextView have a rounded edge which now looks like a panel. Perfect. Hope this helps someone!

If your interested in the code

- (void)drawRect:(CGRect)rect
{
    CGRect frame = self.frame;
    frame.size.height = self.contentSize.height;
    self.frame = frame;     // Drawing code
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 10.0f;    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文