我在其父视图的CALayer上方添加子视图时遇到问题。
我试图附上图片以显示我的意思,但我没有足够的声誉,所以这里是图像的链接:
http://imageshack.us/photo/my-images/843/img0219u.png/
部分子视图被父视图边框遮挡。
如何让子视图显示在父视图图层的顶部?
感谢任何帮助。
如果有帮助,这是我的代码:
添加图层的代码:
UIView *student = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
student.backgroundColor = [UIColor grayColor];
CALayer *studentLayer = [[CALayer alloc] init];
studentLayer.borderColor = [UIColor grayColor].CGColor;
studentLayer.borderWidth = 5;
student.layer.borderColor = studentLayer.borderColor;
student.layer.borderWidth = studentLayer.borderWidth;
添加子视图的代码:
UILabel *ilp = [[UILabel alloc] initWithFrame:(CGRectMake(-20, -10, 40, 20))];
ilp.text = @"ILP";
ilp.backgroundColor = [UIColor yellowColor];
ilp.textColor = [UIColor blackColor];
ilp.textAlignment = NSTextAlignmentCenter;
[student addSubview:ilp];
答案 0 :(得分:4)
希望有所帮助!