简体   繁体   English

UIButton高度在不同设备上使用AutoLayout增加大小

[英]UIButton Height Increase Size Using AutoLayout with Different Devices

I have a fully functional app and I'm creating a new View Controller in Interface Builder with buttons and labels. 我有一个功能齐全的应用程序,并且正在Interface Builder中用按钮和标签创建一个新的View Controller。 I've laid out everything in the Interface Builder and used AutoLayout to make sure every component is in place. 我已经在Interface Builder中布置了所有内容,并使用了AutoLayout来确保每个组件都就位。 It's working very well on the iPhone 5s, but with the iPhone 6 and 6 Plus, my UIButton s are not resizing it's height to adjust to the bigger screens. 它在iPhone 5s上运行良好,但是在iPhone 6和6 Plus上,我的UIButton并未调整其高度以适应更大的屏幕。

A screenshot would make help make more sense of this. 屏幕快照可以帮助您更好地理解这一点。

iPhone 5s iPhone 5S 在此处输入图片说明

iPhone 6 Plus iPhone 6 Plus 在此处输入图片说明

The Update Me text is one UILabel . Update Me文本是一个UILabel The Basic to the bottom PRO Unlimited is one UILabel . 最底层的PRO Unlimited是一个UILabel The buttons are separate UIButton s. 这些按钮是单独的UIButton The Restore Purchases is a UIButton and the final text on the bottom is a UILabel . Restore Purchases是一个UIButton ,底部的最后一个文本是UILabel

The constraints I have in place which matter are: 我所要考虑的约束是:

Basic Label 基本标签

Trailing Space to Superview 尾随空间观看

Leading Space to Superview 领导观看的空间

Bottom Space to Restore Purchases UIButton 恢复购买的底部空间UIButton

Top Space to UpdateMe UILabel UpdateMe UILabel顶部空间

Buy 100 UIButton 购买100 UIButton

Leading Space to Superview 领导观看的空间

Trailing Space to Buy Unlimited UIButton 购买无限UIButton尾随空间

Top Space to Top Layout 顶部空间到顶部布局

Bottom Space to Restore Purchases UIButton 恢复购买的底部空间UIButton

Equal Width to Buy Unlimited UIButton 等宽购买无限UIButton

Buy Unlimited UIButton 购买无限UIButton

Trailing Space to Superview 尾随空间观看

Leading Space to Buy 100 领先的购买空间100

Top Space to Top Layout 顶部空间到顶部布局

Bottom Space to Restore Purchases UIButton 恢复购买的底部空间UIButton

Equal Width to Buy 100 等宽购买100

Restore Purchases UIButton 恢复购买UIButton

Trailing Space to Superview 尾随空间观看

Leading Space to Superview 领导观看的空间

Top Space Basic UILabel 顶部空间基本UILabel

Bottom Space to A One Off UILabel 底部空间到一个UILabel

Top Space to Buy Unlimited 无限购买的顶级空间

Top Space to Buy 100 顶级购买空间100

On the iPhone 5s, the Restore Purchases UIButton has a width of 268 and height of 30. 在iPhone 5s上,“恢复购买” UIButton的宽度为268,高度为30。

On the iPhone 6 Plus, the Restore Purchases UIButton has a width of 382 and height of 198, so clearly that's taking up a huge chunk of space which causes the UIButton to not increase. 在iPhone 6 Plus上,“ Restore Purchases” UIButton的宽度为382,高度为198,因此很显然这占用了大量空间,导致UIButton不会增加。

What I would like to achieve is, every component in it's place as it is now, but on the iPhone 6 Plus, have the Buy 100 and Buy Unlimited UIButton s to increase in height with the width to stay the same. 我想实现的是,它的每个组件都像现在这样放置,但是在iPhone 6 Plus上,使Buy 100和Buy Unlimited UIButton的高度增加,而宽度保持不变。

Any guidance on this would really be appreciated! 对此的任何指导将不胜感激!

Restore Purchases UIButton: 还原购买UIButton:

Remove below constrain 删除以下约束

1.Top Space to Buy Unlimited 2.Top Space to Buy 100 1.顶级空间无限购买2.顶级空间购买100

Show "preview" the screens in "show assistant editor" option. 在“显示助手编辑器”选项中显示“预览”屏幕。 Check the various screen size using preview option. 使用预览选项检查各种屏幕尺寸。 If needed please remove and add the constraints in your screen. 如果需要,请删除并在屏幕上添加约束。 This preview option is very useful to resolve the auto layout constraints issue. 此预览选项对于解决自动布局约束问题非常有用。

In here you can add Aspect Ratio Constrains to your buttons. 在这里,您可以将纵横比约束添加到按钮。

在此处输入图片说明

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

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