I have created an app on iPhone using UITableViewCell within table view and I put an UILabel into table view cell.
I want to change the background color of UILabel.
this is my code:
UILabel *myLabel = (UILabel*)[cell.contentView.subviews objectAtIndex:0];
myLabel.textColor = [UIColor blueColor];
mylabel.backgroundColor = [UIColor greyColor];
mylabel.opaque = YES;
Now, please anyone tell me the problem in my code.
Thanks in advance..!
Tarun Kumar
09-Dec-2015Your 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: