iPhone图片库源代码 [英] IPhone picture gallery source code

查看:171
本文介绍了iPhone图片库源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI所有
有人可以推荐我,iphone图片库源代码吗?
任何链接,示例代码都会有很大帮助。

HI all can anyone please refer me, the iphone image gallery source code? Any link ,sample code will be great help.

我试图以缩略图的形式展示70到100张图片,并且在选择任何图片时,它应该是给出一个完整的图像,我想要完成,无论iphone的图片库,
i想到,必须有任何示例代码。
建议永远赞赏

i am trying to show some 70 to 100 images as thumbnails , and on selecting any image, it should give a full view of that image,i am trying to accomplish, whatever is in iphone's picture gallery, i thought, there must any sample code available. suggestions are always appreciated

问候

推荐答案

In didload方法调用两个方法来创建滚动视图和缩略图按钮。以相同的顺序保存缩略图图像和壁纸图像数组。

In didload method call two methods to create scroll view and thumbnail button.Keep both thumbnail images and wallpaper images array in the same order.

-(void)createScrollView
{
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(320 * (([imagesArray count]- 1) / 25 + 1), 440);

scrollView.backgroundColor=[UIColor blackColor];
[self.view addSubview:scrollView];

}

 -(void)createButton{
for (int i = 0; i < [imagesArray count]; i++) 
{

    thumbNailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    thumbNailButton.frame = CGRectMake(6 + 62 * (i % 5) + 320 * (i / 25), 5+65 * ((i / 5) % 5), 56,56);

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 56, 56)];
    [img setImage:[UIImage imageNamed:[imagesArray objectAtIndex:i]]];
    thumbNailButton.tag=i;
    [thumbNailButton addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];   
    [thumbNailButton addSubview:img];
    [scrollView addSubview:thumbNailButton];

}

}

 -(void)imageClicked:(id)sender{
UIButton* button = (UIButton*)sender;
    AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate setimageClickedValue:button.tag];

LargeWallPaperviewController *largeWallPaperViewController=[[LargeWallPaperviewController alloc]initWithNibName:@"LargeWallPaperviewController" bundle:nil];
[self.navigationController pushViewController:largeWallPaperViewController animated:YES];
[largeWallPaperViewController release];
}

在didload方法的largewallpaperviewcontroller类中

In largewallpaperviewcontroller class in didload method

   [imagesArray addObjectsFromArray:[NSArray arrayWithObjects:@"wallf1.jpg",@"wallf2.jpg",@"wallf3.jpg",@"wallf4.jpg",@"wallf5.jpg",@"wallf6.jpg",@"wallf7.jpg",nil]];

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(320 * ([imagesArray count] ), 440);
scrollView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scrollView];

for (int i = 0; i < [imagesArray count]; i++) 
{

    wallPaperButton=[UIButton buttonWithType:UIButtonTypeCustom];
    wallPaperButton.tag=i;
    wallPaperButton.frame=CGRectMake((320*i),0, 320, 325);

    UIImageView *img =[ [UIImageView alloc]initWithFrame:CGRectMake(0,0, 320, 325)];

    img.image=[UIImage imageNamed:[imagesArray objectAtIndex:i]];
    img.contentMode=UIViewContentModeScaleAspectFit;            
    [wallPaperButton addSubview:img];
    [img release];


    [wallPaperButton addTarget:self action:@selector(imageSelected:) forControlEvents:UIControlEventTouchUpInside];     [scrollView addSubview:wallPaperButton];
}
appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
int imageValue=[appDelegate getimageClickedValue];
[scrollView scrollRectToVisible:CGRectMake(320*imageValue, 0, 320 , 440) animated:NO];

我在largewallpaer视图中使用了一个按钮。如果你想删除它并直接添加到图像视图。这个代码对我有用,可以根据您的要求进行更改。它很容易理解。

i have used a button in the largewallpaer view.If you want you remove it and directly add it to image view.This code is working for me ,change it to your requirement.Its easy to understand.

一切都很好。

这篇关于iPhone图片库源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆