iOS Question Designer script 100%x and 100%y

Discussion in 'iOS Questions' started by rfresh, Jun 18, 2019.

  1. rfresh

    rfresh Well-Known Member Licensed User

    I have an iPhone 6 and the Apple site says its screen resolution is 1334x750.

    However, my test code below returns 559x375.

    What am I doing wrong?

    Code:
    ButtonDayNight.Text = 100%y & "x" & 100%x
     
  2. klaus

    klaus Expert Licensed User

    iOS uses Points instead of Pixels.
    1 iOS point is equivalent to 1dip in Android.

    Extract from the iOS documentation.

    Points Versus Pixels.
    In iOS there is a distinction between the coordinates you specify in your drawing code and the pixels of the
    underlying device. When using native drawing technologies such as Quartz, UIKit, and Core Animation, the
    drawing coordinate space and the view’s coordinate space are both logical coordinate spaces, with
    distances measured in points. These logical coordinate systems are decoupled from the device coordinate
    space used by the system frameworks to manage the pixels onscreen.
    The system automatically maps points in the view’s coordinate space to pixels in the device coordinate
    space, but this mapping is not always one-to-one. This behavior leads to an important fact that you should
    always remember:
    One point does not necessarily correspond to one physical pixel.
    The purpose of using points (and the logical coordinate system) is to provide a consistent size of output that
    is device independent. For most purposes, the actual size of a point is irrelevant. The goal of points is to
    provide a relatively consistent scale that you can use in your code to specify the size and position of views
    and rendered content. How points are actually mapped to pixels is a detail that is handled by the system
    frameworks. For example, on a device with a high-resolution screen, a line that is one point wide may
    actually result in a line that is two physical pixels wide. The result is that if you draw the same content on two
    similar devices, with only one of them having a high-resolution screen, the content appears to be about the
    same size on both devices.
     
    Erel likes this.
  3. rfresh

    rfresh Well-Known Member Licensed User

    Thanks for that Klaus. I thought I could detect an iPhone6 vs an iPhone7 vs an iPad by checking the device screen width. I don't have all of those actual devices (only the iPhone6) so I was relying on reading the screen resolution specs.
     
  4. rfresh

    rfresh Well-Known Member Licensed User

    The iPhone6,7 and 8 all have the same screen resolutions: 1334x750. I am unsure of what to set for a new variant for these iPhones. Do I create a new 1334x750 variant or do I use what 100%x and 100%y returned: 559x375?
     
  5. klaus

    klaus Expert Licensed User

    Use the 100%x and 100%y values.
     
  6. rfresh

    rfresh Well-Known Member Licensed User

    A friend of mine let me test 100%x and 100%y on his iPhone 10.

    The iPhone 10 specs says this screen is 2436x1125. 100%x is 375 and 100%y is 724. Is this because my test app has only one variant?

    I've attached my test app.
     

    Attached Files:

  7. sorex

    sorex Expert Licensed User

    do you really need to know the actual resolution?

    if you know that the aspect ratio is 0.51 (375/724) multiply that with 4 and once with 16 then you know it leans more to 16:9 (16:8.28) than to 4:3(2.07).

    I don't use ratio variants but just place everything based on math in the actual code because I want it to look 'exactly the same' on all devices.
    The same goes if you really need totally different layouts but then you need to check that aspect ratio first and decide which way you want to go next.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice