Circular UIImageView in UITableView without performance hit?

前端 未结 14 2726
失恋的感觉
失恋的感觉 2020-12-12 09:50

I have a UIImageView on each of my UITableView cells, that display a remote image (using SDWebImage). I\'ve done some QuartzCore

14条回答
  •  悲哀的现实
    2020-12-12 10:14

    In Swift use this Extension for CircularImageView or RoundedImageView :

    extension UIView {
    
        func circular(borderWidth: CGFloat = 0, borderColor: UIColor = UIColor.whiteColor()) {
            let radius = CGRectGetWidth(self.bounds) / 2
            self.layer.cornerRadius = radius
            self.layer.masksToBounds = true
    
            self.layer.borderWidth = borderWidth
            self.layer.borderColor = borderColor.CGColor
        }
    
        func roundedCorner(borderWidth: CGFloat = 0, borderColor: UIColor = UIColor.whiteColor()) {
            let radius = CGRectGetWidth(self.bounds) / 2
            self.layer.cornerRadius = radius / 5
            self.layer.masksToBounds = true
    
            self.layer.borderWidth = borderWidth
            self.layer.borderColor = borderColor.CGColor
        }
    
    }
    

    Usage:

    self.ImageView.circular()
    self.ImageView.roundedCorner()
    

提交回复
热议问题