我正在尝试在 UITableViewCell 中添加文本标签或 UIImage(没关系)。但它没有出现。我在这个单元格中使用了几个视图。您可以在下面的代码中看到它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"timelineCell";
KMWTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell)
{
cell = [cell initWithFrame:CGRectMake(13, 10, 293, 200)];
UIView *cellContentView = [[UIView alloc] initWithFrame:CGRectMake(13, 10, 293, 200)];
cellContentView.layer.cornerRadius = 5;
cellContentView.layer.shadowOffset = CGSizeMake(1, 0);
cellContentView.layer.shadowColor = [[UIColor blackColor] CGColor];
cellContentView.layer.shadowRadius = 5;
cellContentView.layer.shadowOpacity = .25;
cellContentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBack"]];
UIView *selectedContentView = [[UIView alloc] initWithFrame:CGRectMake(13, 10, 293, 200)];
selectedContentView.layer.cornerRadius = 5;
selectedContentView.layer.shadowOffset = CGSizeMake(1, 0);
selectedContentView.layer.shadowColor = [[UIColor blackColor] CGColor];
selectedContentView.layer.shadowRadius = 5;
selectedContentView.layer.shadowOpacity = .25;
selectedContentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackActive"]];
UIView *visibleContentView = [[UIView alloc] initWithFrame:CGRectMake(13, 10, 293, 200)];
visibleContentView.layer.cornerRadius = 5;
visibleContentView.layer.shadowOffset = CGSizeMake(1, 0);
visibleContentView.layer.shadowColor = [[UIColor blackColor] CGColor];
visibleContentView.layer.shadowRadius = 5;
visibleContentView.layer.shadowOpacity = .25;
visibleContentView.backgroundColor = [UIColor clearColor];
//Image adding here:
[ UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"active.png"]];
[visibleContentView addSubview:image];
[cellContentView addSubview:visibleContentView];
[selectedContentView addSubview:visibleContentView];
[cell setBackgroundView:cellContentView];
[cell setSelectedBackgroundView:selectedContentView];
}
return cell;
}
正如你所看到的,我正在使用 backgroundView 和 selectedBackgroundView 并且还使用 clearColor 查看其他信息。那么为什么其他元素不显示在 visibleView 中呢?
更新:
我正在使用子类,因为我需要更改单元格的帧大小。