How to change UITableViewCell Image to Circle in UITableView

前端 未结 11 1506

My code works for the most part.

  • The issue I am having is the images start out as square, and change to circle when I scroll the table or refresh it.

11条回答
  •  梦谈多话
    2021-02-12 12:42

    Create a custom cell, and add an image view (with an IBOutlet), sized and positioned however you want (the outlet is "iv" in my example below). Put the code to make image view round in the awakeFromNib method (assuming your cell is created in a nib or storyboard).

    -(void)awakeFromNib {
        self.iv.layer.cornerRadius = self.iv.frame.size.width / 2.0;
        self.iv.layer.borderWidth = 3.0;
        self.iv.layer.borderColor = [UIColor colorWithRed:157.0/255.0 green:34.0/255.0 blue:53.0/255.0 alpha:1.0].CGColor;
        self.iv.clipsToBounds = YES;
    }
    

提交回复
热议问题