가장 쉽고 성능이 좋은 해결책은 아마 UIImageView
를 사용하고 그 층의 마스크로 CAShapeLayer
을 적용하는 것입니다.
예 :
UIImage *image = ...;
CGFloat ringWidth = 20.0;
CGRect outerCircleRect = CGRectMake(0, 0, image.size.width, image.size.height);
CGRect innerCircleRect = CGRectInset(outerCircleRect, ringWidth, ringWidth);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:outerCircleRect];
[path appendPath:[UIBezierPath bezierPathWithOvalInRect:innerCircleRect]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.fillRule = kCAFillRuleEvenOdd;
shapeLayer.path = [path CGPath];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
imageView.layer.mask = shapeLayer;
[self.view addSubview:imageView];
당신은이 작업을위한 QuartzCore 프레임 워크를 포함해야합니다.
내부 원의 반지름을 변경하면 간단히 모양 레이어에 새 경로를 지정할 수 있습니다. 이것은 심지어 움직일 수 있습니다.
출처
2012-02-11 20:58:19
omz
FWIW, 내부 원형 디스크가 잘린 원형 디스크의 용어는 "고리"입니다. – Benjohn