1

カスタム backgroundView を UITableViewCell に割り当てようとしています。テーブルはグループ化されています。

私は少し先駆者なので、背景ビューの典型的な幅である 302 ピクセルを使用する代わりに、幅 300 ピクセルの画像を使用しようとしています。

これが私のコードです:

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    // a 300 pixel wide image
    UIImage *backgroundImage = [UIImage imageNamed:@"tableViewCellBackgroundTop"];
    UIImageView *theBackgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
    theBackgroundView.frame = CGRectMake(10, 0, 300, 49);
    cell.backgroundView = theBackgroundView;
}

これをシミュレーターで実行して xScope で測定すると、セルの幅は 302 ピクセルのままです。何を与える?背景ビューに割り当てたフレームをフレームワークに反映させるために設定する必要がある他のプロパティはありますか、それともテーブル ビュー セルはこの方法でカスタマイズすることを意図していませんでしたか?

4

1 に答える 1

3

UIViewインスタンスを作成してtheBackgroundViewそのサブビューをcell.backgroundView作成してから、作成したビューに設定できます。

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 49)];
[view addSubview:theBackgroundView];
cell.backgroundView = view;
于 2012-08-14T21:19:04.450 に答える