Xcode - Resize Buttons with Images Proportionally for iPhone 4s, 5, 6, 6+ in AutoLayout - iphone

I designed a UI that simply doesn't scale the right way - always squeezing and stretching something. I get everything to align the right way but the scaling messes everything up. In Subviews it even gets worse...
Here is a simplified version of the UI:
http:// i.imgur.com/VIKVm5y.png
All the grey circles have images inside, should be buttons and scale proportional to every iPhone display size - so that a bigger display gets bigger buttons...
It's only meant to be for iPhones and portrait mode only.

Ok actually this was pretty simple and I feel kinda stupid I asked the question in the first place.
The solution was to lock the aspect ratio and set either the height or with equal to the superview and then edit the proportion to it in a second step until you have desired result...

Related

Auto Layout Swift 4 Xcode 9 For Multiple Devices - Am I doing it Wrong?

I am having severe difficulties finding a clear working world example of auto layout on multiple screen sizes. Most tutorials have basic stuff like a button thats centralised and then after adding constraints in Interface Builder it scales with the device. One button is simple but in my example for the iPhone 4:
There are quite a lot of labels / buttons and some that are not central. The above screen shot is exactly how I want it to look on all devices.
The app is for portrait only but I want to target all devices. I tried slowly adding constraints to items from the bottom up using a multiple of the superview to position and size items and then applying aspect ratio to UI Objects (got as far as the got it button but not the red arrow buttons) but as you can see in the next picture for the iPhone 8 plus... the white space isn't going to perfectly fill like in the iPhone 4 which will leave me with a big gap at the top.
Is there a way I can change just the iPhone 8 plus layout in Interface Builder to build a layout that caters for the extra screen size?
The iPhone 8, SE and X layouts are equally awkward with extra white space.
I tried size classes but that changes it for all phones.
Is there a way to centre what I have done so far?
How do you guys position objects in auto layout that are not centred?
Am I going about it the wrong way by applying X / Y constraints using a multiple of the superview? - same for the width. I'm only specifying widths as a multiple of the superviews width then adding aspect ratio.
I just need a real world working example I can learn the basics from or a system to create for multiple devices that I can follow. I don't want to use a 3rd party library.
I really hope someone can help point me in the right direction!
Krivvenz.

Loading levels from xml and supporting screen resolutions in Ios

I am developing a game that uses levels. The levels are made at a default scene width and height resolution.
The thing i am worried about is when the game is played on IPads iphone 5′s etc, the position of sprites loaded from the level xml files will be out of place due to the screen size.
In my case, could someone tell me the best thing to do in this situation or some advice on the approach i should take?
Also if any has experienced this, please let me know.
Thanks. :)
Generally this has nothing to do with how or where you store the level data.
These are the standard approaches, which one works for you depends on your requirements and desired results:
design each screen resolution individually (error-prone, tedious)
design for one screen resolution, then scale up or down according to screen aspect ratio (can lead to skewing as the screen size scaling for width & height are likely to be different)
design for the smallest screen resolution, then center the contents on the screen (this leaves unused areas either at the top/bottom or left/right sides)
same as above, but zoom content to fill the screen (this will remove the letterboxing, but also partially remove one side's content from the view)
In essence this is the same problem as movies have in trying to fit to screens of varying aspect ratios.
In general this is all a matter of scaling the input (positions) to a desirable output. The easiest approach is to maintain aspect ratio and allow for letterboxing. However Apple may reject letterboxing apps if nothing is done to hide the letterboxes (black areas) since Apple requires apps to support widescreen resolution, and letterboxing does not normally fall into their definition of "supporting widescreen".

Making use of the extra pixels on 1136x640 iPhone 5 Screen?

Without the 1136 launch image, apps now run in letterbox mode with black bars on either end.
If you add the Default-568h#2x.png launch image, then the app runs with 1136 pixels (in my case, in landscape mode - 1136x640).
The extra 176 pixels are all getting added to the right side of the screen in landscape mode.
Is there a way that I could have the 176 added pixels distributed 88 to the left and 88 to the right of the screen that I work with in Interface Builder?
To Explain:
If I position an 1136x640 image (to make it work it is actually a 568x320 image with an #2x version in the project) at 0,0 in Interface Builder and run it on an iPhone 5/simulator, the screen shows the entire image even though it's not entirely visible in Interface Builder since it goes off the right side of the screen.
I was hoping to place the 1136x640 image at -88,0 since it is just a background image for my app. If this was possible, I could keep all the menu buttons in their current locations and would just be able to extend my app's background to either end instead of having that area be filled with black bars in letterbox mode.
If that is somehow possible I would love to hear about it... otherwise I better get to repositioning all my buttons and other screen elements! I've recently read about AutoLayout and that is certainly something to strongly consider in any new apps going forward, but I was just hoping for a quick update to my existing apps that would letterbox the apps with additional background art provided by me instead of black bars on either end.
EDIT: Just tried to move buttons around on the screen and it appears that buttons placed on the right-most 176 pixels can't even be clicked on! So I cannot use that extra space on the right even if I reposition everything... =/
AND THEN: I tried AutoLayout, and it too ignored the 176 pixels on the right. If I positioned a button with a constraint of 20 pixels from the right side of the screen, it would show 196 pixels from the right because it's not taking into account the additional screen size that has been added.
Anybody know what is the best way to actually have art fill the entire screen of the new iPhone 5?
Thanks!
I had the same problem of not being able to access the new 176 pixels for the new iPhone. However, this is what I did and now I have access to them.
Open MainWindow.xib with Interface Builder
Select the Window
In Attributes, check Visible at Launch and Full Screen at Launch.
If you hadn't set autoresizing on any of your elements and then enable support for the 4-inch display, indeed you might not have the greatest looking views.
You can use autoresizing to set your views/elements to stretch, center and align, so you should be able to manipulate the resizing mask to do what you'd like.
Autolayout is very fiddly and in most cases overkill if you just want to support the new screen size.
Ended up creating one .xib for for the iPhone 5 size and one .xib for the iPhone 4 size. Both are connected to the same .h/.m file.

Is iPhone's Safari resolution treated differently than the rest of the device?

I have an image that is 480x270. In theory this should occupy all the space between the battery bar on top and the navigation bar at the bottom when the phone is rotated on to its side. However, inexplicably the image is displayed shrunken to where it barely occupies 1/2 the screen horizontally.
I thought perhaps the phone is shrinking the image for some reason, so I just created a div that has its dimensions set to the same size as the image and nothing in it but a background color. The phone displays this rectangle of color in exactly the same dimensions as the graphic.
So, the question is, is Safari compensating in some way and displaying things in a reduced ratio, and if so, WHAT is that ratio?! (or am I just totally out of my mind?)
Check out viewport.

White edge when orienting dark colored view?

I am just playing with an iPhone test app that orients the view when the simulator is rotated left or right. Everything worked fine when my view had a white background, however when I altered the view background to a darker color I noticed a white edge (1 pixel) around the view as it rotates. Has anyone come across this before or know how I might get rid of it. Indeed it might be an issue with the simulator that won't show on the actual device, but I just thought it worth asking for future reference.
gary
I have seen something similar before..
Go through the nib (.xib) files and make sure that all of the views have an appropriate dark background colour set, most notably the nib file which contains the "window". Click on them and set the background colour.
I've never noticed it but then again I've never tried to rotate a very dark view. There might be a small border to keep the view from visually bleeding into the status bars or other views.
Rotation and scaling in the discrete domain( as against analog) is quite difficult, because after a rotation/scaling the rotated location may not be a pixel location. You can suppress the effect by smoothening the edges, but I believe that is not implemented, and so the bug.