在 UIImageView 之上调整 UILabel 的大小
我的问题如下: 我在 UIImageView
之上有一些标签。该图像是一个公式,UILabel
代表条目。 如果我旋转设备,UIImageView
内的图像将使用“宽高比适合”选项调整大小。 如何才能使 UILabel
也调整大小并正确对齐? 调整大小的正常选项无法按需要工作。 UIImageView
可通过设置minimumZoomScale 和maximumZoomScale 进行缩放。
谢谢。
My problem is as follows:
I have on top of a UIImageView
some labels. The image is a formular and the UILabel
s represents the entries.
If I rotate the device the image inside UIImageView
gets resized with option "aspect fit".
How can I achieve that the UILabel
is also resized and aligned correct?
The normal options for resizing aren't working as needed.
The UIImageView
is zoomable with minimumZoomScale and maximumZoomScale set.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下方法按比例调整
UILabel
的大小:您可以使用相对地重新定位
UILabel
的位置:剩下的就是数学 =)
所以我设法解决了您的问题。完整源代码此处。
基本上,我删除了您的
UIImageView
并将其替换为UIView
。然后,我在UIView
中添加了您的UILabel
,并从界面生成器中的UIView
和UILabel
中删除了任何自动调整大小。这样,当UIView
调整大小时,其中的任何内容也会调整大小/重新定位。下一步是在界面构建器中将
UIView
的类更改为UIImageView
。现在,从源代码中,我可以使用 imgView.image = [UIImage imageNamed:@"imagename.png"]; 为其设置图像,也可以使用 imgView 设置模式。 contentMode = UIViewContentModeScaleAspectFit;。旋转变换现在发生在:
You can resize a
UILabel
proportionally using:You can reposition a
UILabel
relatively using:The rest is maths =)
So I managed to solve your problem. Full source code here.
Basically I removed your
UIImageView
and replaced it with aUIView
. Then I added yourUILabel
s within theUIView
and removed any autosizing from theUIView
andUILabel
s in interface builder. That way when theUIView
gets resized any content in it will get resized/repositioned as well.The next step was to change the class of the
UIView
toUIImageView
in interface builder. Now from the source code I could set an image to it usingimgView.image = [UIImage imageNamed:@"imagename.png"];
as well as I could set the mode usingimgView.contentMode = UIViewContentModeScaleAspectFit;
.The transformation at rotation now happens with: