在UITableViewCell中隐藏UIImageView的角落

时间:2012-10-19 05:28:58

标签: iphone objective-c ios5

我在UIImageViewUITableViewCell UITableViewStyleGrouped。我将图像放在圆形表格单元格中的(0,0)位置。当我运行应用程序时,我发现UIImageView仍显示其左角。单元格内的Imageview不会被剪裁。任何人都可以在没有设置UIImageView的角半径的情况下找到解决方案。

2 个答案:

答案 0 :(得分:2)

我认为这样做的方法是使用图层蒙版和圆角半径。方法如下:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:frame
                                                           byRoundingCorners:UIRectCornerAllCorners
                                                                 cornerRadii:CGSizeMake(5.0, 5.0)];
            // Create the shape layer and set its path
            CAShapeLayer *maskLayer = [CAShapeLayer layer];
            maskLayer.frame = frame;
            maskLayer.path = maskPath.CGPath;
            // Set the newly created shape layer as the mask for the image view's layer
            imageView.layer.mask = maskLayer;
imageView.layer.cornerRadius = 5.0;

假设frame是您的imageview的框架。并且,不要忘记#import <QuartzCore/QuartzCore.h>。祝你好运!

答案 1 :(得分:0)

您可以尝试将单元格的clipsToBounds属性设置为YES,看看是否能为您提供所需的结果。