Iphone 在UIScrollView中管理图像
我不明白在我的代码中,我在图像名称中写的位置,以及出现的顺序。这是我的密码Iphone 在UIScrollView中管理图像,iphone,image,uiscrollview,Iphone,Image,Uiscrollview,我不明白在我的代码中,我在图像名称中写的位置,以及出现的顺序。这是我的密码 // load all the images from our bundle and add them to the scroll view NSUInteger i; for (i = 1; i <= kNumImages; i++) { NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i]; UIImage *im
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//从我们的包中加载所有图像并将它们添加到滚动视图中
NSUI;
对于(i=1;i
将%d用于签名整数
%u表示未签名的您的代码段已经在做您想做的事情了-至少部分是这样
如果图像编号为0,则需要以i=0而不是i=1开始循环,并适当调整约束:
for (NSUInteger i = 0; i < kNumImages; i++) {
NSString *imageName = [NSString stringWithFormat:@"image%u.jpg", i];
// create the image and insert into imageview
// add imageview to the containing view
}
for(整数i=0;i
顺序非常简单,因为图像将使用第一篇文章中的代码添加0、1、2……等等,您可以创建多个(更具体地说是kNumImages)图像视图,并从项目目录中加载JPG文件,称为“imageN.JPG”,其中N是1和kNumImages之间的整数
要在UIScrollView中显示这些新创建的视图,必须将它们作为子视图添加到UIScrollView中
差不多
for (int i = 0; i < pageCount; i++) {
UIView *view = [pageViews objectAtIndex:i];
if (!view.superview)
[scrollView addSubview:view];
view.frame = CGRectMake(pageSize.width * i, 0, pageSize.width, pageSize.height);
}
for(int i=0;i
最直接的方法是在UIScrollView的UIViewController中。您可能希望将它们添加到某种集合中(集合可能会保留它们,因此在添加视图时不要忘记释放它们)
随着您对应用程序越来越熟悉,您可能希望延迟加载视图,或者对不同的图像使用简单的UIViewController
在iPhoneOS3.0及更高版本中,UIScrollView有显著改进,您可以在ADC的iPhone部分的ScrollViewSuite教程项目中找到优秀的代码示例