Draw a Custom cell for tableview (UITableView), with changed colors and separator color and width

后端 未结 3 2015
囚心锁ツ
囚心锁ツ 2020-12-09 07:21

I want to draw the background of a UITableViewCell which has a grouped style. The problem with me is I am not able to call the -(void)drawRect:(CGRect)rect or I

3条回答
  •  一整个雨季
    2020-12-09 07:44

    I have to agree with Sbrocket.

    You need two lines of code. Four lines if you want to use a custom color for the line separator and border.

    // For cell background
     cell.backgroundColor=[UIColor lightGrayColor];
    
    // For tableView line separator (assuming IBOutlet UITableView* table;)
    self.table.separatorColor=[UIColor redColor];
    
    //If you need a custom color (I assume you do), then...
     cell.backgroundColor=[UIColor colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha];
    

    Drop in the RGB value for any color you like for both the cell background and line separator.

    Couldn't be easier.

提交回复
热议问题