我試圖將背景圖像設置爲UITableViewCell中的標籤,但在運行時,只有背景圖像顯示在標籤中,文本不顯示。當設置背景圖像時,UILabel不顯示文字
這是我的代碼
- (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;
}
爲什麼不在這裏顯示的文本?誰能幫助?