Objective
How to achieve a picture on the iphone and ipad display different sizes, I learned that there are three ways: direct handwriting code dynamically add constraints; Nslayoutconstraint associated to the Viewcontroller viewdidload inside plus judgment assignment , with size classes (this is not very good at present). Here is a way to share a direct fit within the storyboard.
StatementWelcome reprint, but please keep the original source of the article:)Blog Park: http://www.cnblogs.comFarmer Uncle: Http://over140.cnblogs.com
Body
Import Foundation
classNslayoutconstraintex:nslayoutconstraint {
@IBInspectable
var ipad:cgfloat =0{
Didset {
ifDeviceutils.isipad () {
Constant = ipad
}
}
}
@IBInspectable
var iphone4:cgfloat =0{
Didset {
//640 x 960
ifDeviceutils.isiphone () && deviceutils.getscreensize (). Height = =960.0{
Constant = Self.iphone4
}
}
}
@IBInspectable
var iphone5:cgfloat =0{
Didset {
//640 x 1136
ifDeviceutils.isiphone () && deviceutils.getscreensize (). Height = =1136.0{
Constant = Self.iphone5
}
}
}
@IBInspectable
var iphone6:cgfloat =0{
Didset {
//x 1334
ifDeviceutils.isiphone () && deviceutils.getscreensize (). Height = =1334.0{
Constant = Self.iphone6
}
}
}
@IBInspectable
var iphone6plus:cgfloat =0{
Didset {
//1242 x 2208
ifDeviceutils.isiphone () && deviceutils.getscreensize (). Height >=1920.0{
Constant = Self.iphone6plus
}
}
}
}
Usage:
Modify the current constraint so that it uses Nslayoutconstraintex, with the following effect:
Note that the user Defined Runtime attributes this column, if you remove a custom attribute, there may be a residue on this side, delete the remaining item can be removed. and the module column. If the show none indicates that using a custom class fails, it would be nice to remove the class and re-enact it.
The default is the iphone layout, so you can use a large size image on your ipad.
End
Bought this auto layout development cheats, continue to learn and think about screen adaptation aspects of the content.
"IOS" screen fit Nslayoutconstraint