UITableViewStyleGrouped具有直角

时间:2012-11-19 09:08:42

标签: iphone ios uitableview

当我使用

创建表格视图时
myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStyleGrouped];

表格视图有圆角,但我想要有直角(因此表视图单元格应该看起来像矩形,但是表格视图仍然应该有很多部分)。

问题是:如何创建包含许多部分和直角的表格视图?

4 个答案:

答案 0 :(得分:2)

在TableView数据源中。在cellForRowAtIndexPath中,您可以将单元格的背景设置为空白...

cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero()];

然后你可以在单元格的背面放置一个图像或矩形等等。

您甚至可以创建一个新的UIView并将其放在backgroundView的位置。

然后你可以把你想要的东西,图像,标签等......放在细胞的内容之后。

分组样式的单元格圆角只是一个图像,因此可以替换为您。

答案 1 :(得分:1)

将图像设置为单元格的背景图像,并将UITableView的背景颜色设置为clearColor,并将图像设置为贝娄..

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     ///write your code..
       UIImageView *img = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 45)] autorelease]; // set frame as your cell frame
      img.image = [UIImage imageNamed:@"yourImageName"];
      cell.backgroundView = img;
    ////write your code
}

答案 2 :(得分:0)

对于Sections,您可以编写类似

的委托方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

// Return the number of sections.
return 1;//how many sections you want you can write a value after return type

}

答案 3 :(得分:0)

我发现使角落成直角的最佳方法是将背景视图设置为nil然后将视图放入其中。

[cell setBackgroundView:nil];

cell.backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];