我要做的是使用UIBezierPath
drawRectWithRounderCorners 方法在视图周围绘制一个框架。所以我决定做的是从 draw rect 方法中获取 rect,应用一个UIEdgesInset
值为负数的对象并尝试像这样绘制它。到目前为止,UIBezierPath
对象没有在传递给绘制矩形的矩形边界之外绘制。当我将相同的矩形应用于CALayer
对象时,图层会按照我的需要进行绘制。那么为什么我不能让UIBezierPath
对象绘制与对象相同的矩形CALayer
呢?
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:
UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(-5,-5, -5, -5))
byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft
cornerRadii:CGSizeMake(5, 5)];
[[UIColor blueColor]setFill];
[[UIColor blueColor]setStroke];
[path stroke];
[path fill];
CALayer *backGround = [CALayer layer];
[backGround setOpacity:.2];
[backGround setFrame:UIEdgeInsetsInsetRect(rect,
UIEdgeInsetsMake(-5,-5, -5, -5))];
[backGround setBackgroundColor:[UIColor greenColor].CGColor];
[self.layer addSublayer:backGround];
}