我尝试在 UITableViewCell 中将背景图片设置为标签,但是在运行时,标签中只显示背景图片,不显示文本。
这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableCell";
// Dequeue or create a cell of the appropriate type.
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
UIImageView *preparationLabelBg = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"cellbg.jpeg"]];
[cell.preparationLabel addSubview:preparationLabelBg];
cell.preparationLabel.backgroundColor=[UIColor clearColor];
[cell.preparationLabel sendSubviewToBack:preparationLabelBg];
[cell.preparationLabel setOpaque:NO];
}
[cell.preparationLabel setFont:[UIFont fontWithName:@"Marker Felt" size:14]];
// Configure the cell.
if (btnselected==1)
{
cell.preparationLabel.text = [recipe.ingredients objectAtIndex:indexPath.row];
}
else
{
cell.preparationLabel.text = [recipe.preparation objectAtIndex:indexPath.row];
}
return cell;
}
为什么这里不显示文字?有人可以帮忙吗?