简体   繁体   中英

On iOS, why is 100 “points” a different size on different devices?

It was my understanding that if you specified a size of 100 points in iOS, that it should be interpreted as "100 density independent pixels", such that it would take up the same amount of physical space on the screen, independent of the device.

So if 2 devices had the same pixel density, each mapping 1 point to 2 pixels, 100 points would take up 200 pixels on those devices and they would appear to be the same physical size. If Device_B has 2x the pixel density of Device_A (and device A is 1:1 pixel:point) then 100 points would take up 100 pixels on Device_A, and 200 pixels on Device_B which would consume the same physical screen real-estate. Am I missing something?

I tested a UILabel of size 100x30 on an iPhone 6 and an iPad Air 2, and they definitely don't take up the same physical size on the screens - the 100x30 label on the iPhone 6 screen looks to be about 2/3 the same physical size compared to the iPad.

Here is the very simple test code

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor blueColor]];

    UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
    testLabel.text = @"Test Label";
    testLabel.backgroundColor = [UIColor greenColor];

    [self.view addSubview:testLabel];
}

I've attached an image of the 2 physical devices rendering the same label (iPad left, iPhone on right).

在此处输入图片说明

Ppi is pixel per inch where pixel means physical device pixels.

iOS screen scale factors 1x, 2x, 3x means only relation between physical pixels and screen points (density independent pixels). What even not 100% correct for iPhone6&7 plus where screen points rendered in x3 scale pixels and then this is downsampled with factor 1,15 to real screen pixels.

iPad Air 2 ppi = 264 iPhone 6 ppi = 326 Both have scale factor 2x. So label with size 100x30 will have size 200x60 in physical pixels on each of devices. And

200/264 x 60/264 = 0,76 X 0,23 inches on iPad

200/326 x 60/326 = 0,61 X 0,18 inches on iPhone6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM