this video과 비슷한 가로로 스크롤 가능한 메뉴를 만들려고합니다.UIScrollView의 UIView가 나타나지 않습니다.
UIView
은 UIButtons
묶음을 추가하고 UIScrollView
에 추가 한 후에 표시되지 않습니다. 여기 내 코드는 (은 UIViewController
의 서브 클래스의 -viewDidLoad
에 불렀다)입니다 :
//set up scrollview
UIScrollView *designPicker = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 431, 320, 49)];
//set up a view to drop into the scroll view
UIView * buttonsView = [[UIView alloc] initWithFrame:CGRectMake(0, 431, 640, 49)];
//add buttons to scrollview
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
float runningX = designPicker.frame.origin.x;
for (i = 1; i <= 10; i++)
{
UIButton *tempBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[tempBtn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
CGRect rect = CGRectMake(runningX, designPicker.frame.origin.y, 30.0, 30.0);
tempBtn.frame = rect;
[buttonsView addSubview:tempBtn];
runningX = runningX + 35;
[tempBtn release];
}
[designPicker setContentSize:buttonsView.frame.size];
[designPicker addSubview:buttonsView];
[self.view addSubview:designPicker];
Diederik에게 감사드립니다. UIScrollView는 뷰의 하위 뷰이기 때문에 버튼의 프레임은 UIView와 관련이 있습니다. 따라서 버튼의 프레임은 UIScrollView의 수퍼 뷰와 관련이 있습니다. 어쩌면 내가 뭔가를 놓친거야? 감사! –