1

このコードを使用して、セル内に画像を作成します。

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"CellIdentifier"] autorelease];


    switch (indexPath.row) {
    ...
    case 5:
            cell.imageView.image = [UIImage imageNamed:@"Search.png"];
            break;
        default:
            break;
    }
    return cell;
}

画像をセルの中央に配置するにはどうすればよいですか? UITableViewCell をサブクラス化する必要がありますか?

4

3 に答える 3

1

これを行うためのより効果的で効率的な方法は、Custom UITableViewCellを使用することです。そのため、TableViewCell を簡単にカスタマイズできます。

これは、コードと Interface builder の両方で行うことができます。

Interface Builder を使用したカスタム UITableViewCell

UITableView のテーブル ビュー セルをカスタマイズする

于 2013-07-26T04:22:39.993 に答える
0
cell.imageView.center = cell.center;
于 2013-07-26T04:58:49.217 に答える