【问题标题】:Access corner radius of UITableViewCell in grouped TableView分组TableView中UITableViewCell的访问角半径
【发布时间】:2012-10-25 12:32:40
【问题描述】:
Apple 似乎将 iOS6 中的圆角半径更改为大约 7(之前为 10)。
我的 UITableView 后面有一个视图,它需要与 UITableViewCell 具有相同的角半径。
我的应用程序还支持以前的 iOS 版本,因此我必须将视图的角半径调整为当前 UITableview 所具有的半径。
有没有办法访问单元格的圆角半径?
【问题讨论】:
标签:
objective-c
uiview
uitableview
cornerradius
【解决方案1】:
@bllubbor -你可以通过这种方法,希望它能解决你的答案,因为它对我有用..
@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;