Dưới đây là mẫu mã:Tại sao đột quỵ của CAShapeLayer mở rộng ra khỏi khung?
//Called by VC:
HICircleView *circleView = [[HICircleView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
// init of circle view
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAShapeLayer *borderLayer = [CAShapeLayer layer];
borderLayer.fillColor = [UIColor whiteColor].CGColor;
borderLayer.path = [UIBezierPath bezierPathWithOvalInRect:self.frame].CGPath;
borderLayer.strokeColor = [[UIColor redColor] CGColor];
borderLayer.lineWidth = 5;
[self.layer addSublayer:borderLayer];
}
return self;
}
OK, cảm ơn vì câu trả lời. để dịch chuyển i:
CGRect rect = CGRectMake(3, 3, self.frame.size.width, self.frame.size.height);
borderLayer.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath;
Và thực hiện 6 chiều rộng đường kẻ.
THanks. Bạn có thể giải thích làm thế nào để thay đổi đường dẫn đường? Đừng bận tâm. Hiểu rồi. –
Tôi đã cập nhật câu trả lời của mình, hy vọng rằng nó đã rõ ràng hơn một chút. – Sebastian