Label not pining to the right of a tableview cell - ios

I'm trying to pin the points label to the right of a tableview cell.
Problem is when I pin to the bottom, top and right and then I change the size of the screen, the pin doesn't work.
I have been watching loads of videos and articles about auto layout, and I really couldn't find out why it is not working.
This is how I setup the Label 90 on a iPhone 8 screen
So to achieve this I set these constraints
But when I change to an iPhone 8 Plus screen, this is the result, the label 90 was dragged to the left
And when I go back to iPhone 8 screen, the label is not even showing on the screen

Your constraints seems to be right to see on all devices as you are keeping left (trailing) to 6, which is constant and will work same on all.
Please run on simulator, preview will only works better on same device to same preview, not otherwise as it doesn't do proper constraint like in run time.
Most important is to use UI debugger if any view is not placed well to get better idea where exactly the problem is.
Thanks.

Related

Alignment issues in iPhone X

In my application i have a screen which contains close button on top and program information at bottom and both trailing,leading,bottom and top constraints related to safe area.
Button width and height is 1:1. Program info area height is 0.25 of view height. In run time adding avplayerviewcontroller view on screen whose height is 75% of self.view.It's working fine in all device except iPhone X. If i launch app in landscape then alignment is fine and if I change orientation I can see 44 pixels as x value. If I launch app in portrait first then portrait orientation values are correct if I change orientation to landscape then 44 pixels top(y) value is adding. I am not getting how to fix this issue. Please guide me.
[![enter image description here][1]][1]
I guess your problem is that you have defined constraints in percentages, which might be an issue. When you rotate the screen the mid section might be too small. Have you tried the rotated layout in interface builder to see what is happening? Defining layouts with constraints is relatively easy in interface builder and you can test the layouts as well.
If you programmatically set the constraints, it is hard to find out where it went wrong. If you have one ambiguous constraint, the whole screen can be weird.
If you need to make programmatically set constraints, you should make a test setup in interface builder and implement the good setting in the program code, when everything works as planned.
I have checked your storyboard and I think the issue might be that you have two safe area defined. One outside the containerview and one inside. What you put inside the container view, might be wrongly calculating the constraints inside.
Try to take out this checkbox and try it again.

AutoLayout (Y-Constraints for different iPhones)

The problem I'm having is that the y-size of the iPhone 4 is much smaller than the y-size of the iPhone 5 & 6(+).
If I want to support both devices I can use almost only half of the screen of the iPhone 6(+) because if I use the whole screen and add y-constraints to the top and bottom it does not work for the iPhone 4 since the constraint lengths are way too big.
How can I use the whole screen of the iPhone 6 and similarily use the full screen of the iPhone 4? Is there anything I'm missing?
I watched a tutorial but the tutor only uses center-y as constraint.
why is it necessary to set a bottom y-constraint?
otherwise, you could put everything inside a scrollview (with scroll enabled and with all the y-constraints you want at top and bottom between the scroll view and the main view), and inside the scroll view you can put the previous top and bottom y-constraints
if you use size-classes, you should be able to create a specific layout for iPhone 4 and another one for iPhone 5-6+

constraints doesnt keep it in the middle

When I add an image and constraint it to remain in the top-half center of the screen; I would like it to work with all iPhones except it doesnt,.the problem is it only works with iPhone 4 portrait and landscape that I have but when I change the iPhone to iPhone 6 it doest stay in the middle, does anyone know why?
To geta an element in the middle of the screen here are a few tips:
Ensure you drag the object in to the middle of the screen (Horizontally). You will notice guideline's appear up the screen.
Set the constraints on the item which include 'Set Horizontally in container' & Set a top constraint only (You may want a height wand width also, experiment with this.
For an image make sure that you have set your fill property for your application. (Aspect Fill etc)
A good tip to get used to auto layout is to set your view controller to iPhone 4 and design on that (With constraints of course)
Auto-Constraints are rubbish, create them yourself!

Auto layout: Xcode 6: Centering UI elements

I'm using Interface Builder in Xcode 6 to make an app and am having trouble getting the text fields and button to centre on the screen for different size screens.
I thought it was a matter of selecting horizontal and vertical centering in container but it doesn't seem to be that when I try it in auto layout. Actually I've tinkered around a bit and I still haven't got it.
I just want to be able to see all of my button and text fields for any size iPhone screen and right now simulator is only showing part of these UI elements like this:
I also want to do this in storyboard and not in code as I'm not at the level of doing this in code yet.
Step 1: Make sure your size class covers all the iPhone screen at least in portrait view. So, change the size class to "wCompact hRegular".
Step 2: After setting the size class properly, add the UITextFields and UIButton to your storyboard. To me, it looks something like-
Step 3:
Before, you start adding constraints, you need to remember two things-
a. Your element(UITextField, UIButton, UIView or any component) needs to know its starting position unambiguously, and
b. Your element needs to know its size meaning, its height and width.
In this case, as you want to centre your elements, I am just assuming that it needs to be centred starting from 10 scale from the left edge and should end 10 scales away from the right edge of your iPhone screen. Now, that means, it's width will be different based on the screen size, but its height will be same.
So, I just add the constrains following way for the 1st text box-
Notice, in the size inspector, I set the text box's starting point, x and width in a way that it is 10 pt away from left edge and 10 pt away from the right edge. Don't worry, it's just simple math.
For the 2nd textField, I add the constrain, the same way-
Lastly, for the button, the constrains are following-
Now, you are good to go. Everything is centered.
By using your size class selector in the bottom of the storyboard window, set you sizes as any width and any height and then follow the below auto layout constrains. It will work for you.
First select the view you want to set the auto layout, and then select the pin option from the right bottom corner of your storyboard and then add the constrains as shown in above picture and click button Add 4 constrains
Repeat the process for all views and set the constrains as Fix the top, bottom, left and right constrains of all views except the last button that should be fix from top,left,right and fixed height.
You need to make use of the size class selector in the bottom of the storyboard window.
So for an iPhone 6 or 6 Plus in portrait you would choose a compact width and regular height like this:
And then you would do whatever auto layout stuff for the given device there

IOS7 Tableview autolayout not work

Oh, I am having trouble with AutoLayout in IB(xcode 5, ios7), an IPad project.
Here is a view hierarchy in my project.
UIViewController->UIView->UITableView->UITableviewCell->UILabel。
And I add some constraints to UILable, (1.pin height, 2. Pin leading space to superview 3.pin trailing space to super view, 6 pin top space to superview.). But when I look in the portrait mode, I think it should change its' width to keep 2 and 3 constraints, but it didn't, can anyone give me a suggestion what should I do.
Thanks a lot!
Here is my screen shot in portrait mode and landscape mode.
I suppose I'm right when I say that you obtain the second screenshot when you select Landscape for the Orientation in the Simulated Metrics of your view controller. As the title of this section suggests, it's a simulation (might be different at run time). The warning message you have might be saying Frame for **** will be different at run time. Have you tried to run your app? Have your labels wrong positions/sizes ?

Resources