在用户点击屏幕时,应该有一个带按钮的弹出窗出现。但是弹出窗出现,按钮没出现。不知道哪出错了。是在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];
}
按钮已经在了,不显示是由于maskToBounds 设置为YES了。改为设置NO试试,然后修正一下button的x,y坐标。
多设置一下UIButton的buttontype试试
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0, 0, 100, 30)];
[button setTitle:@"Click me!" forState:UIControlStateNormal];
[popUp addSubview:button];