Reputation: 579
hi Friends i have to develop an photo management app. here my images should arrange in gris View in my iphone.i analysed in Google i got Some Frame work. the below list is
1.UICollectionView
and also my features in grid view is listed below
the grid View cell allows UITapGestureRecognizer
for deleting the image cell or Edit style options like in table view.
create custom GridView cell
please can any one sugest me which one is good to develop
Upvotes: 1
Views: 2834
Reputation: 119
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];
}
Upvotes: 0
Reputation: 2171
I am currently using AQGridView
so surely i recommend that as it is the least buggy and its functions are very similar to UITableView
.
Also that If you are trying to do this without XIB it will be little bit difficult for you to handle it but you can create a view controller with Xib file to Create the interface of your choice. Here is the Video of how it can be done in the best possible way by Evadne Wu
. And here is the Sample Project
Upvotes: 0
Reputation: 497
It would be better if u create custom buttons, store the image paths in an array, write the for loop to display the number of images in each row. Insert those images inside each of the custom buttons. It will now look like a thumbnail image view.
Something like this,
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)];
Explanation:
The path of the images are stored in imagePath. We are then storing the imagePath in a string(path). Now, to the imageArray, we are adding the contents of path. Hence the imageArray now contains the path of all the images. Then create a for loop to display say, 4 images in each row. Create a custom button and to the button, insert each images one by one(using imageArray). Create a scrollview to put all the button-images in it.
You are now done creating a 4*4 grid view for the images. HAPPY CODING...
Upvotes: 1
Reputation: 18346
Seems like PSTCollectionView is what you need.
It is like UICollectionView, but works on iOS 4.3.
You can create Custom cell by overriding dataSource method:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Also in this method you can add gesture recognizer to your cell.
Upvotes: 0