Getting rid of cell text background box - ios

I have this table:
How do I get rid of the boxes behind the text?
This is my current code:
UIColor *CellColor = [UIColor colorWithWhite:0.7 alpha:0.2];
cell.backgroundColor = CellColor;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:16.0];
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10.0];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = #"Title text...";
cell.detailTextLabel.text = #"Subtitle text...";

Default background color for a UILabel is white. So this is normal.
If you want a transparent background, you need to use:
cell.textLabel.backgroundColor = [ UIColor clearColor ];
And same for detailTextLabel

Related

iOS Objective C - UITableView performance issue

My app is using CoreData as persistence data storage. Below is my code for the tableview. On the simulator it runs fine, but when running it on the phone it gets very laggy. Any suggestions on optimization is appreciated :)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
Journal* journal = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.titleLabel.text = journal.title.uppercaseString;
cell.titleLabel.font = [UIFont fontWithName:#"SourceSansPro-Bold" size:25];
cell.titleLabel.textColor = [UIColor blackColor];
cell.detailLabel.text = journal.detail;
cell.detailLabel.font = [UIFont fontWithName:#"SourceSansPro-SemiBold" size:18];
cell.detailLabel.textColor = [UIColor blackColor];
NSDate *currentDate = journal.timeStamp;
cell.dateLabel.text = [self.dateFormatter stringFromDate: currentDate];
cell.dateLabel.font = [UIFont fontWithName:#"SourceSansPro-SemiBold" size:16];
cell.dateLabel.textColor = [UIColor blackColor];
cell.locationLabel.text = [NSString stringWithFormat:#"%#, %#", journal.city, journal.country];
cell.locationLabel.font = [UIFont fontWithName:#"SourceSansPro-SemiBold" size:18];
cell.locationLabel.textColor = [UIColor blackColor];
cell.tempLabel.text = [NSString stringWithFormat:#"%g°C", round(journal.temp)];
cell.tempLabel.font = [UIFont fontWithName:#"SourceSansPro-SemiBold" size:18];
cell.tempLabel.textColor = [UIColor blackColor];
cell.weatherIcon.image = [UIImage imageNamed:journal.condition];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageWithData:journal.image] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
cell.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageWithData:journal.image] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
cell.selectedBackgroundView.contentMode = UIViewContentModeScaleAspectFill;
cell.backgroundView.alpha = 0.5;
cell.selectedBackgroundView.alpha = 0.5;
return cell;
}
You are experiencing low FPS lags because of this API usage:
[UIImage imageWithData:journal.image]
The UIImage imageWithData: method is NOT asynchronous, so as the table view loads each new cell, it has to process the data, locking up the app while doing so.
Try to find an async way to load/create/cache an image on a background thread making your UI responsive.
Check out this popular image loading/caching library SDWebImage for more ideas/inspiration and potential solution for your needs.
First, you can customize a cell, some code is unnecessary, such as set Font and TextColor in every time.
Next, you can use instrument-->Profile to find the code where is time consuming.
Hope it can help you!

Where to set UITableViewCell other than in cellForRowAtIndexPath ? Objective-C

In a wish to improve UITableView performance, I'm thinking of relocating all of my UITableViewCell's settings outside cellForRowAtIndexPath.
At this moment, I have several custom cells inside my tableview that I set inside cellForRowAtIndexPath. But because of this, everytime I scroll inside my tableview and so everytime a cell has to be shown on screen, the settings is done again, causing a lag.
I've tried to put settings inside viewDidLoad by using a class variable for my cell but with no effect. Do you have any idea where I could move all of my cells' settings but especially if it's possible ?
Thanks in advance and have a nice day !
EDIT :
As asked, here is my cellForRowAtIndexPathMethod :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.delegate = self;
if ([appliedTheme hasPrefix:#"DarkMode"]) {
self.tableView.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0];
cell.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0];
cell.cardView.backgroundColor = [UIColor colorWithRed:0.30 green:0.30 blue:0.30 alpha:1.0];
cell.webServerIntroLabel.textColor = [UIColor whiteColor];
cell.webServerOptionsTitle.textColor = [UIColor whiteColor];
cell.webServerOptionsReachableAtLabel.textColor = [UIColor whiteColor];
}else {
self.tableView.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0];
cell.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0];
cell.cardView.backgroundColor = [UIColor whiteColor];
cell.webServerIntroLabel.textColor = [UIColor blackColor];
cell.webServerOptionsTitle.textColor = [UIColor blackColor];
cell.webServerOptionsReachableAtLabel.textColor = [UIColor blackColor];
}
if ([CellIdentifier isEqualToString:#"webServerIntro"]) {
cell.webServerIntroImageView.image = [UIImage imageNamed:webServerIntroIconToShow];
cell.webServerIntroLabel.adjustsFontSizeToFitWidth = YES;
cell.webServerIntroLabel.numberOfLines = 0;
[cell.webServerIntroLabel sizeToFit];
cell.webServerIntroLabel.text = #"Some text";
}else if ([CellIdentifier isEqualToString:#"webServerOptions"]) {
cell.webServerOptionsTitle.adjustsFontSizeToFitWidth = YES;
cell.webServerOptionsTitle.text = NSLocalizedString(#"Web Server Options", nil);
cell.webServerOptionsStatusLabel.adjustsFontSizeToFitWidth = YES;
if (!webServerStarted) {
cell.webServerOptionsImageView.image = [UIImage imageNamed:#"Not-Checked"];
cell.webServerOptionsStatusLabel.text = NSLocalizedString(#"Not Running", nil);
cell.serverURLLabel.text = NSLocalizedString(#"Not Reachable", nil);
cell.ipAddressURLLabel.text = NSLocalizedString(#"Not Reachable", nil);
[cell.startStopWebServerButton setTitle:NSLocalizedString(#"Start Web Server", nil) forState:UIControlStateNormal];
cell.webServerStartedBool = NO;
}else {
NSString *serverURL = [self deviceName];
serverURL = [serverURL stringByReplacingOccurrencesOfString:#" " withString:#"-"];
cell.webServerOptionsImageView.image = [UIImage imageNamed:#"Checked"];
cell.webServerOptionsStatusLabel.text = NSLocalizedString(#"Running", nil);
cell.serverURLLabel.text = [NSString stringWithFormat:#"http://%#.local", serverURL];
cell.ipAddressURLLabel.text = [NSString stringWithFormat:#"%#", webUploader.serverURL];
[cell.startStopWebServerButton setTitle:NSLocalizedString(#"Stop Web Server", nil) forState:UIControlStateNormal];
cell.webServerStartedBool = YES;
}
cell.webServerOptionsStatusLabel.textColor = [UIColor lightGrayColor];
cell.webServerOptionsReachableAtLabel.adjustsFontSizeToFitWidth = YES;
cell.webServerOptionsReachableAtLabel.text = NSLocalizedString(#"Reachable At :", nil);
cell.ipAddressURLLabel.adjustsFontSizeToFitWidth = YES;
cell.ipAddressURLLabel.textColor = [UIColor lightGrayColor];
cell.ipAddressURLLabel.layer.borderWidth = 1.0f;
cell.ipAddressURLLabel.layer.borderColor = [[UIColor lightGrayColor] CGColor];
cell.ipAddressURLLabel.layer.cornerRadius = 5;
cell.serverURLLabel.adjustsFontSizeToFitWidth = YES;
cell.serverURLLabel.textColor = [UIColor lightGrayColor];
cell.serverURLLabel.layer.borderWidth = 1.0f;
cell.serverURLLabel.layer.borderColor = [[UIColor lightGrayColor] CGColor];
cell.serverURLLabel.layer.cornerRadius = 5;
cell.startStopWebServerButton.layer.borderWidth = 1.0f;
cell.startStopWebServerButton.layer.borderColor = [[UIColor clearColor] CGColor];
cell.startStopWebServerButton.layer.cornerRadius = 5;
cell.startStopWebServerButton.titleLabel.adjustsFontSizeToFitWidth = YES;
if ([appliedTheme isEqualToString:#"Default-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0 green:0.478 blue:0.875 alpha:1]; /*#007ADF : Bleu iOS*/
}else if ([appliedTheme isEqualToString:#"Red-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.90 green:0.07 blue:0.00 alpha:1.0]; /*#E61100 : Rouge*/
}else if ([appliedTheme isEqualToString:#"Orange-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.83 green:0.33 blue:0.00 alpha:1.0]; /*#D35400 : Orange*/
}else if ([appliedTheme isEqualToString:#"Yellow-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.95 green:0.61 blue:0.07 alpha:1.0]; /*#F39C12 : Jaune*/
}else if ([appliedTheme isEqualToString:#"Green-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.15 green:0.68 blue:0.38 alpha:1.0]; /*#27AE60 : Vert*/
}else if ([appliedTheme isEqualToString:#"Purple-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.56 green:0.27 blue:0.68 alpha:1.0]; /*#8E44AD : Violet*/
}else if ([appliedTheme isEqualToString:#"Gray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.74 green:0.76 blue:0.78 alpha:1.0]; /*#BDC3C7 : Gris*/
}else if ([appliedTheme isEqualToString:#"DarkGray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.50 green:0.55 blue:0.55 alpha:1.0]; /*#7F8C8D : Gris foncé*/
}else if ([appliedTheme isEqualToString:#"DesaturatedBlue-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.17 green:0.24 blue:0.31 alpha:1.0]; /*#2C3E50 : Bleu désaturé*/
}else if ([appliedTheme isEqualToString:#"VeryDarkGray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0]; /*#333333 : Gris très foncé*/
}else if ([appliedTheme isEqualToString:#"Black-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1.0]; /*#000000 : Noir*/
}else if ([appliedTheme isEqualToString:#"DarkModeDefault-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0 green:0.478 blue:0.875 alpha:1]; /*#007ADF : Bleu iOS*/
}else if ([appliedTheme isEqualToString:#"DarkModeRed-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.90 green:0.07 blue:0.00 alpha:1.0]; /*#E61100 : Rouge*/
}else if ([appliedTheme isEqualToString:#"DarkModeOrange-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.83 green:0.33 blue:0.00 alpha:1.0]; /*#D35400 : Orange*/
}else if ([appliedTheme isEqualToString:#"DarkModeYellow-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.95 green:0.61 blue:0.07 alpha:1.0]; /*#F39C12 : Jaune*/
}else if ([appliedTheme isEqualToString:#"DarkModeGreen-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.15 green:0.68 blue:0.38 alpha:1.0]; /*#27AE60 : Vert*/
}else if ([appliedTheme isEqualToString:#"DarkModePurple-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.56 green:0.27 blue:0.68 alpha:1.0]; /*#8E44AD : Violet*/
}else if ([appliedTheme isEqualToString:#"DarkModeGray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.74 green:0.76 blue:0.78 alpha:1.0]; /*#BDC3C7 : Gris*/
}else if ([appliedTheme isEqualToString:#"DarkModeDarkGray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.50 green:0.55 blue:0.55 alpha:1.0]; /*#7F8C8D : Gris foncé*/
}else if ([appliedTheme isEqualToString:#"DarkModeDesaturatedBlue-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.17 green:0.24 blue:0.31 alpha:1.0]; /*#2C3E50 : Bleu désaturé*/
}else if ([appliedTheme isEqualToString:#"DarkModeVeryDarkGray-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0]; /*#333333 : Gris très foncé*/
}else if ([appliedTheme isEqualToString:#"DarkModeBlack-Theme"]) {
cell.startStopWebServerButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1.0]; /*#000000 : Noir*/
}
}else {
}
return cell;
}
While you have a lot of code there, nothing seems like it would be dreadfully slow.
It is a minor point in term of performance, but the code that sets the tableview's background colour should be in viewWillAppear rather than cellForRowAt as there is no need to set the background colour each time a cell is dequeued.
You can also simplify this function considerably by moving all of the theme-related code into the cell subclass. Call a function on the cell passing the theme and have the cell set all of that stuff; The same amount of code will be executed, but cellForRowAt will be smaller and easier to read.
Where I think you can get some performance is by eliminating the repeated string operations related to the theme. Create a class or struct that represents your theme and use an enumeration (This stuff is much easier is Swift, but you can still do it in ObjectiveC).
If you do this, then, for example,
if ([appliedTheme hasPrefix:#"DarkMode"])
becomes
if (appliedTheme.darkMode)
A complex string comparison is replaced with a simple boolean check; this is much faster
Similarly, using an enumeration for the theme you get something like
switch (appliedTheme.theme) {
case DarkModeGreen-Theme:
...
Now an expesnsive string comparison has been replaced with a quick integer comparison.
Finally, creating UIColors is relatively expensive. You can move that into your Theme object too. When you create an instance of a Theme, expose the colours as properties. This way you get rid of the switch statement I suggested and creating the colours each time and simply say something like
cell.startStopWebServerButton.backgroundColor = appliedTheme.buttonBackgroundColor
Have to tried prepareforreuse. Apart from loading images I don't see other code that could cause the delay. Few things that might help
Even though imagenamed should return a cache image if it's already loaded, try loading images async with GCD
Is the web service code causing any delay?
Run instruments (time profiler?) to see what is causing the lag or delay

Table view not appearing the same way in iOS7 as it did in iOS6

The relevant part of the code is in - tableView:cellForRowAtIndexPath::
cell.textLabel.backgroundColor = [UIColor clearColor];
if (indexPath.row == 0) {
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",result.level]]];
} else {
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]];
}
cell.backgroundView.alpha = 0.5;
cell.backgroundColor = [UIColor darkGrayColor];
if (totalPieces) {
cell.textLabel.textColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.1 alpha:1.0];
cell.textLabel.shadowColor = [UIColor blackColor];
if (indexPath.row == 0) {
cell.textLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.0 alpha:1.0];
cell.textLabel.textColor = [UIColor yellowColor];
cell.backgroundView.alpha = 1.0;
}
cell.textLabel.shadowOffset = CGSizeMake(1.0, 1.0);
} else {
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.shadowColor = nil;
}
Essentially, each row of the table has its own background image. This appears correctly in iOS6. But in iOS7, what happens is that the image is covered by what appears to be the background color. That is, until the user scrolls the table. When the user scrolls the table, it displays properly. What's making it behave differently upon first presentation? What should I do to fix it?
The intended result is a background color of dark grey covering the whole cell. Above that is the background image, which has some transparency, through which the background color should show. Above that is the text, which has a transparent background so the image/cell background shows through.
Unless I hear something else, I suppose what I'll do is to stack two images instead of using the cell background.
First clear the background view of cell by setting it to nil. Then set a custom view
[cell setBackgroundView: nil];
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor colorWithPatternImage:#"your image"];
[cell setBackgroundView:bview];
This worked for me.. Hope it will work for you too.. :-) Best of luck..
This is an intended change by Apple. To fix it change cell.backgroundColor to [UIColor clearColor].
OK. This solution works, although maybe there's a more efficient one.
cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
backgroundView.backgroundColor = [UIColor darkGrayColor];
if (indexPath.row == 0) {
[backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",result.level]]]];
cell.backgroundView = backgroundView;
} else {
[backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]]];
cell.backgroundView = backgroundView;
}

Set Navigation Title Text

I have a UICollectionViewController and trying to set navigation title..
but none of these works...It does not show the text!
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.backgroundColor = [UIColor clearColor];
self.titleLabel.font = [UIFont fontWithName:#"ArialHebrew-Bold" size:15];
self.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.text = [self.navigationItem title];
self.navigationItem.titleView = self.titleLabel;
[self.titleLabel setText:#"title"];
self.navigationItem.title = #"The title";
Make the frame of your new label bigger. The height of a nav bar is fixed at 44 pixels.
For example: CGRectMake(100,0,120,44);
The width and origins depend on what else is on the navbar, and the width of the navbar.

Pixelated UILabel in table cell

To add a UILabel to a table cell I use
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 10, 40, 12)];
timeLabel.text = #"2s";
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.font = [UIFont systemFontOfSize:12];
timeLabel.textColor = [UIColor lightGrayColor];
timeLabel.highlightedTextColor = [UIColor whiteColor];
timeLabel.textAlignment = UITextAlignmentRight;
timeLabel.frame = CGRectIntegral(timeLabel.frame);
[cell.contentView addSubview:timeLabel];
in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.
This works fine until I scroll the table or select a cell. Then the label becomes pixelated.
At load:
after action:
I also tried to add the label by subclassing UITableViewCell and load it in
- (void) layoutSubviews.
I already found related questions here and here but nothing worked.
EDIT: It's not possible to use the standard cell labels since they're already in use. I need to add an additional label.
I finally got it working with a dirty fix.
In - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
I set
cell.selectionStyle = UITableViewCellSelectionStyleNone;.
In a subclass of UITableViewCell I load the timeLabel in initWithStyle as follows:
timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 10, 40, 12)];
timeLabel.text = #"2s";
timeLabel.backgroundColor = [UIColor whiteColor];
timeLabel.font = [UIFont systemFontOfSize:12];
timeLabel.textColor = [UIColor lightGrayColor];
timeLabel.highlightedTextColor = [UIColor whiteColor];
timeLabel.textAlignment = UITextAlignmentRight;
[self.contentView addSubview:timeLabel];
then I override these two functions:
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if(highlighted == YES){
UIImage *image = [UIImage imageNamed:#"cellBg#2x.png"];
//scale custom cell background to necessary height
UIImage *scaledImage = [image scaleToSize:CGSizeMake(1,self.contentView.frame.size.height)];
//set cell background
self.backgroundColor = [UIColor colorWithPatternImage:scaledImage];
//set textcolor for default labels
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor whiteColor];
//set textcolor for custom label
timeLabel.textColor = [UIColor whiteColor];
//cope background for custom label background since timeLabel.backgroundColor = [UIColor clearColor] doesnt work
CGImageRef ref = CGImageCreateWithImageInRect(scaledImage.CGImage, CGRectMake(0, 10, 12, 20));
UIImage *img = [UIImage imageWithCGImage:ref];
//set custom label background
timeLabel.backgroundColor = [UIColor colorWithPatternImage:img];
} else {
//set unselected colors
self.backgroundColor = [UIColor whiteColor];
self.textLabel.textColor = [UIColor darkGrayColor];
self.detailTextLabel.textColor = UIColorFromRGB(0x808080);
timeLabel.textColor = UIColorFromRGB(0x808080);
//white background works without the label pixelates
timeLabel.backgroundColor = [UIColor whiteColor];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
if(selected == YES){
UIImage *image = [UIImage imageNamed:#"cellBg#2x.png"];
UIImage *scaledImage = [image scaleToSize:CGSizeMake(1,self.contentView.frame.size.height)];
self.backgroundColor = [UIColor colorWithPatternImage:scaledImage];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor whiteColor];
timeLabel.textColor = [UIColor whiteColor];
CGImageRef ref = CGImageCreateWithImageInRect(scaledImage.CGImage, CGRectMake(0, 10, 12, 20));
UIImage *img = [UIImage imageWithCGImage:ref];
timeLabel.backgroundColor = [UIColor colorWithPatternImage:img];
} else {
self.backgroundColor = [UIColor whiteColor];
self.textLabel.textColor = [UIColor darkGrayColor];
self.detailTextLabel.textColor = UIColorFromRGB(0x808080);
timeLabel.textColor = UIColorFromRGB(0x808080);
timeLabel.backgroundColor = [UIColor whiteColor];
}
}
hope this helps some people!

Resources