How to get iPhone screen size programmatically? [duplicate]

喜你入骨 提交于 2019-12-03 06:09:42
Midhun MP

You can use:

CGsize screenSize      = [[[UIScreen mainScreen] bounds] size];
CGFloat widthOfScreen  = screenSize.width;
CGFloat heightOfScreen = screenSize.height;
jcesarmobile

You can know it with the UIScreen properties

[[UIScreen mainScreen] bounds].size.height;
[[UIScreen mainScreen] bounds].size.width;

for iPhone 5 and iPod touch 5gen the height is 568

for other iPhones and iPods the height is 480

Edit: on iOS 8 the height and the width deppend on the orientation, so this sizes are for portrait, on landscape this sizes will be for the width instead. So, best choice is to read both and do the max

You can get the size of iPhone screen as

CGSize size = [UIScreen mainScreen].bounds.size;
UIScreen *screen = UIScreen.mainScreen;

It has all you need including bounds and scale (may be different for retina and non-retina).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!