なぜかXIBでUITableViewとUITableViewCellの背景色を半透明にするだけでは、セルを半透明にできなかったので備忘録として。
UITableViewを半透明にする.
-(void)viewDidLoad {
// 半透明にする.
UIColor* tableBackgroundColor = [UIColor blackColor];
tableBackgroundColor = [tableBackgroundColor colorWithAlphaComponent:0.5];
[self.tableView setBackgroundColor:tableBackgroundColor];
}
UITableViewCellを透明にする.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableCellTableViewCell* cell = (MyTableCellTableViewCell*)
[tableView dequeueReusableCellWithIdentifier:MY_TABLE_CELL];
if( cell == nil ) {
cell = [self createCustomCell];
// なぜかXIB上でclearColorを設定していも、セルが透明にならず、
// ここで設定する事でセルが透明になった。
[cell setBackgroundColor:[UIColor clearColor]];
}
return cell;
}
// テーブルセルを生成する
-(MyTableCell*)createCustomCell {
MyTableCell* result = nil;
NSArray* nibArray = [[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:nil options:nil];
for(id obj in nibArray) {
if( [obj isMemberOfClass:[MyTableCell class]] ) {
result = (MyTableCell*)obj;
break;
}
}
return result;
}