Detecting iPhone 6/6+ screen sizes in point values

前端 未结 16 2266
独厮守ぢ
独厮守ぢ 2020-11-29 15:44

Given the newly announced iPhone 6 screen sizes:

iPhone 6: 1334h * 750w @2x (in points: 667h * 375w)
iPhone 6+: 1920 * 1080 @3x (in points: 640h * 360w)
         


        
16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 15:48

    All three devices have (pretty much) the same number of points per inch. So your images will automatically be the same physical size.

    Use [[UIScreen mainScreen] bounds] to get the total number of points on the screen. Divide by 163 to get the approximate size in inches if you really want it.

    Notice that the 6+ does not return 1080p because it doesn't render to a 1080p buffer. It renders such that output is approximately 160 points per inch, using @3x assets.

    No need to second guess.

    E.g. if you write this code:

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 163, 163)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    

    You'll get a view that is pretty much the same physical size — one inch square — on all iOS devices.

    Apple has already done the hard work, so you don't have to.

提交回复
热议问题