如何为不同的屏幕尺寸设置不同的自动版式约束 [英] How to set up different Auto Layout constraints for different screen sizes

查看:147
本文介绍了如何为不同的屏幕尺寸设置不同的自动版式约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有静态单元格的tableView.该单元格包含一个ImageView,将其完全填充.我上面还有另一个较小的ImageViews.我将这个ImageViews置于约束中.我有一个关于调整约束大小的问题. 如何在不编程if/else循环的情况下为不同的设备大小设置不同的约束常数.有没有办法在情节提要中进行设置?我对父版式有一个主要的约束,例如恒定值为10.这对于iPhone 5屏幕是可以的,但是在iPhone 6/6 plus屏幕上,它应该大于10.

I have a tableView with static cells. The cell contains an ImageView which fills it completely. And I have another smaller ImageViews atop. I position this ImageViews with constraints. I have a question about resizing the constraints. How can I set different constraint constants for different devices sizes without programming if/else loops. Is there a way to set it in the storyboard? I have a leading constraint to parent layout for example with an constant value of 10. This is okay for the iPhone 5 screen, but on an iPhone 6/ 6 plus screen it should be higher than 10.

iPhone5自动版式

iPhone6自动版式

推荐答案

无需编写任何代码!

一旦我的初级开发人员问了我一个相同的问题,那就是当时我该如何区分iPhoneSE和iPhone6的某些约束,只有一个解决方案正在编写类似的东西

Without writing a single line of Code!

Once my junior developer asked me the same question that how can I differentiate between iPhoneSE and iPhone6 for some constraint at that time there was only one solution that was writing some thing like

if device == iPhoneSE { 
   constant = 44 
} else if device == iPhone6 {
   constant = 52
}

为解决此问题,我创建了一个库 Layout Helper ,现在您可以为每个库更新约束设备,而无需编写任何代码.

To overcome this issue I created a library Layout Helper so now you can update constraint for each device without writing a single line of code.

这篇关于如何为不同的屏幕尺寸设置不同的自动版式约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆