美文网首页
ios-label上添加button不显示的解决办法

ios-label上添加button不显示的解决办法

作者: 那一处风景ljz | 来源:发表于2017-06-30 18:24 被阅读207次
    效果图 2017-06-30 下午6.22.36.png

    使用两个view

    {
        UILabel *aLabel;
    
        UIView *bView;
        UIView *cView;
    
        UIButton *btn;
    
    }
    
    bView =[[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.width)];
        [self.view addSubview:bView];
        bView.userInteractionEnabled = YES;
        bView.backgroundColor=[UIColor colorWithWhite:0.1 alpha:0.9];
    
    
        cView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 260)];
        cView.userInteractionEnabled = YES;
        [bView addSubview:cView];
        cView.backgroundColor=[UIColor blueColor];
    
    
        aLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 260, 260)];
        aLabel.userInteractionEnabled = YES;
        aLabel.numberOfLines = 0;
        aLabel.text = @"有文字的这里";//这里是文字。假如是数字的话就不需要cView也行。
        aLabel.font = [UIFont systemFontOfSize:12];
        [bView addSubview:aLabel];
        aLabel.backgroundColor=[UIColor clearColor];//设置成透明,相当于一个覆盖
    
    
        btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(0, 0, 80, 40);
        [btn setBackgroundColor:[UIColor redColor]];
        [btn setTitle:[NSString stringWithFormat:@"不显示吗"] forState:UIControlStateNormal];
        [aLabel addSubview:btn];
    

    相关文章

      网友评论

          本文标题:ios-label上添加button不显示的解决办法

          本文链接:https://www.haomeiwen.com/subject/jkeicxtx.html