Align navigation buttons on all devices - ios

As you can see on the picture, the bar on the bottom is using 5 different buttons (the icons). When I run my program with an iPhone 5s everything works fine. But on other devices such as the iPhone X, etc., the images floats to the left side. Does anyone know how I can add constraints to the buttons to make them stay where they are on all devices?
UPDATE:
So, if you see the navigation-bar from the iPhone 5s, you see it's like "perfect" aligned to each other. And that's how I want them to be on ALL devices. If you take a look on the iPhone XS you can see that all the buttons is to the left. I also added "Flexible Space Bar Button Item" between all of the buttons, and it was a lot better, but they "Doghead" is not in the center of the phone, which I want.

You need to add a UIBarButtonItem with a system type of .flexibleSpace between each of your other buttons. This will force all of the buttons to be equally spaced across the width of the toolbar. To ensure that the middle button ends up in the center of the toolbar, all of the images need to be same width.
If you want all of the buttons grouped together in the center of the toolbar, then just add a flexible spaced item before the first button and another after the last button.

Related

Positioning a UISegmentedControl in a button bar

I'm trying to use a UISegmentedControl as a custom right button bar item. Using Interface Builder, when I drag the control into the navigation bar, it gets sized to be quite wide (too wide, considering the segment contents):
I've tried setting the widths of the segments to something that I think looks good and the overall control resizes, but it is pinned to the left side of the original space it was allocated. I can't seem to find a way of moving it from there. Here's a picture of what this looks like in IB in landscape:
and here's what it looks like running on an iPhone 7 Plus simulator in portrait mode:
As you can see, the segmented control is positioned way too far toward the center.
I tried a hack (suggested in this thread) of embedding the segmented control inside another view, leaving the containing view to be full width of the bar button item and constraining the segmented view to be on the right of it's container. That gets it over to the right, but here's the effect of running that on an iPhone 7 simulator (somewhat narrower than the 7 Plus):
Here the problem is that the title, which is supposed to be centered, has been pushed off to the left. I assume that this is because the (transparent) bar button item is taking up so much more width than what is needed just for the segmented control.
Is there some way of getting the right button area of the navigation bar to simply be smaller?
My steps are below:
1.Drag the segment control to navigationbar:
2.Change the segment width:
3.iPhone7 & iPhone 7Plus all looks good:

Double Navigation Bar in View

I have a problem with a "double" navigation bar in a screen of my iPhone app.
Starting position:
Xcode 8, Swift
I have a TableView with static lines that is embedded in a navigation controller. From the first cell I then call a screen (Segue Show Detail), which is very complex (labels, text boxes, buttons, etc.). When I execute the "Reset to suggested constraints" function on the screen, the screen is supplied with "generated" constraints. This is still clear. When I run my app in the simulator (iPhone 6) or my own iPhone 6, I see on the above screen a status bar, then my right navigation bar (Back button, title) and below an "empty" 2.Navigation bar. This decreases the screen down and is no longer fully visible. If I delete the constraints for the screen with the "Clear Constraints" function, the screen in the simulator (i6) looks good as I develop in the storyboard for the iPhone 7. But when I connect my own iPhone 6 and test, the screen does not fit completely to my iPhone, because right and down is something truncated.
I suspect the error in the "generated" constraints.
Now my question:
How can I check the generated Contraints (well over 100) for errors?
In the Internet and the forum I found nothing, which could help me.
Workaround for me:
The top UI element on the screen is a label across the entire width of the screen. For this label, I set a constraint manually, in addition to the generated constraints
Label.top = Top Layout Guide.bottom + 44,
whose value I then change to the value
Label.top = Top Layout Guide.bottom
This causes the label to slide directly below the status bar in the storyboard. The navigation bar is then no longer visible in the storyboard. This makes the placement of UI-Elements at the bottom of the screen somewhat more difficult because you do not know exactly which space is still available.
The display in the simulator (i6) and on my iPhone 6 looks however through the workaround ok.
For your help I would be very grateful.
Greeting Reinhard

Is the iPhone touch surface larger than the screen?

[I have a weird iPhone bug, only tested on an iPhone 5S.]
My app has two panes, each of width 320px. When the right pane is fully visible (and the left pane fully hidden), I can sometimes tap a button on the left pane. This button touches the left pane's right border. It is hard to trigger the bug, the trigger surface seems to be on the edge of the phone.
If the iPhone 5S touch surface is no larger than the 320px screen, this should not be possible.
Is the iPhone 5S touch surface larger than the 320px screen? I.e., do the iPhone 5S screen edges have a few extra pixels of touch sensitivity?
It's a problem with your interface, not the hardware. The touchable bounds region of the button may be bigger than the apparent visible drawing of the button. Thus, it may be invisibly sticking into your screen from the left. To confirm this, try making the invisible visible, by giving the button a background color that shows its actual dimensions.
Oh, one more thing. You may be positioning your panes off by one pixel. That would be enough to bring one pixel width of the button onto the screen - and thus would make it, with difficulty, tappable.
Since both panes will never be visible simultaneously, why not avert this entire issue by adding some space between the panes?
You can check pane (button) location by printing it's frame into console. Now you know for sure, if button edge is on-screen or not:
NSLog(#"%#", NSStringFromCGRect(button.frame));
Btw I'm wondering, if this could be related to iOS7 feature "(New gesture - Swipe left to right - as shortcut for Back button in UINavigationController in old app)"?

Custom UIButton alignment with respect to background image issues in xcode 5 on iPhone 4s and 5 - addition of constraints does not fix the issues

I am having issues with UIButton with background images. When clicking on a button when running the code in simulator and in iPhone 4s and 5, a button seems to be selected even when I press an area outside the button
I have a very simple UI with an image, followed by another image (Login), followed by 3 custom buttons (Facebook, Email and Signup) and an image after that at the very bottom.
Note -
1. I have each button size (width and height) equal to the size of the background image. So if the background image is say 100 by 20, the button would be 100 by 20. Also, I have Autolayout checked and the image to AspectFill the UIButton in the IB.
I have a UIView within the Superview. All the UI elements (images, UIbuttons with background images) are placed in the UIView.
I have constraints on the UIView for width and height, so that it remains the same in iPhone 4s and 5. I also have constraints to ensure that the UIView is horizontally and vertically centered.
Within the view, I have constraints on each UI element's (images and UIbuttons with images) width and height, so that it remains the same in iPhone 4s and 5. I also have constraints on each elements Y location. So, I have a constraint that the first image is X distance from the UIView's top line. Then, I have a constraint that the first button is Y distance from the image on top. Then, I have a constraint that the second button is Z distance from the first button above it. I, then, have a constraint that the bottom-most label is A distance from the bottom line of the UIView. And I have a constraint that the third button is B distance above the bottom-most label. The idea is to ensure that all these elements are in the center of the screen in iPhone 4s and iPhone 5 (since the UIView will move to the center due to the constraints on it and the UI elements within it will move to the center along with it since their constraints are relative to the UIView).
The project supports iOS 6, 6.1 and 7.
I started developing and testing using iPhone 4s. The buttons seemed to be working fine on it. Then I connected iPhone 5 and, on compiling, I found that the buttons' clickable area and the buttons' background image did not overlap anymore. I re-connected iPhone 4s, cleaned the project, built it again and ran it (both on the simulator and on the device) to find that the buttons did not work anymore. On clicking on an area outside the button, the buttons were getting selected. What was also strange was that in some cases, when I touched a button (ie. Facebook), the button below it (i.e. Email) was getting selected.
So, in summary, it worked fine in iPhone 4s. On connected, iPhone 5, it seems that the buttons stopped working properly. On reconnecting iPhone 4s, the buttons no longer functioned properly. I tried removing all the UI elements and restarting the build (in same view controller in the same storyboard), tried creating a brand new view controller in the same storyboard, but with no luck. I have had to start the project all over again to have it function in iPhone 4s. So, to me, it seems that something is corrupting the storyboard, to an extent that it cannot be fixed again!
I have highlighted the UIView in gray for your reference.
Please see the images for reference -
Basic screen with UIView grayed out and no touch
Basic screen with UIView grayed out and trying to click Facebook button -
Basic screen with UIView grayed out and trying to click on the non-clickable image below the Signup button -
Not sure if anyone has faced such problems But, I would love to understand it and fix it now since it is a reoccurring issue and do not want to face it when most of my project is complete as it seems to completely corrupt the storyboard, leaving me to start the project all over again!
Please help.
Did you try calling sizeToFit method on all the buttons?

Legacy iOS app not stretching properly

I have a layout issue. I'm trying to make a legacy 3.5in app work on iPhone 5. As soon as I give it the Default-568h#2x.png splash image, the whole app gets aligned to the top of the screen, leaving a huge white gap at the bottom. The autosizing struts and such seem to be set properly (not using Autolayout at the moment), but the thing doesn't stretch to fill the screen. I'm not sure where to look next. I just want my poor tab bar to be at the bottom!
Since you're not using AutoLayout, now is a great time to start. Xcode 5 makes setting constraints a simple exercise.
I suspect that your tab bar frame is hard-coded to certain x, y, width, height coordinates which work well on the 3.5" screen. You can also see how your view renders on taller screens by pressing this button in the Xcode 5 Interface Builder:

Resources