我需要以编程方式创建UIButton
,然后将它放在创建的UIScrollView
上,然后将UIScrollView
放在UIView
上。如果将这些元素添加到self.view
中,则会显示它们,但是当我想嵌套时,则不会显示它们。 这是我到目前为止有:将UIButton添加到UIScrollView,然后将UIScrollView添加到UIView
viewWithPictures=[[UIScrollView alloc] initWithFrame:self.bottomView.frame];
viewWithPictures.contentSize=CGSizeMake(160*[smallImagesFromGallery count], self.bottomView.frame.size.height);
viewWithPictures.backgroundColor=[UIColor greenColor];
NSLog(@"Number of small images: %i",[smallImagesFromGallery count]);
for(int i=0; i<[smallImagesFromGallery count]; i++)
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(self.bottomView.frame.origin.x+i*160, self.bottomView.frame.origin.y, 150, 100);
[btn setBackgroundImage:[smallImagesFromGallery objectAtIndex:i] forState:UIControlStateNormal];
if (btn==nil) {
NSLog(@"Button is nil");
}
btn.tag=i;
[btn addTarget:self action:@selector(viewLargeVersion:) forControlEvents:UIControlEventTouchUpInside];
[viewWithPictures addSubview:btn];
}
[bottomView addSubview:viewWithPictures];
谢谢,已经解决=) –