Square instead of rounded corners in UITableViewCell grouped style

后端 未结 4 1944
無奈伤痛
無奈伤痛 2021-01-01 06:16

I want to have square corners for my grouped tableview cells instead of the default rounded corners, and I don\'t just want to use an image to give that effect. Is it possib

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 06:50

    First set your cell's background view as desired and then set the cell's selected background view (to the same bounds as of cell's background)

    you can specify the cornerRadius property , so that you can set rounding of corners as desired , i have omitted this property in my case

    Here is the code to both :

            UIView *bg = [[UIView alloc] initWithFrame:cell.bounds];
            bg.backgroundColor = [UIColor colorWithRed:0.980 green:0.988 blue:0.984 alpha:1];
            bg.layer.borderColor = [UIColor colorWithRed:0.827 green:0.827 blue:0.835 alpha:1].CGColor;
            bg.layer.borderWidth = kCellBorderWidth;
    //        bg.layer.cornerRadius= kCellBorderRadius;
            cell.backgroundView = bg;
    
            // to make cell selection square and not round (which is by default)
            UIView *bg_selected = [[UIView alloc] initWithFrame:cell.bounds];
            bg_selected.backgroundColor = [UIColor lightGrayColor];
            bg_selected.layer.borderColor = [UIColor colorWithRed:0.827 green:0.827 blue:0.835 alpha:1].CGColor;
            bg_selected.layer.borderWidth = kCellBorderWidth;
            cell.selectedBackgroundView = bg_selected;
    

提交回复
热议问题