我想覆盖我的自定义视图中的UIView的drawRect:
方法。然而,我的观点已经边框半径定义为:UIView覆盖drawRect导致视图不服从掩码ToBounds
sub = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:self options:nil] objectAtIndex:0];
[self addSubview:sub];
[sub setUserInteractionEnabled:YES];
[self setUserInteractionEnabled:YES];
CALayer *layer = sub.layer;
layer.masksToBounds = YES;
layer.borderWidth = 5.0;
layer.borderColor = [UIColor whiteColor].CGColor;
layer.cornerRadius = 30.0;
这完美的作品,并把一个漂亮的边框周围我的观点边框半径(不介意对角/直白线在后面,他们没有与该视图做):
然而,当我尝试重写drawRect:
方法在我看来,我可以看到一个黑色的背景不遮蔽到边界。我没有做任何事情(目前),这里是我的代码:
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
}
这里是结果:
我改变什么,但平局方法。我怎样才能重写绘制方法,同时保持我的视图服从角圆角掩模?这是iOS中的错误还是我错过了一些东西?
这是正确的答案。 – Randy