2013-03-22 4 views
0

Я попытался установить фоновое изображение на метку в 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; 

}

Почему текст не отображается здесь? Может кто-нибудь помочь?

ответ

4

Попробуйте этот код,

theLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellbg.jpeg"]]; 
0

Вы не должны добавлять фоновое изображение UILable вместо добавить фоновое изображение TableCell в subnview или добавить фоновое изображение [cell.contentview addSubview:[UIImage imageNamed:@"cellbg.jpeg"]]

использовать Также PNG вместо JPEG/JPG. Apple предпочитает PNG.

0

Вместо того, чтобы фон в lable поставить одну ImageView в задней части lable, а затем установить изображение в эту ImageView. Это будет работать.

Смежные вопросы