我需要以編程方式創建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];
謝謝,已經解決=) –