Xcode: Autolayout not working correctly - ios

I've got this weird bug in my application. When I load up my app on the simulator or an iDevice and I go to the pageControl page the layout is doing weird things.
I use the pagecontrol pages for a calendar view, so if I load it up I see this
That's all good, but when I scroll down (or up) the layout changes a bit
If the scrolling is done and I'm on the next page the layout readjust itself and is then in it's good state
So I don't know where this has gone wrong but of someone knows I would be very grateful!
I'm using auto-layout in this page and on every simulator size I get this same problem.

If you are using auto-layout to position the vertical line, then I suggest you base it's position off of the left side of the cell rather than the right side of the label to the left of the cell.

Related

How to set constraints to a tableView into a viewController?

I'm trying to place a tableView in a viewController, but im not able to constraint properly the tableView, i'm doing the usual things, i'm sticking the leading, trailing and bottom constraints to superview, and some space to the top superview. But as shown in the preview, table view does not look to be constrained, the effect that it brings for me is that when i put elements into content view, they extend along the right side i can not see them for small devices. Does anyone know what could be happening?
Thanks in advance!
StoryBoard Tree
After spending long time checking what happened i figured out that there is a Xcode fail on it, i run it in simulators and real devices and it works perfect, the bad thing is that everything i inserted into that view does not look as it should in the preview, but again, in simulator everything works fine. So, preview is not always as trusty as i expected and now i know it

iOS app only showing half in simulator

I am trying to develop a simple app with one screen for iOS and am running into a strange problem. Only half of the app is showing up. For example I have a screen with just one button in the center of the screen. When I run the app in the simulator I only see half the button and I cannot move it either.I can scroll the view in the simulator vertically but not horizontally. I am stumped. Will appreciate any pointers.
I'm pretty sure you built your view using the main storyboard and put everything in the middle of it. The main storyboard is set to take all iOS format into account, iPhone and iPad. If you want your app to appear centered on your iOS device, you need to constraint the position of your different UI objects, using Auto Layout. That way it would appear centered automatically, whatever is the device you're using
I reckon you've got AutoLayout turned on... but haven't set any constraints on your controls yet.
Try the following test:
Go into your Storyboard file.
Click on a blank area in your storyboard, then on your screen (so the border of your screen is blue - not black or gray).
In the menu bar, click on Editor \ Resolve Auto Layout Issues, and then "Update Frames".
Alternatively, you can click on the following button, and select "Update Frames" from there (it doesn't matter which one):
When you do this, where does your "one button" end up ? Does it suddenly disappear off the screen, have a negative X or Y position, or a width/height of 0 ? If so, then AutoLayout is your problem.
With XCode 6.1, Apple has put a gun to developers' heads and demanded that when you add an object to a Storyboard, you must - straightaway - add some constraints to it.
I had this issue when I first upgraded to XCode 6.
I would add, say, a View to a screen, stretch it to a particular size, then drag a second control (perhaps a Label) onto the same screen. Suddenly, my View would resize itself to a height/width of zero, or be positioned way off the side of the screen... huh ?!
To get around this, when you add a control onto a Storyboard, you must add sufficient constraints to really let XCode calculate where to position it, based on which device/orientation the device is running on. And, yes, you sometimes need to do this straightaway before XCode ridiculously decides to mess up your control's position or size.
I really do loathe XCode. This isn't the way a development environment should behave in 2015...
If I get your point of problem then
I m sure the problem is you have auto layout and size classes enabled.
check if you have Auto layout and size classes enabled ....???
If yes then you haven't set the constraints accurately. set the constraints for the UI Objects to show on your desired position in screen.

Detail Text and Accessory Don't show [duplicate]

I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.

UILabel in different position for 2 different screen sizes

I have a UILabel that i placed in the top left corner of the screen in the Storyboards. I disabled "Autolayout" and it works perfectly fine on the iPhone 5 screen. The problem comes when i try them on any of the smaller screens like the iPhone 4. The label is then placed on the bottom right corner. After this issue, i tried to programmatically 'fix' the position in the "viewDidLoad" method of the view controller, but it stills moves position and the problem continues.
Ive been scratching my head about this for a while!
Any help would be appreciated.
I would suggest that you turn autolayout back on. If you get the constraints right, this situation (two different screen sizes) is exactly the sort of thing autolayout is really good for. There's a very good reason why Apple migrated autolayout from OS X to iOS at exactly the moment the iPhone 5 screen appeared on the scene!
try to fix it at viewWillAppear
Go to the utilities panel, click the tab "Show size inspector", and change the autosizing. Then drag your component in your storyboard's view so that it stays in one of the "borders". If you do not need to support older iOS versions, I'd recommend you to figure the proper way with auto-layout though.

Developing on an iPod iTouch - UIView Issues

So I've been using this site for a lot of my questions. I'm very good with Googling problems and debugging even the worst error code, but this is something rather basic that I'm not able to figure out.
My UIView compared to what I actually see on the iTouch has always been a bit different. I'm not sure if this is xCode's IB just having larger graphics for its buttons, but in general there is this 20px height difference, to the point where if I set a button at the bottom of the UIView, it gets cut off. (I thought it was supposed to be 320x460..)
Normally I shrug this off because it hasn't been an issue till I've started to put scrolling into place with the login screen. xCode claims my view is 320x548, my app says its 320x480. If I resize my scroll size to 320x480, the view shrinks on the iTouch, leaving a large gap.
I have been using UIViews in the IB rather then a ViewController because I'm subviewing mixed with some nav control.
Is there something that I'm doing wrong?
http://oi49.tinypic.com/rrnjit.jpg (when first loading)
http://oi50.tinypic.com/j8matu.jpg (scrolling down about 20 px..)
You need to make correct use of springs and struts or Auto Layout. You are probably designing your app for the 4 inch screen - in your Storyboard, there is an option to see how it would look on a 3:5 inch screen. Press that.
For more info, Google Auto Layout.

Resources