简体   繁体   English

如何调整标签大小以适合任何屏幕尺寸

[英]How to Re-Size Label to fit any screen size

Ok, here's what I'm trying to do: I would like to create a scroll view to scroll vertically, in case my text is longer than the screen size (think iPhone 4 vs. iPhone 6). 好的,这是我要尝试的操作:我想创建一个滚动视图以垂直滚动,以防我的文本长于屏幕尺寸(想想iPhone 4与iPhone 6)。

I've added a scroll view and placed a view within that. 我添加了一个滚动视图,并在其中放置了一个视图。 I embedded by label for the text within the view. 我通过标签将视图中的文本嵌入。

However, the scroll view currently will scroll only horizontally. 但是,当前滚动视图将仅水平滚动。

Is there a way to constrain the label width to be the width of the screen? 有没有办法将标签宽度限制为屏幕的宽度? How do I do this? 我该怎么做呢?

You can constrain the width to contentview to be equal to scrollview width. 您可以将contentview的宽度限制为等于scrollview宽度。 And pin the four sides of label to the content view. 并将label的四个侧面固定到内容视图。 Also you will need to pin all sides of content view to scrollview, if you haven't already did that. 另外,如果您还没有这样做,则需要将内容视图的所有侧面固定到scrollview。

If you push the constraint button on the bottom of your storyboard pin it to both the left and right side. 如果按情节提要板底部的约束按钮,则将其固定在左侧和右侧。 Uncheck constraint to margins and pin it both 0. :) 取消选中对边距的约束,并将其都固定为0。:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM