我有一个滚动器,我希望能够在视图之间滚动,例如像这样的简单图像视图。我在这里设置它们:
UIImageView *settingsView = [[UIImageView alloc] init];
[settingsView setImage:[UIImage imageNamed:@"1.jpg"]];
UIImageView *cameraView = [[UIImageView alloc] init];
[cameraView setImage:[UIImage imageNamed:@"2.jpg"]];
接下来我想把这些 ImageViews 放入我的 ScrollView 数组中。我试着这样做:
int PageCount = 2;
NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:settingsView,cameraView,nil];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroller.scrollEnabled=YES;
scroller.backgroundColor = [UIColor clearColor];
[scroller setShowsHorizontalScrollIndicator:NO];
scroller.pagingEnabled = YES;
scroller.bounces = NO;
scroller.delegate = self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;
for (int i=0; i<PageCount; i++)
{
UIImageView *ImgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
[ImgView setImage:[UIImage imageNamed:[arrImageName objectAtIndex:i]]];
[scroller addSubview:ImgView];
scroller.contentSize = CGSizeMake(width, 0);
width +=scroller.frame.size.width;
xPos +=scroller.frame.size.width;
}
我得到的错误是'NSInvalidArgumentException', reason: '-[UIImageView stringByDeletingPathExtension]: unrecognized selector sent to instance
我怎样才能将这些视图放在滚动条内?谢谢!