我创建了一个基于输入大小创建子视图的方法,所以没有定义和默认的角落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