Skip to content

Commit

Permalink
Added new ImagesView
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Rush committed Jun 23, 2011
1 parent b72e5b7 commit ce1f0a4
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 0 deletions.
16 changes: 16 additions & 0 deletions MiniKeePass/EditGroupViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// EditGroupViewController.h
// MiniKeePass
//
// Created by Jason Rush on 6/23/11.
// Copyright 2011 Self. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface EditGroupViewController : FormViewController {

}

@end
14 changes: 14 additions & 0 deletions MiniKeePass/EditGroupViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// EditGroupViewController.m
// MiniKeePass
//
// Created by Jason Rush on 6/23/11.
// Copyright 2011 Self. All rights reserved.
//

#import "EditGroupViewController.h"


@implementation EditGroupViewController

@end
28 changes: 28 additions & 0 deletions MiniKeePass/ImagesViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ImagesViewController.h
// MiniKeePass
//
// Created by Jason Rush on 6/22/11.
// Copyright 2011 Self. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol ImagesViewControllerDelegate;

@interface ImagesViewController : UIViewController {
UIView *imagesView;
NSMutableArray *imageViews;
UIImageView *selectedImageView;
id<ImagesViewControllerDelegate> delegate;
}

@property (nonatomic, retain) id<ImagesViewControllerDelegate> delegate;

- (void)setSelectedImage:(NSUInteger)index;

@end

@protocol ImagesViewControllerDelegate <NSObject>
- (void)imagesViewController:(ImagesViewController*)controller imageSelected:(NSUInteger)index;
@end
109 changes: 109 additions & 0 deletions MiniKeePass/ImagesViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// ImagesViewController.m
// MiniKeePass
//
// Created by Jason Rush on 6/22/11.
// Copyright 2011 Self. All rights reserved.
//

#import "ImagesViewController.h"
#import "MiniKeePassAppDelegate.h"

#define IMAGES_PER_ROW 7
#define SIZE 24
#define HORIZONTAL_SPACING 10.5
#define VERTICAL_SPACING 10.5

@implementation ImagesViewController

@synthesize delegate;

- (id)init {
self = [super init];
if (self) {
// Get the application delegate
MiniKeePassAppDelegate *appDelegate = (MiniKeePassAppDelegate*)[[UIApplication sharedApplication] delegate];

imagesView = [[UIView alloc] init];

CGRect frame = CGRectMake(HORIZONTAL_SPACING, VERTICAL_SPACING, SIZE, SIZE);

// Load the images
imageViews = [[NSMutableArray alloc] initWithCapacity:NUM_IMAGES];
for (NSUInteger index = 0; index < NUM_IMAGES; index += IMAGES_PER_ROW) {
for (int i = 0; i < IMAGES_PER_ROW; i++) {
UIImage *image = [appDelegate loadImage:index + i];

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = frame;
[imagesView addSubview:imageView];

[imageViews addObject:imageView];

[imageView release];

frame.origin.x += SIZE + 2 * HORIZONTAL_SPACING;
}

frame.origin.x = HORIZONTAL_SPACING;
frame.origin.y += SIZE + 2 * VERTICAL_SPACING;
}

UIImage *selectedImage = [UIImage imageNamed:@"checkmark"];
selectedImageView = [[UIImageView alloc] initWithImage:selectedImage];
[imagesView addSubview:selectedImageView];

[self setSelectedImage:0];

UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.alwaysBounceHorizontal = NO;
scrollView.contentSize = CGSizeMake(IMAGES_PER_ROW * (SIZE + 2 * HORIZONTAL_SPACING), ceil(((CGFloat)NUM_IMAGES) / IMAGES_PER_ROW) * (SIZE + 2 * VERTICAL_SPACING));
[scrollView addSubview:imagesView];

UIGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageSelected:)];
[scrollView addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];

self.view = scrollView;

[scrollView release];
}
return self;
}

- (void)dealloc {
[imagesView release];
[imageViews release];
[selectedImageView release];
[delegate release];
[super dealloc];
}

- (void)setSelectedImage:(NSUInteger)index {
if (index >= NUM_IMAGES) {
return;
}

NSUInteger row = index / IMAGES_PER_ROW;
NSUInteger col = index - (row * IMAGES_PER_ROW);

CGSize size = selectedImageView.image.size;
CGRect frame = CGRectMake((col + 1) * (SIZE + 2 * HORIZONTAL_SPACING) - size.width, (row + 1) * (SIZE + 2 * VERTICAL_SPACING) - size.height, size.width, size.height);
selectedImageView.frame = frame;
}

- (void)imageSelected:(UIGestureRecognizer*)gestureRecognizer {
CGPoint point = [gestureRecognizer locationInView:imagesView];
NSUInteger col = point.x / (SIZE + 2 * HORIZONTAL_SPACING);
NSUInteger row = point.y / (SIZE + 2 * VERTICAL_SPACING);

NSUInteger index = row * IMAGES_PER_ROW + col;
[self setSelectedImage:index];

if ([delegate respondsToSelector:@selector(imageViewController:imageSelected:)]) {
[delegate imagesViewController:self imageSelected:index];
}
}

@end
Binary file added images/checkmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions images/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ce1f0a4

Please sign in to comment.