[英]How to set Height and width for a object in Xcode 10? If we set value it says fixed constraint may cause clipping
Should I give width and Height for an object like button while setting layout? 设置布局时,是否应该为按钮之类的对象指定宽度和高度? If I use Greater than or equal to option, It expands the button in bigger screens? 如果我使用大于或等于选项,它将在更大的屏幕上展开按钮吗? How to make a button stay in same size regardless of the device its being viewed? 如何使按钮保持相同的大小,而不管其在观看的设备如何? Is it a good practise to design like this ? 这样设计是一种好习惯吗? or the object should get bigger for bigger screens? 还是对象应该变得更大以适合更大的屏幕?
Sorry about too many questions. 抱歉,有太多问题。 Just breaking my head for days. 几天都伤了我的头。
Thanks in Advance Guys 在此先感谢大家
Generally speaking, it's quite a bad practice to set width and height for a button. 一般而言,为按钮设置宽度和高度是一个很糟糕的做法。 Because the size of its content might expand depending on the user's settings (accessibility settings, for instance). 因为其内容的大小可能会根据用户设置(例如,辅助功能设置)而扩展。
It's better just to set the top+leading OR top+trailing OR bottom+leading , etc... 最好只设置top + leading 或 top + trailing 或 bottom + leading等。
This is mostly sufficient to make the button "look the same" on different devices (it will indeed be a little bigger on bigger screens). 这足以使按钮在不同设备上“看起来相同”(在更大的屏幕上确实会更大)。
And remember, as of constraints, less is better than many. 并且请记住,由于种种限制,少胜于多。 When your component is placed and its constraints are all blue, test if it works as you expect and if yes, don't add more constraints. 放置组件且其约束全部为蓝色时,请测试其是否按预期工作,如果是,请不要添加更多约束。 As beginners, we tend to over-constraint and it generates issues. 作为初学者,我们倾向于过度约束,并且会产生问题。
It mostly depends on yours app design. 这主要取决于您的应用程序设计。
Many built-in UIKit views (including buttons) have their own (intrinsic) size. 许多内置的UIKit视图(包括按钮)具有自己的(本征)大小。 So it is not necessary to define size explicitly, but you can do this if you want. 因此,不必显式定义大小,但是您可以根据需要执行此操作。 Remember that you shouldn't make excessive use of expicit sizes as this can lead to non-adaptive design. 请记住,您不应过度使用显式尺寸,因为这可能会导致非自适应设计。
In most cases it's worth to allow view to have its intrinsic height but constrain its width in some way (for example, in percents to superview's width, set minimum/maximum allowed value etc). 在大多数情况下,值得使视图具有其固有高度,但以某种方式限制其宽度(例如,以百分比表示的视图宽度,设置最小/最大允许值等)。 But in any case you should define position where your view will be displayed. 但是无论如何,您都应该定义显示视图的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.