将组件放置在 UITextView 下方并调整大小以适合

发布于 2024-12-22 21:16:42 字数 345 浏览 3 评论 0原文

我有一个 UITextView ,它必须保持宽度为:100px,但高度可以增长;但高度应该足以容纳内容。我想在 UITextView 的正下方显示图像。

是否有自动调整的控件,还是我必须自己编写所有这些代码?

例如:

情况 1:UITextView 的高度为 200px 那么我希望我的 UIImageView 的高度为 201px (y)
情况 2:UITextView 的高度是 300px 那么我希望我的 UIImageView 的高度为 301px (y)

I have a UITextView that must keep a width of say: 100px but the height can grow; but the height should only be enough to fit the contents. Right below the UITextView I want to display an image.

Is there a control the auto adjust or do I have to code all this myself?

for example:

case 1: the height of UITextView is 200px then I want my UIImageView to go at 201px (y)
case 2: the height of UITextView is 300px then I want my UIImageView to go at 301px (y)

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

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

发布评论

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

评论(1

自由如风 2024-12-29 21:16:42

为此,您首先需要在 NSString 上使用 sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: (或任何 sizeWithFont... 选择器)选择器code> 来测量您的字符串(我假设您没有使用属性字符串),然后设置 UITextView 的框架以匹配大小。

获得该框架后,您可以将 UIImageView 直接放置在其下方。

In order to do this, you'll first need to use the sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: (or any of the sizeWithFont... selectors) selector on NSString to measure your string (I'm assuming you're not using an attributed string) and then set the UITextView's frame to match the size.

After you have that frame, you can place your UIImageView directly below it.

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