【问题标题】:Trying to add a subview to a view, but the subview does not show up试图向视图添加子视图,但子视图不显示
【发布时间】:2017-12-12 12:32:20
【问题描述】:

我有一个圆形视图,它被用作我的对象的调整大小,但它的颜色有点主导对象,所以我决定向这个视图添加一个子视图,然后为内部视图着色,以便视图的区域保持不变同时稍微降低颜色优势。

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 75, 75)];
            UIView *innerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50,  50)];
            [view addSubview:innerView];
            view.layer.cornerRadius = CGRectGetWidth(view.frame) * 0.5;
            view.backgroundColor = [UIColor clearColor];
            innerView.alpha = 0;
            //view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.8];
            innerView.backgroundColor = [UIColor colorWithHexString:@"#866BFF"];
            innerView.layer.cornerRadius = CGRectGetWidth(view.frame) * 0.5;
            innerView.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.8].CGColor;
            innerView.layer.borderWidth = 2;
            innerView.center = view.center;
            [view bringSubviewToFront:innerView];
            [self setGestureRecognizer:view];

            [arr addObject:view];

调整大小工作正常,因此正在添加视图,但内部视图颜色不可见。如果我将主视图的颜色更改为红色等,效果会很好。

我不知道为什么没有添加 innerView。

【问题讨论】:

  • innerView.alpha = 0;更改为 alpha=1;并尝试
  • 哦,就是这样,它有效,非常感谢。 :)

标签: ios objective-c uiview


【解决方案1】:

@SritejaC 你的内部视图不可见,因为你的 alpha 是 0 更改为 1

innerView.alpha = 1;

及其作品!!

【讨论】:

    猜你喜欢
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多