正确的方法来确定分组自定义单元格的UITableViewCell宽度? [英] Proper way to determine UITableViewCell width for grouped custom cells?

查看:144
本文介绍了正确的方法来确定分组自定义单元格的UITableViewCell宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过代码创建的自定义UITableViewCell(不是Interface Builder)。我有依赖于单元格宽度的子视图:有一个标签总是需要在单元格的右边缘内。单元格显示在分组的表格视图中。

I have a custom UITableViewCell created through code (not Interface Builder). I have sub-views that rely on the width of the cell: there is a label that always needs to be just inside the right edge of the cell. The cells appear in a grouped table view.

我最初硬编码的值与iPhone一起使用,但现在我将应用程序转换为通用二进制文件iPad上的分组表格视图中有硬编码的数字。

I had originally hard-coded the values to work with iPhone, but now I'm converting the app to a universal binary and the hard-coded numbers are out for grouped table views on the iPad.

是否有正确的方法来获取单元格的宽度?框架返回整个屏幕宽度,这使我的标签不合适。或者我应该硬编码两组值,一组用于iPhone,另一组用于iPad?

Is there a proper way to get the width of the cell? The frame returns the full screen width, which is throwing my labels out of place. Or should I just hard-code two sets of values, one for iPhone and one for iPad?

任何建议都将非常感谢。

Any suggestions would be greatly appreciated.

推荐答案

您应该可以从单元格的 contentView 子视图中获取相应的尺寸。但是,您通常只需在子视图上设置大小和自动调整遮罩,这样无论特定宽度到底是什么,单元格都会正确显示。

You should be able to get the appropriate dimensions from the cell's contentView subview. But you should normally just set the sizes and autoresizing masks on your subviews so that the cell will appear correctly no matter what the specific width ends up being.

这篇关于正确的方法来确定分组自定义单元格的UITableViewCell宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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