-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomImagePicker.m
107 lines (84 loc) · 2.79 KB
/
CustomImagePicker.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// CustomImagePicker.m
// ContentionApp
//
// code taken from:
// http://www.raywenderlich.com/130/how-to-write-a-custom-image-picker-like-uiimagepicker/
//
#import "CustomImagePicker.h"
#import "ContentionAppAppDelegate.h"
@implementation CustomImagePicker
@synthesize deviceView;
@synthesize parent;
static NSArray* _thumbs;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil view:(DeviceView*) v imagelist:(NSArray*)images parent:(UIViewController *)p{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
[self setDeviceView:v];
_thumbs = images ;
[self setParent: p];
}
return self;
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
UIScrollView *view = [[UIScrollView alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
int row = 0;
int column = 0;
for(int i = 0; i < _thumbs.count; ++i) {
UIImage *thumb = [UIImage imageNamed:[_thumbs objectAtIndex:i]];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*100+24, row*90+10, 84, 84);
[button setImage:thumb forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[view addSubview:button];
if (column == 2) {
column = 0;
row++;
} else {
column++;
}
}
[view setContentSize:CGSizeMake(320, (row+1) * 90 + 10)];
self.view = view;
[view release];
[super viewDidLoad];
}
- (IBAction)buttonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
NSString *selectedImage = [_thumbs objectAtIndex:button.tag];
if (deviceView != NULL){
[deviceView updateImage:selectedImage];
}
[parent updateImage:selectedImage forNode:[deviceView identifier]];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
//[_thumbs release];
[super dealloc];
}
@end