Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoLayout labels getting cut off on right side of screen

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: enter image description here

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. enter image description here

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:

enter image description here

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!

like image 717
Realinstomp Avatar asked Oct 29 '14 21:10

Realinstomp


1 Answers

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.

like image 184
matt Avatar answered Oct 19 '22 02:10

matt