-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathItem.m
More file actions
179 lines (151 loc) · 6.57 KB
/
Item.m
File metadata and controls
179 lines (151 loc) · 6.57 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// Item.m
// Purge
//
// Created by Ryan Nystrom on 2/18/12.
// Copyright (c) 2012 Topic Design. All rights reserved.
//
#import "Item.h"
@implementation Item
@synthesize purge = _purge;
@synthesize scrollView = _scrollView;
-(void)dealloc
{
[_scrollView release], _scrollView = nil;
[_purge release], _purge = nil;
[super dealloc];
}
- (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.
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
[[self view] addSubview:view];
[self setScrollView:view];
[view setScrollEnabled:YES];
[view setShowsVerticalScrollIndicator:NO];
[view setAlwaysBounceVertical:YES];
[view setDelegate:self];
[view setBackgroundColor:[UIColor colorWithRed:0.792f green:0.874f blue:0.894f alpha:1]];
[view release], view = nil;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[[self tabBarController] navigationItem] setRightBarButtonItem:nil];
[[self navigationController] setNavigationBarHidden:NO animated:animated];
[MBProgressHUD showHUDAddedTo:[self view] animated:YES];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
int padding = 5;
int runningHeight = padding;
CGSize maxLabelSize = CGSizeMake(320 - 2 * padding, MAXFLOAT);
UIFont *boldFont = [UIFont fontWithName:@"Helvetica-Bold" size:17];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:17];
UIColor *fontColor = [UIColor colorWithRed:0.301f green:0.325f blue:0.431f alpha:1];
PFFile *imageFile = [[self purge] objectForKey:@"image"];
NSData *imageData;
if ( ! [imageFile isDataAvailable]) {
imageData = [imageFile getData];
}
else {
imageData = [[self purge] objectForKey:@"image"];
}
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect frame = CGRectMake(padding, padding, 320 - 2 * padding, 320 - 2 * padding);
[imageView setFrame:frame];
[[self scrollView] addSubview:imageView];
[[imageView layer] setMasksToBounds:YES];
[[imageView layer] setCornerRadius:2.0];
[[imageView layer] setBorderColor:[[UIColor colorWithRed:0.396f green:0.435f blue:0.427f alpha:0.8] CGColor]];
[[imageView layer] setBorderWidth:2.0];
runningHeight += imageView.frame.size.height + padding;
[imageView release], imageView = nil;
UILabel *descriptionTitle = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[descriptionTitle setText:@"Description"];
[descriptionTitle setFont:boldFont];
[[self scrollView] addSubview:descriptionTitle];
runningHeight += descriptionTitle.frame.size.height;
[descriptionTitle setBackgroundColor:[UIColor clearColor]];
[descriptionTitle setTextColor:fontColor];
[descriptionTitle release], descriptionTitle = nil;
UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 40)];
[description setNumberOfLines:0];
[description setLineBreakMode:UILineBreakModeWordWrap];
NSString *dText = [[self purge] objectForKey:@"description"];
CGSize expected = [dText sizeWithFont:font constrainedToSize:maxLabelSize lineBreakMode:UILineBreakModeWordWrap];
frame = [description frame];
frame.size.height = expected.height;
[description setText:dText];
[description setTextColor:fontColor];
[description setFrame:frame];
[[self scrollView] addSubview:description];
runningHeight += description.frame.size.height + padding;
[description setBackgroundColor:[UIColor clearColor]];
[description release], description = nil;
UILabel *priceTitle = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[priceTitle setText:@"Price"];
[priceTitle setFont:boldFont];
[[self scrollView] addSubview:priceTitle];
runningHeight += priceTitle.frame.size.height;
[priceTitle setTextColor:fontColor];
[priceTitle setBackgroundColor:[UIColor clearColor]];
[priceTitle release], priceTitle = nil;
UILabel *price = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[price setNumberOfLines:0];
[price setTextColor:fontColor];
[price setLineBreakMode:UILineBreakModeWordWrap];
dText = [[self purge] objectForKey:@"price"];
[price setText:dText];
[[self scrollView] addSubview:price];
[price setBackgroundColor:[UIColor clearColor]];
runningHeight += price.frame.size.height + padding;
[price release], price = nil;
CGRect buttonFrame = CGRectMake(padding, runningHeight, 320 - 2 * padding, 73);
UIImage *buyImage = [UIImage imageNamed:@"product_button.png"];
UIButton *buy = [UIButton buttonWithType:UIButtonTypeCustom];
[buy setTitleEdgeInsets:UIEdgeInsetsMake(10, -320, 5.0, 5.0)];
[buy setTitleColor:fontColor forState:UIControlStateNormal];
[[buy titleLabel] setFont:boldFont];
[buy setImage:buyImage forState:UIControlStateNormal];
[buy setTitle:@"Buy" forState:UIControlStateNormal];
[buy setFrame:buttonFrame];
[buy addTarget:self action:@selector(onBuy) forControlEvents:UIControlEventTouchUpInside];
[[self scrollView] addSubview:buy];
runningHeight += buy.frame.size.height + padding;
[[self scrollView] setContentSize:CGSizeMake(320, runningHeight)];
[[self scrollView] addSubview:buy];
[MBProgressHUD hideHUDForView:[self view] animated:YES];
}
-(void)onBuy
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"Buy accepting you are committing to purchasing this item from the seller." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Agree", nil];
[av show];
[av release], av = nil;
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end