Search Unity

GUI.Button on iphone 3 versus iPhone 4

Discussion in 'iOS and tvOS' started by lesfundi, Feb 16, 2011.

  1. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    if you create a button with the height 44 pixels and you run this on the iPhone 3 the size is okay.
    When you run this on the iPhone 4 it looks very small due the face the iPhone has a bigger resolution.

    Now do you still need to create line of code to check the resolution and create another button with pixel hight 88 if
    is iPhone 4? Or are there any other options to run the resolution of iPhone 3 on iPhone 4? Any other suggestion?

    c
     
  2. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    in build setting you have some option where you can set the reso you want , for 4g if you select low / standard resolution you will get things showing at 3g res
     
  3. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    The iphone4 resolution is exactly twice the resolution of the previous devices, which makes things a little easier. What I typically do is define an int for the resolution modifier and multiply it into anything that needs to scale depending on resolution. This includes textures, GUI elements, etc.

    Code (csharp):
    1. private int resMod = 1;
    2.  
    3. void Start()
    4. {
    5.    //detect higher resolution display
    6.    if (Screen.width > 500)
    7.       resMod = 2;
    8. }
    9.  
    10. void OnGUI
    11. {
    12.    GUI.Label (new Rect( 10 * resMod, 10*resMod, 100*resMod, 20*resMod), "Hello world");
    13. }
    Obviously this is not the most performant example, as I could have declared the GUI rectangle in Start and not had to create a new rectangle every frame, but it illustrates the usage of the resolution modifier.
     
  4. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    Just position your buttons relatively to screen dimentions, that avoided me alot of pain myself....