Clip Subviews
セルや実際のテーブルのプロパティで遊ぶことができると思います。セルに自分を入れてUIImageView
(Backgroundプロパティとして割り当てることができるかどうかはわかりませんが、試すことができます)、セルの高さよりも高い高さに設定します。ただし、唯一の問題は、画像が重なる可能性があることです。選択した状態のビューを配置する実際のインデックスを設定することで、問題の解決を試みることができます。
さて、少しテストしました。このコードを見てください:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
cell.clipsToBounds = NO;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGRect frame = cell.bounds;
UIImageView *background = [[UIImageView alloc] initWithFrame:frame];
background.image = [UIImage imageNamed:@"CellBackground"];
cell.backgroundView = background;
[background release];
frame.size.height = 50.0;
UIImageView *selected = [[UIImageView alloc] initWithFrame:frame];
selected.tag = 13;
selected.image = [UIImage imageNamed:@"CellSelectedBackground"];
[cell insertSubview:selected atIndex:1];
selected.hidden = YES;
[selected release];
}
cell.textLabel.text = [NSString stringWithFormat:@"cell %d", indexPath.row];
return cell;
}
ここでの主なものはcell.clipsToBounds = NO;
と[cell insertSubview:selected atIndex:1];
です。ただし、セルのサブクラスを作成し、ここですべてのものと選択を処理する方がはるかに優れています。あなたの写真で見られるように、あなたはすでにサブクラス化されたセルを使用していますが:)