将组件放置在 UITextView 下方并调整大小以适合
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您首先需要在
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 onNSString
to measure your string (I'm assuming you're not using an attributed string) and then set theUITextView
's frame to match the size.After you have that frame, you can place your
UIImageView
directly below it.