How to change UITableViewCell Image to Circle in UITableView

前端 未结 11 1489

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:36

    Here is a perfect and state away solution for circular image in UITableview Cell. Simply modify your UITableviewCell (custom cell) class with below code.

    override func awakeFromNib() {
        super.awakeFromNib()
        imgEvent.layer.frame = (imgEvent.layer.frame).insetBy(dx: 0, dy: 0)
        imgEvent.layer.borderColor = UIColor.gray.cgColor
        imgEvent.layer.cornerRadius = (imgEvent.frame.height)/2
        imgEvent.layer.masksToBounds = false
        imgEvent.clipsToBounds = true
        imgEvent.layer.borderWidth = 0.5
        imgEvent.contentMode = UIViewContentMode.scaleAspectFill
      }
    

    It will also helps to solve the problem of image circular only after scrolling table..(if anyenter image description here)

提交回复
热议问题