假设我在iphone 5上有一个44px x 44px UIView。将它转换为iphone 6和6 plus的等效像素大小的公式是什么?
就像88 x 88& 132 x 132还是什么?
如果iPhone 5上有44 x 44 UIView,我怎样才能在6和6上使用相同的视图,并按比例占用屏幕上相同的空间
答案 0 :(得分:1)
+(float)convertWidthToEquivalentDeviceWidth:(float)width{
float sizedToWidthDesignedTo = 320.0f;
float actualWidth = [[UIScreen mainScreen] bounds].size.width;
float percentWidth = actualWidth/sizedToWidthDesignedTo;
return width * percentWidth;
}
+(float)convertHeightToEquivalentDeviceHeight:(float)height{
float sizedToHeightDesignedTo = 568.0f;
float actualHeight = [[UIScreen mainScreen] bounds].size.height;
float percentHeight = actualHeight/sizedToHeightDesignedTo;
return height * percentHeight;
}
答案 1 :(得分:0)
您可以获取屏幕的宽度并将其划分为您想要的数字,这样您就不需要为每个设备执行代码:
viewWidth = [[UIScreen mainScreen] bounds].size.width / scaleOfYourChoice
答案 2 :(得分:0)
设置顶部,前导,尾随空格和宽高比的约束。
前导和尾随约束将使您的视图在较大的手机上更改宽度,宽高比约束将相应地调整其高度。
答案 3 :(得分:-1)
这是你做的:你将框架设置为44x44。然后你什么都不做。 UIKit坐标不是像素;问题是为你处理的。
如果您对一个点内有多少物理像素感到好奇,请使用-[UIScreen nativeScale]
。这实际上是你的UIKit坐标乘以制作像素的数字。
如果您希望自己的视图始终是36%的可用空间,请使用等宽NSLayoutConstraint
,乘以0.36
。