创建100%轮UIView / UIImageview

时间:2016-07-01 03:01:35

标签: ios objective-c uiview uiimageview

我打算使用以下代码行来添加"圆形视图":

_myBackView = [[UIView alloc] initWithFrame:rect];
_myBackView.backgroundColor = [UIColor colorWithR:153 G:85 B:57 alpha:1.0];
_myBackView.layer.cornerRadius = artworkViewWidth / 2;
_myBackView.layer.masksToBounds = YES;
_myBackView.layer.borderWidth = 0;
_myBackView.clipsToBounds = NO;
[self.view addSubview:_myBackView];

视图创建得很好,看起来大多是圆的。但问题是它似乎没有" 100%回合" - 尽管我将clipsToBounds属性设置为NO,但四条边似乎仍有点剪裁。

任何指导都将不胜感激。

编辑:刚添加了repro图片。请注意被夹住的4个边缘。 repro picture

2 个答案:

答案 0 :(得分:0)

你可以尝试这个(使用圆形png遮罩层)

- (void)useMaskFor: (UIView*)colorArea {

    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame = colorArea.bounds;
    UIImage *maskImage = [UIImage imageNamed:@"cirMask.png"];
    maskLayer.contents = (__bridge id)maskImage.CGImage;
    colorArea.layer.mask = maskLayer;
}

回答How to draw a custom UIView that is just a circle - iPhone app

答案 1 :(得分:0)

 _image.layer.cornerRadius = _image.frame.size.height/2;

 _image.layer.masksToBounds = YES;

尝试上面的代码。