尝试和搜索了很多。当超视图的框架很小时,作为子视图添加的按钮远离视图。我不希望它在帧很小时出现。作为子视图添加UIButton远离UIView
UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(20 , 100, 200, 30)];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:@"OK" forState:UIControlStateNormal];
[btn setFrame:CGRectMake(20 , 100, 30, 20)];
[vw sendSubviewToBack:btn];
[vw addSubview:btn];
[vw setBackgroundColor:[UIColor redColor]];
[self.view addSubview:vw];
这是我的代码。它看起来像这样
你知道superview的界限。测试你是否放置按钮。 –
检查第一个视图的UIButton层次.......它改变iOS 7 –
给[btn setFrame:CGRectMake(20,0,30,20)]; – Spynet