简体   繁体   English

ios-如何在情节提要中自动调整视图大小? 迅捷3

[英]ios - How to auto-resize my view in storyboard? swift 3

I try to auto-resize my view with auto-layout contraints, but I have some errors of Y-position missing. 我尝试使用自动布局约束自动调整视图大小,但是我缺少一些Y位置错误。 I can't understand what is wrong, I attached my Y-position to the top of the view. 我不明白哪里出了问题,我将Y位置附加到视图顶部。

Thanks for your help, here is the screenshot: 感谢您的帮助,以下是屏幕截图:

约束错误

The problem is that you don't set a fixed height but, if you can, ALWAYS AVOID to put a fixed height for a view. 问题是您没有设置固定的高度,但是,如果可以的话,请始终避免为视图设置固定的高度。 For an app that can fit all screen is better to use different techniques. 对于适合所有屏幕的应用,最好使用不同的技术。 If don't want to set a fixed height on your view, you have two possible options: 如果不想在视图上设置固定高度,则有两个可能的选择:

  1. Give to the view a bottom constraint . 给视图一个底部约束 You should also set the distance between the bottom of your view and the screen (or another object below your view). 您还应该设置视图底部和屏幕(或视图下方的另一个对象)之间的距离。
  2. Use stackview. 使用stackview。 If you place your views into a stack view you will be able to autoresize the width and height of your views according to the screen dimension. 如果将视图放入堆栈视图,则可以根据屏幕尺寸自动调整视图的宽度和高度。

You must give a height for the view or construct it's subviews in a way that gives it a height by hooking constraints properly from top to bottom 您必须为视图提供高度或以子视图的方式构造子视图,从而通过适当地上下挂钩约束来赋予其高度

when you have ay position error it means top, bottom and height issue 当您遇到ay位置错误时,这意味着顶部,底部和高度问题

and when x it means leading , trailing and width issue 当x表示前导,尾随和宽度问题

IF you want to create dynamic view drag a vertical UIStackView and give it a height and in runtime add items to it 如果要创建动态视图,请拖动垂直的UIStackView并赋予其高度,然后在运行时向其中添加项目

 self.myStackView.addArrangedSubview(lbl)

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

相关问题 如果我仅包含3倍于iOS的图像,它会自动调整大小吗? - If I just include images 3 times as large for iOS, will it auto-resize? 当我的 UITableViewCell 的内容发生变化时,如何告诉它“自动调整大小”? - How do I tell my UITableViewCell to “auto-resize” when its content changes? 如何调整情节提要的大小? ios - How to resize storyboard? ios 如何防止UIView动画进行子视图自动调整大小操作? - How to prevent UIView animation for subview auto-resize operations? 我应该如何通过 Storyboard 为我的 iOS 视图设置自动布局/约束? - How should I got about setting the auto layout / constraints for my iOS view via Storyboard? 自动将iPhone xib应用程序调整为ipad - Auto-resize iPhone xib app to ipad 在iOS 6中更改tableHeaderView的框架时,UITableView不会自动调整大小 - UITableView doesn't auto-resize when changing frame of tableHeaderView in iOS 6 iOS在UITableViewHeaderFooterView.ContentView子视图中自动调整自定义单元格宽度 - iOS Auto-resize custom cell width in UITableViewHeaderFooterView.ContentView Subview 在滚动时迅速调整iOS大小 - swift iOS resize view on scroll iOS自动布局,如何调整超级视图的大小以适合所有子视图 - iOS auto layout, how to resize super view to fit all subviews
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM