图像在圈子框架iOS

我有一个联系人列表uitableview。 我想要像在特立独行的login屏幕中的每个联系人的图像。 任何build议如何在uitableviewCell中做到这一点?

在这里输入图像说明

我认为你的cellView里面有你的imageView,所以你只需要做一个效果就是使用一个不可见的边框。 使用这个代码来达到这个效果:

cell.yourImageView.layer.cornerRadius = cell.yourImageView.frame.size.height /2; cell.yourImageView.layer.masksToBounds = YES; cell.yourImageView.layer.borderWidth = 0; 

您的UIImageView必须具有相同的高度和宽度,您还必须在项目中导入quartzCore框架

显然我可以这样做一个圆形的矩形

 float fw, fh; if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, rect); return; } CGContextSaveGState(context); CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect)); CGContextScaleCTM (context, ovalWidth, ovalHeight); fw = CGRectGetWidth (rect) / ovalWidth; fh = CGRectGetHeight (rect) / ovalHeight; CGContextMoveToPoint(context, fw, fh/2); CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); CGContextClosePath(context); CGContextRestoreGState(context); 

然后把图像放在里面,它会自动剪切:

  CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); addRoundedRectToPath(context, self.frame, 10, 10); CGContextClip(context); [image drawInRect:self.frame]; CGContextRestoreGState(context);