AutoLayout标签在屏幕右侧被切断 [英] AutoLayout labels getting cut off on right side of screen

查看:138
本文介绍了AutoLayout标签在屏幕右侧被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中使用自动布局自定义表视图单元格。

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:

在Xcode中调试。不知何故,Simulator中显示的内容与Xcode调试中显示的不同。

Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.

这是我显示的TableView的宽度:

Here's the width of my TableView shown:

更新:
这里的问题与用户亚马在接受的答案中所说的相关,但是我想让Q& A更清楚一点,因为我已经找到了其他遇到此问题的人。

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.

在他最初的评论中,他提到了Xcode View的调试,这很棒,而且我能够深入了解一点。它被称为辅助编辑器:设备预览,您可以在其中查看屏幕上的内容的布局和图层,以查看是否有标签重叠或根据其运行的设备离屏。如果要检查多个设备大小,只需点击此图片左下角的加号图标即可。

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.

这个帮我找到了TableView的重叠层和大小调整问题。我能够看到每个设备尺寸的样子。

This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.

有时候使用Pin菜单也有帮助。有时标签可以在屏幕外运行,因为它不知道单元格的约束取决于设备大小。因此,如果标签基于横向布局,但您的标签可以在屏幕外运行,但设备是iPhone 5,例如在肖像中。这是Pin菜单:

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.

这篇关于AutoLayout标签在屏幕右侧被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆