如何为分组模式自动调整 UITableViewCell 子视图的大小?
我对 UITableViewCell 进行了子类化以添加额外的标签和一些颜色选项。
我将标签添加为 [the cell].contentView 的子视图。当您将 UITableView 设置为“分组”模式时,它会从父视图的两侧缩进。默认子视图会移动相应的量,但您添加的子视图不会移动。我将添加视图的 autoResizingMask 设置为每个可能的值,但没有一个正确考虑减小的宽度。
标签子视图的矩形在 initWithReuseIdentifier 中创建,如下所示:
CGRect specialtyRect = CGRectMake(IMAGE_THUMBNAIL_SIZE + 3, 3, self.contentView.frame.size.width - IMAGE_THUMBNAIL_SIZE - 6, 16);
self.specialtyLabel = [[UILabel alloc] initWithFrame:specialtyRect];
[self.contentView addSubview:specialtyLabel];
有谁知道为什么红色子视图的行为是这样的,如何使右端正确缩进以匹配减小的宽度,同时左端保持与 imageView 的正确偏移?谢谢!
我没有使用 UITableViewController,也没有从 XIB 加载这些单元格。
I've subclassed UITableViewCell to add an extra label and some color options.
I added the label as a subview of [the cell].contentView. When you set a UITableView to "grouped" mode, it's indented from the sides of the parent view. The default subviews are moved a corresponding amount, but not ones you add. I set the added view's autoResizingMask to every possible value, but none takes the reduced width into account correctly.
The rect for the label subview is created in initWithReuseIdentifier as follows:
CGRect specialtyRect = CGRectMake(IMAGE_THUMBNAIL_SIZE + 3, 3, self.contentView.frame.size.width - IMAGE_THUMBNAIL_SIZE - 6, 16);
self.specialtyLabel = [[UILabel alloc] initWithFrame:specialtyRect];
[self.contentView addSubview:specialtyLabel];
Does anyone know why the red subview is behaving this way, and how to make the right end indent correctly to match the reduced width while the left end remains correctly offset from the imageView? Thanks!
I'm not using a UITableViewController, and I'm not loading these cells from a XIB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论