更改iOS6中分组的uitableview的拐角半径 [英] changing corner radius of uitableview grouped in iOS6

查看:82
本文介绍了更改iOS6中分组的uitableview的拐角半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码,但是没有运气.有人知道如何在iOS 6中执行此操作吗?我不想要创建自定义单元格.

I've tried using the following code but with no luck. Anybody know how to do this in iOS 6? I do not want to create a custom cell.

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

看来,实际发生的是此代码正在为整个视图而不是每个UITableViewSection创建一个拐角半径.这有道理吗?

It appears that what's actually happening is that this code is creating a corner radius for the entire view, not each individual UITableViewSection. Does this make sense?

我也尝试过[cell.layer setCornerRadius:3.0];,但是也没有运气.我的UITableView的角仍然完全相同.

I have also tried [cell.layer setCornerRadius:3.0]; but also with no luck. The corners of my UITableView are still exactly the same.

推荐答案

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

You can change de backgroundView of the TableViewCell, create a subclass of UIView and change the layer class:

@interface BackgroundView : UIView
@end

@implementation BackgroundView

+ (Class)layerClass
{
    return [CAShapeLayer class];
}
@end

稍后在cellForRowAtIndexPath中,您将执行以下操作:

later in cellForRowAtIndexPath you do something like this:

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;

结果如下:

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

You can modify the corners you want or create another path.

希望对您有帮助.

这篇关于更改iOS6中分组的uitableview的拐角半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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