當用戶在屏幕上點擊時,彈出窗口應該會顯示一個按鈕。 但我不知道爲什麼按鈕不顯示在PopUp中。是否有問題,因爲它是子視圖中的子視圖?將UIButton添加到子視圖
-(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];
}
編輯:
是否有可能在UIButton的座標是錯誤的?我不確定座標系是來自主視圖還是來自彈出子視圖。
座標來自彈出窗口,而不是主視圖。這很可能不是問題。 –