嘗試和搜索了很多。當超視圖的框架很小時,作爲子視圖添加的按鈕遠離視圖。我不希望它在幀很小時出現。作爲子視圖添加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