Objective c 如何消除分组UITableView的左右边距

Objective c 如何消除分组UITableView的左右边距,objective-c,ios,uitableview,Objective C,Ios,Uitableview,如果我有一个分组的UITableView,它的边缘会有一个浅灰色的边框/缓冲区。有没有办法知道这个缓冲区有多大,或者等效地说,它里面的实际白色单元格有多大?这就是如何消除分组UITableView的左右边距的方法。只是UITableViewCell的子类。请注意,如果希望边距不是0,只需更改setFrame方法以满足您的需要 //In CustomGroupedCell.h #import <UIKit/UIKit.h> @interface CustomGroupedCell :

如果我有一个分组的UITableView,它的边缘会有一个浅灰色的边框/缓冲区。有没有办法知道这个缓冲区有多大,或者等效地说,它里面的实际白色单元格有多大?

这就是如何消除分组UITableView的左右边距的方法。只是UITableViewCell的子类。请注意,如果希望边距不是0,只需更改setFrame方法以满足您的需要

//In CustomGroupedCell.h
#import <UIKit/UIKit.h>

@interface CustomGroupedCell : UITableViewCell
@property (nonatomic, weak) UITableView *myTableView;
@end




//In CustomGroupedCell.m
#import "CustomGroupedCell.h"

@implementation CustomGroupedCell
@synthesize myTableView = _myTableView;

- (void)setFrame:(CGRect)frame 
{
    frame = CGRectMake(- [self cellsMargin] , frame.origin.y, self.myTableView.frame.size.width + 2 *[self cellsMargin], frame.size.height);
    self.contentView.frame = frame;
    [super setFrame:frame];
}

- (CGFloat)cellsMargin {

    // No margins for plain table views
    if (self.myTableView.style == UITableViewStylePlain) {
        return 0;
    }

    // iPhone always have 10 pixels margin
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return 10;
    }

    CGFloat tableWidth = self.myTableView.frame.size.width;

    // Really small table
    if (tableWidth <= 20) {
        return tableWidth - 10;
    }

    // Average table size
    if (tableWidth < 400) {
        return 10;
    }

    // Big tables have complex margin's logic
    // Around 6% of table width,
    // 31 <= tableWidth * 0.06 <= 45

    CGFloat marginWidth  = tableWidth * 0.06;
    marginWidth = MAX(31, MIN(45, marginWidth));
    return marginWidth;
}

@end
//在CustomGroupedCell.h中
#进口
@接口CustomGroupedCell:UITableViewCell
@属性(非原子,弱)UITableView*myTableView;
@结束
//在CustomGroupedCell.m中
#导入“CustomGroupedCell.h”
@CustomGroupedCell的实现
@综合myTableView=\u myTableView;
-(void)setFrame:(CGRect)frame
{
frame=CGRectMake(-[self cellsMargin],frame.origin.y,self.myTableView.frame.size.width+2*[self cellsMargin],frame.size.height);
self.contentView.frame=frame;
[超级设置帧:帧];
}
-(CGFloat)细胞边缘蛋白{
//普通表格视图没有边距
if(self.myTableView.style==UITableViewStylePlain){
返回0;
}
//iPhone总是有10像素的边距
如果(用户界面习惯用法()==UIUserInterfaceIdiomPhone)
{
返回10;
}
CGFloat tableWidth=self.myTableView.frame.size.width;
//非常小的桌子

如果(桌面宽度)我永远找不到办法,我真的试过并用谷歌搜索过(但那是几个月前的事了).最后我只是硬编码了值-每边都有20个点。祝你好运!没有办法删除边框,是吗?我不是说让边框消失,我的意思是让实际单元格占据整个表格的宽度。问题是,我想动态更改表格的位置,但tableview边框anges大小取决于表格的宽度-您想使用组样式,这就是它的工作方式。您可能可以通过创造性地使用节页眉和页脚等,使用普通样式旋转类似的内容。为什么不将其作为答案发布?