【问题标题】:Add Subview above mainviews layer在 mainviews 层上方添加 Subview
【发布时间】:2012-11-10 22:36:31
【问题描述】:

我在其父视图的 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];

【问题讨论】:

    标签: ios xcode uiview calayer subview


    【解决方案1】:

    到目前为止这是不可能的,我能想到的最好的解决方案是将子视图及其父视图都添加到另一个视图中,而不仅仅是重新排序两个子视图,以便您的子视图位于另一个及其边界之上.

    希望有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多