我有一个带有联系人列表的 uitableview。我想在小牛的登录屏幕中将每个联系人的图像放在一个圆形框架中。任何建议如何在 uitableviewCell 中执行此操作?
问问题
24740 次
2 回答
75
我假设你的 Cell 中有你的 imageView,所以你要做的就是使用一个不可见的边框来达到同样的效果。使用此代码产生这种效果:
cell.yourImageView.layer.cornerRadius = cell.yourImageView.frame.size.height /2;
cell.yourImageView.layer.masksToBounds = YES;
cell.yourImageView.layer.borderWidth = 0;
您的 UIImageView 必须具有相同的高度和宽度,您还必须在项目中导入quartzCore 框架
于 2013-10-28T17:13:05.657 回答
1
显然我可以像这样做一个圆角矩形
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);
于 2013-10-28T17:09:41.303 回答