嗨朋友我必须开发一个照片管理应用程序。在这里,我的图像应该在我的 iphone 中以 gris 视图排列。我在谷歌中分析了一些框架工作。下面的列表是
1.UICollectionView
2.AQGridView _
下面列出了我在网格视图中的功能
- 该应用程序应与 4.3 以上的 iOS 兼容
网格视图单元格允许
UITapGestureRecognizer
删除图像单元格或编辑样式选项,如表格视图。创建自定义 GridView 单元格
请任何人都可以向我推荐哪一个适合开发
嗨朋友我必须开发一个照片管理应用程序。在这里,我的图像应该在我的 iphone 中以 gris 视图排列。我在谷歌中分析了一些框架工作。下面的列表是
1.UICollectionView
2.AQGridView _
下面列出了我在网格视图中的功能
网格视图单元格允许UITapGestureRecognizer
删除图像单元格或编辑样式选项,如表格视图。
创建自定义 GridView 单元格
请任何人都可以向我推荐哪一个适合开发
如果您创建自定义按钮,将图像路径存储在数组中,编写 for 循环以显示每行中的图像数量会更好。将这些图像插入到每个自定义按钮中。它现在看起来像一个缩略图视图。
像这样的东西,
imageArray =[[NSMutableArray alloc]init];
for (NSString* path in imagePath)
{
[imageArray addObject:[UIImage imageWithContentsOfFile:path]];
NSLog(@"%@",path);
}
NSLog(@"%@",imageArray);
NSLog(@"Yes");
myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 840.0)];
myScrollView.delegate = self;
myScrollView.contentSize = CGSizeMake(320.0, 840.0);
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
float horizontal = 8.0;
float vertical = 8.0;
for(int i=0; i<[imageArray count]; i++)
{
if((i%4) == 0 && i!=0)
{
horizontal = 8.0;
vertical = vertical + 70.0 + 8.0;
}
buttonImage = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonImage setFrame:CGRectMake(horizontal, vertical, 70.0, 70.0)];
[buttonImage setTag:i];
[buttonImage setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
[buttonImage addTarget:self action:@selector(buttonImagePressedSmiley forControlEvents:UIControlEventTouchUpInside];
[buttonImage setImage:[UIImage imageNamed:@"check.jpg"] forState:UIControlStateSelected];
[myScrollView addSubview:buttonImage];
horizontal = horizontal + 70.0 + 8.0;
}
[myScrollView setContentSize:CGSizeMake(320.0, vertical + 78.0)];
说明:
图像的路径存储在 imagePath 中。然后我们将 imagePath 存储在一个字符串(路径)中。现在,我们正在向 imageArray 添加路径的内容。因此 imageArray 现在包含所有图像的路径。然后创建一个 for 循环来显示每行 4 张图像。创建一个自定义按钮并在按钮上,一张一张地插入每个图像(使用 imageArray)。创建一个滚动视图以将所有按钮图像放入其中。
您现在已完成为图像创建 4*4 网格视图。快乐的编码...
似乎 PSTCollectionView 是您所需要的。
它类似于 UICollectionView,但适用于 iOS 4.3。
您可以通过覆盖 dataSource 方法来创建自定义单元格:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
同样在这种方法中,您可以将手势识别器添加到您的单元格。
我目前正在使用AQGridView
,所以我推荐它,因为它是最少的错误,它的功能与UITableView
.
此外,如果您尝试在没有XIB的情况下执行此操作,您将很难处理它,但您可以使用 Xib 文件创建视图控制器来创建您选择的界面。这是有关如何以最佳方式完成此操作的视频 Evadne Wu
。这是示例项目
ViewController.h
{
NSMutableArray *galleryarray;
}
@property (retain, nonatomic) IBOutlet UIScrollView *scrolll_photo;
ViewController.m
[self gallery];
Secondview.h
NSMutableArray *imagesArraySlide;
int imageCount;
@property (retain, nonatomic) IBOutlet UIScrollView *photoscroll;
@property (nonatomic, retain) NSMutableArray *imagesArraySlide;
@property (readwrite) int imageCount;
@property (readwrite) int imageID;
Secondview.m
[self loadphoto];
-(void)loadphoto
{
NSArray *viewsToRemove = [_photoscroll subviews];
for (UIView *view in viewsToRemove)
{
[view removeFromSuperview];
}
imageCount = [imagesArraySlide count];
_photoscroll.delegate = self;
_photoscroll.contentSize=CGSizeMake(320*imageCount, 380);
_photoscroll.scrollEnabled = TRUE;
_photoscroll.pagingEnabled = TRUE;
int scroll_x=0;
for(int i=1; i<=imageCount; i++)
{
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(scroll_x, 20, 320, 380)];
imageView1.contentMode = UIViewContentModeScaleAspectFit;
imageView1.clipsToBounds = NO;
imageView1.autoresizingMask = UIViewContentModeScaleAspectFit;
imageView1.image=[UIImage imageNamed:[imagesArraySlide objectAtIndex:i-1]];
[_photoscroll addSubview:imageView1];
[imageView1 release];
scroll_x = scroll_x + 320;
}
[_photoscroll setContentOffset:CGPointMake(imageID*320, 0) animated:NO];
self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
imageID = scrollView.contentOffset.x / scrollView.frame.size.width;
self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.title = [NSString stringWithFormat:@"%d of %d",imageID+1,imageCount];
}