0

無地のテーブルに色を設定する方法を知っています。グループ化されたテーブルに移行すると、背景色もシフトし、テーブル自体の外側の背景になります。テーブルに色を設定することもできますか?つまり、外側のエリアに 1 つの色を、テーブルに別の色を付けますか?

4

2 に答える 2

1

これは、数行のコードを追加することで実行できます。

画像を背景として使用する場合、

tableView.opaque = NO;
[tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];

単色を使用する場合は、

tableView.opaque = NO;
    [tableView setBackgroundColor:[UIColor blueColor]]; 

詳細については、このチュートリアルを参照してください。

于 2012-02-02T08:17:12.037 に答える
1

外側の色については、インターフェースビルダーまたはコードを使用してテーブルの背景色を設定できます

[myTableView setBackgroundColor: [UIColor redColor]];

内側の色については、UITableView データソース メソッドでセルの背景色を設定できます。

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

static NSString * CellIdentifier = @"customCell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

cell.backgroundColor = [UIColor greenColor];

return cell;

}
于 2012-02-02T08:21:47.217 に答える