我創建了一個基於輸入大小創建子視圖的方法,所以沒有定義和默認的角落CGRect值。我想要創建一個解僱按鈕,將位於左上角每個子視圖的角落。目前我使用這種方法來添加它,但問題在於CGRectMake的值不能是靜態的。獲取創建子視圖的動態座標ios
CGRect tapToDismissFrame = CGRectMake(50.0f, 50.0f, 400.0f, 400.0f);
UIButton *tapToDismiss = [[UIButton alloc] initWithFrame:tapToDismissFrame];
tapToDismiss.backgroundColor = [UIColor clearColor];
tapToDismiss.titleLabel.font = [UIFont fontWithName:[NSString stringWithFormat:@"Helvetica-Bold"] size:20];
[tapToDismiss setTitle:@"⊗" forState:UIControlStateNormal];
[tapToDismiss setTitleColor:[UIColor colorWithRed:173.0/255.0 green:36.0/255.0 blue:36.0/255.0 alpha:1.0] forState:UIControlStateNormal];
[tapToDismiss addTarget:self action:@selector(tapToDismissClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.maskView addSubview:tapToDismiss];
如何獲取動態值以便在左上角或右上角創建它。
爲什麼不使用佈局約束來定位按鈕? – rdelmar 2014-10-30 00:19:25