[英]Changing background color of a custom UITableViewCell cell in a plain styled UITableView
[英]changing the background color of custom cell
它看起來很簡單,但是我不知道為什么我不能更改正在使用的自定義標簽的背景顏色。 請在下面檢查我的代碼以獲取自定義單元格。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
self.textLabel.backgroundColor = [UIColor clearColor];
self.textLabel.textColor = [UIColor orangeColor];
self.textLabel.text = @"lklklk";
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.contentView.backgroundColor = [UIColor blackColor];
self.accessoryView.backgroundColor = [UIColor blackColor];
}
return self;
}
單元格僅以白色背景顯示上述文本
提前致謝
在進行春季大掃除時,我不得不面對這個挑戰
這是我解決問題的方法:
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor blackColor];
view.opaque = YES;
self.backgroundView = view;
[view release];
UITableViewCells有一個backgroundView,您需要隱藏它以便設置backgroundColor:
[self.backgroundView setHidden:YES];
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.