如何在 UITableView 中为 UITableViewStyleGrouped 修复边框
Posted
技术标签:
【中文标题】如何在 UITableView 中为 UITableViewStyleGrouped 修复边框【英文标题】:How to fix border in UITableView for the UITableViewStyleGrouped 【发布时间】:2011-10-03 09:49:51 【问题描述】:对于UITableViewStyleGrouped
UITableView
,在表格视图下方绘制了一条额外的小线
我该如何解决这个问题?
我已经尽力了。到目前为止没有运气。
提前致谢。
我的代码
-(void)myTableView
// if(mytableView != nil)
// [mytableView release];
if (mytableView == nil)
mytableView = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped];
mytableView.delegate=self;
mytableView.dataSource=self;
mytableView.backgroundView=nil;
mytableView.scrollEnabled = FALSE;
[self.view addSubview:mytableView];
[self myPortraitMode];
表格的背景是固定的图像。
【问题讨论】:
你必须清楚地解释你自己?你到底有什么问题? @user891268,这是分组表视图的默认样式。为什么要改变它? 不设置背景视图看起来很糟糕 【参考方案1】:我认为您指的是表格视图的斜角颜色。
答案就在这个post。
基本上,您需要将表separatorStyle
设置为UITableViewCellSeparatorStyleNone
或UITableViewCellSeparatorStyleSingleLine
。
【讨论】:
这个是正确的答案,选择的是改变整个背景,而不是按要求删除多余的行。【参考方案2】:你需要设置背景视图:
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor yourColor];
tableview.backgroundView = backgroundView;
[backgroundView release];
您不需要每次都设置属性。
-(void)myTableView
if (mytableView == nil)
mytableView = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped];
mytableView.delegate=self;
mytableView.dataSource=self;
mytableView.backgroundView=nil;
mytableView.scrollEnabled = NO;
[self.view addSubview:mytableView];
[self myPortraitMode];
但我真的不明白问题出在哪里。
【讨论】:
您对问题和如何设置表格视图的代码有更全面的了解吗? 对于 backgroundView 它是一个图像。在 UITableview 上 这个问题的正确答案是@Code Monkey 的答案。以上是关于如何在 UITableView 中为 UITableViewStyleGrouped 修复边框的主要内容,如果未能解决你的问题,请参考以下文章
如何在 UITableView 的两个部分之间插入 UIImageView?
如何根据 UITableView 滚动动态调整 UITableViewCell 的大小?
如何在 Swift 中为 UITableView 设置左右边距
如何在 UITableView 的单元格中为 UIImageView 获取 touchesMoved?