Avoid hardcoding iPhone screen size with programmatic view creation

前端 未结 2 1321
死守一世寂寞
死守一世寂寞 2021-02-03 10:48

I was looking up how to create a view programmatically and found the following example code:

self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

2条回答
  •  一生所求
    2021-02-03 11:19

    [[UIScreen mainScreen] bounds] or [[UIScreen mainScreen] applicationFrame]

    should be all you need to get the full screen size.

    I've only used the applicationFrame version myself.

    (I also suggested [UIHardware fullScreenApplicationContentRect] but that was from some very old code - don't use it)

提交回复
热议问题