0
我想要做的是使用UIBezierPath
drawRectWithRounderCorners方法在視圖周圍畫一個框架。所以我決定做的是從繪製矩形方法中取出矩形,應用一個具有負值的UIEdgesInset
對象並嘗試像這樣繪製它。到目前爲止,UIBezierPath
對象不是繪製rect傳遞的矩形邊界之外的繪圖。當我將同一個矩形應用於一個CALayer
對象時,該圖層會根據需要進行繪製。那麼我怎麼不能讓UIBezierPath
對象繪製與CALayer
對象相同的矩形?爲什麼我的UIBeizerPath對象不能像我的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];
}
非常感謝你的傢伙 – Esko918