我打算使用以下代码行来添加"圆形视图":
_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,但四条边似乎仍有点剪裁。
任何指导都将不胜感激。
答案 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;
尝试上面的代码。