请帮忙。我有这段代码可以在滚动视图中显示图像。:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *imgNames = [[NSArray alloc] initWithObjects:@"ip1.jpg", @"ip2.jpg", @"ip3.jpg", @"ip4.jpg", @"ip5.jpg", @"ip6.jpg", @"ip7.jpg", @"ip8.jpg", @"ip9.jpg", @"ip10.jpg",@"ip11.jpg",@"ip12.jpg",@"ip13.jpg",@"ip14.jpg",@"ip15.jpg",@"ip16.jpg",@"ip17.jpg",@"ip18.jpg",@"ip19.jpg",@"ip20.jpg",@"ip21.jpg", nil];
// Setup the array of UIImageViews
NSMutableArray *imgArray = [[NSMutableArray alloc] init];
UIImageView *tempImageView;
for(NSString *name in imgNames) {
tempImageView = [[UIImageView alloc] init];
tempImageView.contentMode = UIViewContentModeScaleAspectFill;
tempImageView.image = [UIImage imageNamed:name];
[imgArray addObject:tempImageView];
}
CGSize pageSize = scrollViewBack.frame.size; // scrollView is an IBOutlet for our UIScrollView
NSUInteger page = 0;
for(UIView *view in imgArray) {
[scrollViewBack addSubview:view];
// This is the important line
view.frame = CGRectMake(pageSize.width * page++ + 40, 0, pageSize.width - 80, pageSize.height);
}
scrollViewBack.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height);
}
现在,我想要一个 UILabel,它会在我滚动时显示图像名称。请帮助我,我无法实现。非常感谢。