7

グループ化されたテーブルビューで強調表示されているときに、UITableViewCell の背景色を設定したいと考えています。私が現在使用しているコードは、この結果を生成します。uitableviewcell の丸みを帯びた角を維持するために、誰かがこれを行う正しい方法を教えてください。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds] ;
    cell.selectedBackgroundView.backgroundColor = coolBlue ;
}

更新されたコード:

cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
cell.selectedBackgroundView.backgroundColor = coolBlue;

UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8.0f, 8.0f)];

CAShapeLayer *shape = [[CAShapeLayer alloc] init];

[shape setPath:rounded.CGPath];

cell.selectedBackgroundView.layer.mask = shape;
rounded = nil;
shape = nil;

ここに画像の説明を入力

アップデート:

ここに画像の説明を入力

4

2 に答える 2

0

セルの clipsToBounds が YES に設定されていることを確認してください

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/clipsToBounds

于 2013-07-20T03:15:23.470 に答える