2012-10-19 64 views
1

我有一個UIImageViewUITableViewCell與。我將圖像放置在圓形表格單元的(0,0)位置。當我運行應用程序時,我發現UIImageView仍然顯示其左上角。單元格內的Imageview未被剪切。沒有設置UIImageView的圓角半徑,任何人都可以有解決方案。隱藏在UITableViewCell中的UIImageView的角落

回答

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>。祝你好運!

+0

法赫裏阿濟莫夫thaks好的......但ineed只有左角落掩蓋...... – krishh

+0

然後在路徑指定 - 'UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:框架 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake( 5.0,5.0)];' –

+0

Fahri Azimov是啊那得到了...再次感謝... – krishh

0

您可以嘗試將單元格的clipsToBounds屬性設置爲YES並查看是否給出了期望的結果。