开发者社区 问答 正文

关于给subView添加UIButton

在用户点击屏幕时,应该有一个带按钮的弹出窗出现。但是弹出窗出现,按钮没出现。不知道哪出错了。是在

subView中的subView。
-(void) popUpWithX:(int)x andY:(int)y {
    CGRect popUpRect = CGRectMake(x, y, 125, 75);
    popUp = [[UIView alloc] initWithFrame:popUpRect];
    popUp.backgroundColor = [UIColor whiteColor];
    popUp.layer.cornerRadius = 7.5f;
    popUp.layer.masksToBounds = YES;

    [self.view addSubview:popUp];
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [button setTitle:@"Click me!" forState:UIControlStateNormal];
    [popUp addSubview:button];
}

展开
收起
爵霸 2016-03-19 09:17:21 1939 分享 版权
1 条回答
写回答
取消 提交回答
  • 按钮已经在了,不显示是由于maskToBounds 设置为YES了。改为设置NO试试,然后修正一下button的x,y坐标。

    2019-07-17 19:07:12
    赞同 展开评论
问答地址: