Skip to content

Instantly share code, notes, and snippets.

@serpent7776
Last active March 18, 2018 13:15

Revisions

  1. serpent7776 revised this gist Mar 18, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pointsPixels.m
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,6 @@ - (CGFloat)pointsToPixels:(CGFloat)points {
    } else {
    pixelPerInch = 160 * scale;
    }
    CGFloat px = points / (pointsPerInch * pixelPerInch);
    CGFloat px = points / pointsPerInch * pixelPerInch;
    return px;
    }
  2. @danielcardeenas danielcardeenas created this gist Apr 1, 2016.
    29 changes: 29 additions & 0 deletions pointsPixels.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    - (CGFloat)pixelToPoints:(CGFloat)px {
    CGFloat pointsPerInch = 72.0; // see: http://en.wikipedia.org/wiki/Point%5Fsize#Current%5FDTP%5Fpoint%5Fsystem
    CGFloat scale = 1;
    float pixelPerInch; // DPI
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    pixelPerInch = 132 * scale;
    } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    pixelPerInch = 163 * scale;
    } else {
    pixelPerInch = 160 * scale;
    }
    CGFloat points = px * pointsPerInch / pixelPerInch;
    return points;
    }

    - (CGFloat)pointsToPixels:(CGFloat)points {
    CGFloat pointsPerInch = 72.0; // see: http://en.wikipedia.org/wiki/Point%5Fsize#Current%5FDTP%5Fpoint%5Fsystem
    CGFloat scale = 1;
    float pixelPerInch; // DPI
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    pixelPerInch = 132 * scale;
    } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    pixelPerInch = 163 * scale;
    } else {
    pixelPerInch = 160 * scale;
    }
    CGFloat px = points / (pointsPerInch * pixelPerInch);
    return px;
    }