简体   繁体   中英

How to change background color of UITableViewCell using my own color combination

actually i have found some thread that asking question like mine. but every solution that given in those thread can not be use in my code.. the last link i was read is How to customize the background color of a UITableViewCell?

my problem is i just want to change my tableviewcell background color with my own color. can somebody help me??

How about something like:

[myCell setBackgroundColor:[UIColor colorWithRed:0.2 blue:0.5 green:0.2 alpha:1]];

One place you could put this would be your table view's willDisplayCell:forRowAtIndexPath: data source method. Or else you could subclass UITableViewCell and set it in your overridden initializer. Or you could load the cell from a XIB and use Interface Builder to set the color.

try this..

cell.backGroundColor = [UIColor colorWithRed:190.0/255.0 blue:190.0/255.0 green:190.0/255.0 alpha:1.0];

Write this code in cellForRowAtIndexPath function. U will get these kind of different RGB combinations simply from MS Paint and alpha is the opacity ranging in between 0.0 to 1.0 .

Before iOS 7 Simply add this method

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{

       [cell setBackgroundColor:[UIColor colorWithRed:(221.0/255.0) green:(221.0/255.0) blue:(221.0/255.0) alpha:1.0]];

}

Now in iOS 7 if you put this code in cellForRowAtIndexPath it will work

[cell setBackgroundColor:[UIColor colorWithRed:(221.0/255.0) green:(221.0/255.0) blue:(221.0/255.0) alpha:1.0]];

另一个链接,帮助这个问题... UITableViewCell颜色问题与自定义表视图背景

finnaly i found out how to solve this problem. but i was choose to use an image. I was declare my way to solve it in my another question in : is there somebody who made an application using background for tableview and tableviewcell?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM