简体   繁体   English

如何在UIButton上设置宽度约束

[英]How to set a width constraint on a UIButton

I have a button that I want to be a constant size across all devices (iPhone 4,5,6, iPad...etc). 我有一个按钮,希望在所有设备(iPhone 4、5、6,iPad等)上保持恒定大小。 I want that button to be 347 x 66 pixels wide. 我希望该按钮的宽度为347 x 66像素。 I currently have the following constraints: 我目前有以下限制:

限制

However, the width constraint isn't followed. 但是,没有遵守宽度限制。 This is what it looks like when ran in simulation: 这是在模拟中运行时的样子:

约束问题

Any ideas on how to get it to always be 374 pixels wide on any device ? 关于如何使它在任何设备上始终保持374像素宽的任何想法?

Thanks 谢谢

You should always design in points not pixels, which is why constraints are in points. 您应该始终以点而不是像素进行设计,这就是为什么约束以点为单位。 The iPhones up to the 5s are all 320 points across in portrait mode, so 374 points would be wider than the screen. 在纵向模式下,5s以下的iPhone的总像素为320点,因此比屏幕宽374点。 The two iPhone 6 models are a bit wider, in points. 两种iPhone 6机型的宽度稍大一点。 The simulator image you posted is indeed trying to show a button which is 374 points wide, ie wider than the screen. 您发布的模拟器图像确实试图显示一个374点宽(即比屏幕宽)的按钮。 Perhaps you intended to make a button which is half that width, 187 points, which is 374 pixels on a 2x retina screen? 也许您打算在2x视网膜屏幕上制作一个按钮,宽度是宽度的一半(187点),即374像素?

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

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