2013/04/02

[iOS][Objective-C]UITableViewCellの背景色を変更する

昔、書いたような気がするのだが、探してみてなさそうだったので、1エントリー。

UITableViewCellの背景色(セルの色)を設定するには、どうしたらいいのかなとひとまず、下のようにしました。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.backgroundColor = [UIColor redColor];
}
でもこれだと変わらず困りました。

UITableViewCell の背景色を変えるを読んで確かに、
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
   cell.backgroundColor = [UIColor blueCorlo];
}
としても変わるのだが、
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    cell.contentView.backgroundColor = [UIColor redColor];
}
でも設定できることがわかりました。

何か問題があるまで当分は、contentViewで背景色を設定したいと思います。

0 コメント:

コメントを投稿