2 exit door eXit_door 于 2013.07.09 11:31 提问

给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];
}

2个回答

redCoral_
redCoral_   2013.07.09 14:25
已采纳

按钮已经在了,不显示是由于maskToBounds 设置为YES了。改为设置NO试试,然后修正一下button的x,y坐标。

zhanglei5415
zhanglei5415   Rxr 2013.07.09 13:55

多设置一下UIButton的buttontype试试

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0, 0, 100, 30)];
[button setTitle:@"Click me!" forState:UIControlStateNormal];
[popUp addSubview:button];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!