如何确定分组 UITableView 的边距(或者更好,如何设置)? [英] How to determine margin of a grouped UITableView (or better, how to set it)?

查看:19
本文介绍了如何确定分组 UITableView 的边距(或者更好,如何设置)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分组的 UITableView 在视图边缘和表格单元格之间放置了一个边距.令人讨厌的是(对我而言)这个边距是视图宽度的某种函数.

The grouped UITableView places a margin between the edge of the view and the table cells. Annoyingly (for me) this margin is some function of the width of the view.

在我的应用程序中,我有两个不同宽度的 UITableViews,我希望它们对齐单元格边缘.

In my application I have two UITableViews of different widths that I am looking to align the cell edges of.

有可能获得这个保证金吗?或者更好的是可以设置这个边距吗?

Is it possible to get this margin? Or better is it possible to set this margin?

干杯,--本

推荐答案

通过创建(并使用!) UITableViewCell 的子类,您可能会实现您想要的.只需在 layoutsubviews 中移动 contentview 和 backgroundview,如下面的代码示例所示,它将单元格的可见部分向右移动 20pt.

By creating (and using!) a subclass of UITableViewCell, you can possibly achieve what you're looking for. Just move the contentview and backgroundview around in layoutsubviews, as in the code sample below which shifts the visible parts of the cell 20pt to the right.

- (void) layoutSubviews
{
    NSLog (@"Cell/contentview/backgroundview before:\n%@\n%@\n%@", self, self.contentView, self.backgroundView);
    [super layoutSubviews];
    CGRect frame = self.backgroundView.frame;
    frame.origin.x += 20;
    frame.size.width -= 20;
    self.backgroundView.frame = frame;
    frame = self.contentView.frame;
    frame.origin.x += 20;
    frame.size.width -= 20;
    self.contentView.frame = frame;

    NSLog (@"Cell/contentview/backgroundview after:\n%@\n%@\n%@", self, self.contentView, self.backgroundView);
}

这篇关于如何确定分组 UITableView 的边距(或者更好,如何设置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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