Apple は iOS6 で角の半径を約 7 (以前は 10) に変更したようです。
UITableViewCell と同じコーナー半径を持つ必要がある UITableView の背後にビューがあります。私のアプリは以前の iOS バージョンもサポートしているため、ビューの角の半径を現在の UITableview のものに合わせる必要があります。セルのコーナー半径にアクセスする方法はありますか?
Apple は iOS6 で角の半径を約 7 (以前は 10) に変更したようです。
UITableViewCell と同じコーナー半径を持つ必要がある UITableView の背後にビューがあります。私のアプリは以前の iOS バージョンもサポートしているため、ビューの角の半径を現在の UITableview のものに合わせる必要があります。セルのコーナー半径にアクセスする方法はありますか?
@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;