开发者社区> 问答> 正文

关于给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 1847 0
1 条回答
写回答
取消 提交回答
  • 按钮已经在了,不显示是由于maskToBounds 设置为YES了。改为设置NO试试,然后修正一下button的x,y坐标。

    2019-07-17 19:07:12
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载