import Foundation
class NSLayoutConstraintEx: NSLayoutConstraint {
@IBInspectable
var ipad: CGFloat = 0 {
didSet {
if DeviceUtils.isIPad() {
constant = ipad
}
}
}
var iphone4: CGFloat = 0 {
//640 x 960
if DeviceUtils.isIphone() && DeviceUtils.getScreenSize().height == 960.0 {
constant = self.iphone4
var iphone5: CGFloat = 0 {
//640 x 1136
if DeviceUtils.isIphone() && DeviceUtils.getScreenSize().height == 1136.0 {
constant = self.iphone5
var iphone6: CGFloat = 0 {
//750 x 1334
if DeviceUtils.isIphone() && DeviceUtils.getScreenSize().height == 1334.0 {
constant = self.iphone6
var iphone6Plus: CGFloat = 0 {
//1242 x 2208
if DeviceUtils.isIphone() && DeviceUtils.getScreenSize().height >= 1920.0 {
constant = self.iphone6Plus
}
用法:
修改现在的约束,让它使用NSLayoutConstraintEx,效果如下:
注意User Defined Runtime Attributes这一栏,如果去掉某个自定义属性,这边可能会存在残留,删掉残留的那一项即可。还有Module这一栏如果显示None说明使用自定义类失败,一般把Class删除一下重新制定就好了。
默认是iPhone布局,这样在iPad上就能使用大尺寸的图片了