更改iOS6中分组的uitableview的角半径

更改iOS6中分组的uitableview的角半径,ios,objective-c,Ios,Objective C,我尝试过使用下面的代码,但没有成功。有人知道如何在iOS 6中做到这一点吗?我不想创建自定义单元格 self.tableView.layer.cornerRadius = 5.0f; [self.tableView setClipsToBounds:YES]; 编辑: 看起来实际发生的是,这段代码为整个视图创建了一个圆角半径,而不是每个单独的UITableViewSection。这有意义吗 我还尝试了[cell.layer setCornerRadius:3.0]但也没有运气。我的UI

我尝试过使用下面的代码,但没有成功。有人知道如何在iOS 6中做到这一点吗?我不想创建自定义单元格

self.tableView.layer.cornerRadius = 5.0f;
    [self.tableView setClipsToBounds:YES];
编辑:

看起来实际发生的是,这段代码为整个视图创建了一个圆角半径,而不是每个单独的UITableViewSection。这有意义吗

我还尝试了
[cell.layer setCornerRadius:3.0]但也没有运气。我的UITableView的各个角落仍然完全相同


将quartzcore框架添加到项目中

import QuartzCore/QuartzCore.h to your .h file

self.tableView.layer.cornerRadius=5.0f

我认为您缺少这一行代码:

[self.tableView.layer setMasksToBounds:YES];

首先,您需要使用QuartzCode框架导入该框架并声明.h文件,以设置层效果

并添加该方法

myTableView.layer.cornerRadius=5;
[myTableView setClipsToBounds:YES];
如果你想把无线电波调到手机,也试过这个代码

UITableViewCell.layer是一种CALayer类,CALayer类有一个名为cornerRadius的属性。因此,可以将单元的角半径设置为“休耕”:

[cell.layer setCornerRadius:3.0];

试试这段代码。

你可以这样做。它对我有用

    UILabel *delLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 44)];
    delLbl.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
    delLbl.layer.cornerRadius = 10.0f;
    delLbl.layer.borderWidth = 1.0f;
    delLbl.layer.borderColor = [UIColor grayColor].CGColor;
    delLbl.text = @"Cell Text";
    delLbl.textAlignment = NSTextAlignmentCenter;
    [cell.contentView addSubview:delLbl];
    cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    Return Cell;
试试这个:-

tableView.layer.cornerRadius=5.0f;

您可以更改TableViewCell的背景视图,创建UIView的子类并更改图层类:

@interface BackgroundView : UIView
@end

@implementation BackgroundView

+ (Class)layerClass
{
    return [CAShapeLayer class];
}
@end
稍后在cellForRowAtIndexPath中,您可以执行以下操作:

static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];

CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer  *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;

return cell;
结果如下:

可以修改所需的角点或创建其他路径


我希望它能帮上忙。

我想你要找的是PrettyKit。完全可定制和快速。试试看。你应该把工作做好

将其添加到.h文件中

#import <QuartzCore/QuartzCore.h>

谁说的
[[u tblView.layer setCornerRadius:10.0]在分组样式表视图中不起作用

[_tblView setBackgroundView:nil];
[_tblView setBackgroundColor:[UIColor greenColor]];
[_tblView.layer setCornerRadius:10.0];
编写这段代码,您将设置setCornerRadius也可以在分组表视图中工作

[_tblView setBackgroundView:nil];
[_tblView setBackgroundColor:[UIColor greenColor]];
[_tblView.layer setCornerRadius:10.0];


[[u tblView.layer setCornerRadius:10.0]
不会为tableView的特定部分创建角半径这用于设置整个tableView的角半径。

不设置单元格的角半径,而是按如下方式设置单元格的半径。contentview:

[_tblView setBackgroundView:nil];
[_tblView setBackgroundColor:[UIColor greenColor]];
[_tblView.layer setCornerRadius:10.0];
cell.contentView.layer.cornerRadius = 10.0f;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
cell.contentView.layer.borderWidth = 3.0f;

在初始化单元格时输入上述代码。

查看我的更新答案。请问您为什么不需要自定义单元格?它让生活变得如此美好easier@RobvanderVeer过去我在使用自定义单元格时遇到过困难,但我想我愿意接受使用自定义单元格的建议。我主要担心的是性能问题。有人建议对整个单元格使用自定义图像,这似乎是一种懒散且不正确的解决问题的方法。我建议打开一个游乐场项目并进行实验,这样您可以做出更好的决定。您是否试图绕过整个tableview(tableview的一部分,tableview的一部分)的各个角落“部分”?你能澄清一下吗?如何设置tableview部分的角半径?我不确定为什么这个答案被接受。OP问你是否可以将角半径应用于分组单元格,如果我错了,请纠正我。