---
title: "How to change background color of UILabel in  UITableViewCell"  
description: "How to change background color of UILabel in  UITableViewCell"  
author: "Anonymous User"  
published: 2015-12-08  
updated: 2015-12-09  
canonical: https://www.mindstick.com/forum/33702/how-to-change-background-color-of-uilabel-in-uitableviewcell  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to change background color of UILabel in  UITableViewCell

I have created an app on iPhone using UITableViewCell within [table view](https://www.mindstick.com/forum/33654/send-table-view-cell-value-on-button-action-in-ios) and I put an UILabel into table view cell.\
I want to change the [background color](https://www.mindstick.com/forum/12937/how-to-style-togglebutton-so-that-the-background-color-is-white) of UILabel.\
this is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
UILabel *myLabel = (UILabel*)[cell.contentView.subviews objectAtIndex:0];myLabel.textColor = [UIColor blueColor];mylabel.backgroundColor = [UIColor greyColor];mylabel.opaque = YES;
```

[Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now), please [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) tell me the [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) in my code.

Thanks in advance..!

## Replies

### Reply by Tarun Kumar

Your problem is that you are not adding your own label to the **contentView** at the time of allocating the cell. Use **addSubview:** method to allocate it on the cell.\
Here we provide your complete code with one additional line of code:

```
UILabel *myLabel = (UILabel*)[cell.contentView.subviews objectAtIndex:0];myLabel.textColor = [UIColor blueColor];mylabel.backgroundColor = [UIColor greyColor];mylabel.opaque = YES;[cell.contentView addSubview:myLabel];
```


---

Original Source: https://www.mindstick.com/forum/33702/how-to-change-background-color-of-uilabel-in-uitableviewcell

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
