我定制了一个BWLabel来绘制标签的边框。
- (void)drawRect:(CGRect)rect {
CGRect frame = self.frame;
UIBezierPath *linePath = [UIBezierPath bezierPath];
[linePath moveToPoint:CGPointMake(0,0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, 0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, frame.size.height)];
[linePath addLineToPoint:CGPointMake(0, frame.size.height)];
CAShapeLayer *lineLayer = [CAShapeLayer layer];
lineLayer.lineWidth = 3.0f;
lineLayer.strokeColor = [[UIColor whiteColor] CGColor];
lineLayer.path = linePath.CGPath;
[self.layer addSublayer:lineLayer];
}
我使用Debug View Hierarchy来查看BWLabel。
我有一个问题,为什么CAShapeLayer不满?
答案 0 :(得分:0)
你的绘制矩形应该是这样的
- (void)drawRect:(CGRect)rect
{
CGRect frame = self.frame;
UIBezierPath *linePath = [UIBezierPath bezierPath];
[linePath moveToPoint:CGPointMake(0,0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, 0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, frame.size.height)];
[linePath addLineToPoint:CGPointMake(0, frame.size.height)];
[linePath addLineToPoint:CGPointMake(0, 0)];
CAShapeLayer *lineLayer = [CAShapeLayer layer];
lineLayer.lineWidth = 3.0f;
lineLayer.strokeColor = [[UIColor whiteColor] CGColor];
lineLayer.path = linePath.CGPath;
[self.layer addSublayer:lineLayer];
}