我有一个UIView
,我是这样定义它的边框的:
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 3;
我将一个子视图附加到这个UIView
,当我移动子视图超过边界时,它会被遮盖。这是预期行为吗?有没有办法让子视图在其上方?
我有一个UIView
,我是这样定义它的边框的:
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 3;
我将一个子视图附加到这个UIView
,当我移动子视图超过边界时,它会被遮盖。这是预期行为吗?有没有办法让子视图在其上方?
它在接收者的内容和子层之上进行合成。
因此,边框将始终位于所有子视图之上,即使您将子视图置于最前面等等。UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
backgroundView.backgroundColor = [UIColor blackColor];
backgroundView.clipsToBounds = NO;
UIView *bView = [[UIView alloc] initWithFrame:CGRectInset(backgroundView.bounds, 3, 3)];
bView.backgroundColor = [UIColor redColor];
UIView *cView = [[UIView alloc] initWithFrame:CGRectMake(-50, -50, 100, 100)];
cView.backgroundColor = [UIColor yellowColor];
[bView addSubview:cView];
[backgroundView addSubview:bView];
[self.window addSubview:backgroundView];
以及效果:
CustomView
,它的.view
就是border
,而且CustomView
有一个名为yourView
的UIView
属性。yourView
是你真正有用的视图,而且yourView
是CustomView
的子视图之一。.view
- Guo Luchuan在适合你的特定位置插入层:
self.layer.insertSublayer(sublayer, at: 0)