Today's Menu  Portugal
journal and plan nutrition
Z6MenuItemFocusView.m
Go to the documentation of this file.
1 //
2 // Z6MenuItemFocusView.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 3/23/17.
6 // Copyright © 2017 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
9 #import "Z6MenuItemFocusView.h"
10 #import "Z5DataController.h"
11 #import "Z5TextField.h"
12 
13 @interface Z6MenuItemFocusView ()
14 
15 @property (strong, nonatomic) MenuItem *focusMenuItem;
16 
17 @end
18 
19 @implementation Z6MenuItemFocusView
20 {
21  UIPickerView *menuItemGalleryPicker;
22  // UIPickerView *newParameterPickerView;
23 
24  NSInteger focusGallery;
25 
26 }
28 UITextField *menuItemNameTextField;
29 
31 float usdaTopOfPageFloat = 2.0;
34 float usdaImageWidth = 160;
37 
39 {
41 }
42 
43 - (instancetype) initWithMenuItem: (MenuItem *) menuItem andDelegate: (id<Z6ItemFocusDelegate>) delegate
44 {
45  self = [super init];
46  if (self) {
47  _focusMenuItem = menuItem;
48  _delegate = delegate;
49  focusGallery = 1;
50  [self originate];
51  }
52  return self;
53 }
54 - (void) originate
55 {
56 
57  CGRect galleryIdPickerFrame = CGRectMake(usdaSideMarginWidthFloat,
61  CGRect focusMenuItemImageFrame = CGRectMake(usdaSideMarginWidthFloat + (usdaFeaturesWidthFloat - usdaImageWidth)/2,
65  CGRect menuItemNameFrame = CGRectMake(usdaSideMarginWidthFloat,
69 
70  menuItemGalleryPicker = [[UIPickerView alloc] initWithFrame:galleryIdPickerFrame];
71  [menuItemGalleryPicker setDelegate:self];
72  [menuItemGalleryPicker setDataSource:self];
73  [menuItemGalleryPicker setBackgroundColor:[UIColor colorWithWhite:0.76 alpha:1.0]];
74  [menuItemGalleryPicker selectRow:focusGallery inComponent:0 animated:YES];
75  [self addSubview:menuItemGalleryPicker];
76 
77  focusMenuItemImageView = [[UIImageView alloc] initWithFrame:focusMenuItemImageFrame];
78  [focusMenuItemImageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
79  // [focusMenuItemImageView.layer setBorderColor: [[[Z5DataController sharedInstance] wheatColor] CGColor]];
80  [focusMenuItemImageView.layer setBorderWidth: 2.0];
81  focusMenuItemImageView.layer.cornerRadius = 8.0f;
82  focusMenuItemImageView.layer.masksToBounds = YES;
83  focusMenuItemImageView.image = [UIImage imageWithData:_focusMenuItem.photo];
84  [self addSubview:focusMenuItemImageView];
85 
86 
87  UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:22];
88  NSDictionary *attribs = @{
89  NSForegroundColorAttributeName: [UIColor blackColor],
90  NSFontAttributeName: herefont
91  };
92  menuItemNameTextField = [[Z5TextField alloc] initWithFrame:menuItemNameFrame];
93  [menuItemNameTextField setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
94  NSString *focusName = [_focusMenuItem name];
95  if (focusName) {
96  NSMutableAttributedString *attributedText =
97  [[NSMutableAttributedString alloc] initWithString:focusName
98  attributes:attribs];
99  [menuItemNameTextField setAttributedText:attributedText];
100  } else {
101  [menuItemNameTextField setPlaceholder:@"enter menu item name"];
102  }
103  [menuItemNameTextField setTextAlignment:NSTextAlignmentCenter];
104  menuItemNameTextField.layer.cornerRadius = 8.0f;
105  menuItemNameTextField.layer.masksToBounds = YES;
106  [menuItemNameTextField setDelegate:self];
107  [self addSubview:menuItemNameTextField];
108 }
109 
110 - (void) appear: (CGRect) bound
111 {
112  NSLog(@"MenuItemFocusView.appear: width: %3.2f outer: %3.2f", self.bounds.size.width, bound.size.width);
113 
114  usdaFeaturesWidthFloat = self.bounds.size.width - 2 * usdaSideMarginWidthFloat;
115 
116  CGRect galleryIdPickerFrame = CGRectMake(usdaSideMarginWidthFloat,
117  usdaTopOfPageFloat + 6,
120  [menuItemGalleryPicker setFrame:galleryIdPickerFrame];
121  CGRect focusMenuItemImageFrame = CGRectMake(usdaSideMarginWidthFloat + (usdaFeaturesWidthFloat - usdaImageWidth)/2,
125  [focusMenuItemImageView setFrame:focusMenuItemImageFrame];
126  CGRect menuItemNameFrame = CGRectMake(usdaSideMarginWidthFloat,
130  [menuItemNameTextField setFrame:menuItemNameFrame];
131 }
132 
133 
134 #pragma mark - UIPickerViewDelegate
135 
138 - (CGFloat)pickerView:(UIPickerView *)pickerView
139 rowHeightForComponent:(NSInteger)component
140 {
141  CGFloat ret;
142  ret = 32.0;
143  return ret;
144 }
145 
146 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
147 {
148  CGFloat ret;
149  ret = 220.0;
150  return ret;
151 }
152 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView
153  attributedTitleForRow:(NSInteger)row
154  forComponent:(NSInteger)component
155 {
156  NSString *ret;
157  NSLog(@"Z6MenuItemFocusView.titleForRow: menuItemGalleryPicker");
158  switch (row) {
159  case 0:
160  ret = @"Discards";
161  break;
162  case 1:
163  ret = @"Home";
164  break;
165  default:
166  break;
167  }
168 
169  UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:16];
170  NSDictionary *attribs = @{
171  NSForegroundColorAttributeName: [UIColor blackColor],
172  NSFontAttributeName: herefont
173  };
174  NSMutableAttributedString *attributedText =
175  [[NSMutableAttributedString alloc] initWithString:ret
176  attributes:attribs];
177  return attributedText;
178 }
179 -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
180 {
181  // create attributed string
182  NSString *ret;
183  NSLog(@"Z6MenuItemFocusView.titleForRow: menuItemGalleryPicker");
184  switch (row) {
185  case 0:
186  ret = @"Discards";
187  break;
188  case 1:
189  ret = @"Home";
190  break;
191  default:
192  break;
193  }
194 
195  UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:20];
196  NSDictionary *attribs = @{
197  NSForegroundColorAttributeName: [UIColor blackColor],
198  NSFontAttributeName: herefont
199  };
200  NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:ret attributes:attribs];
201 
202  // add the string to a label's attributedText property
203  UILabel *labelView = [[UILabel alloc] init];
204  [labelView setTextAlignment:NSTextAlignmentCenter];
205  labelView.attributedText = attributedString;
206 
207  // return the label
208  return labelView;
209 }
210 - (void)pickerView:(UIPickerView *)pickerView
211  didSelectRow:(NSInteger)row
212  inComponent:(NSInteger)component
213 {
214  // NSLog(@"Z6MenuItemFocusView.didSelectPickerRow: component: %ld", component);
215  NSLog(@"Z6MenuItemFocusView.didSelectPickerRow (gallery picker): %ld", (long)row);
216  focusGallery = row;
217 
218  NSNumber *rowNumber = [NSNumber numberWithLong:row];
219  [_focusMenuItem setGalleryNumber:rowNumber];
220 
221 }
222 
223 #pragma mark - UIPickerViewDataSource
224 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
225 {
226  NSInteger ret = 0;
227  ret = 1;
228  return ret;
229 }
230 - (NSInteger)pickerView:(UIPickerView *)pickerView
231 numberOfRowsInComponent:(NSInteger)component
232 {
233  NSInteger ret = 0;
234  ret = 2;
235  return ret;
236 }
237 
238 
239 #pragma mark - UITextFieldDelegate
240 - (void)textFieldDidEndEditing:(UITextField *)textField
241 {
242  [self.focusMenuItem setName:[textField text]];
243  // also at this point change to attributed
244  // UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:22];
245 // NSDictionary *attribs = @{
246 // NSForegroundColorAttributeName: [UIColor blackColor],
247 // NSFontAttributeName: herefont
248 // };
249 // NSMutableAttributedString *attributedText =
250 // [[NSMutableAttributedString alloc] initWithString:[textField text]
251 // attributes:attribs];
252  // [menuItemNameTextField setAttributedText:attributedText];
253 
254 }
255 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
256  [textField resignFirstResponder];
257  return NO;
258 }
259 
260 /*
261 // Only override drawRect: if you perform custom drawing.
262 // An empty implementation adversely affects performance during animation.
263 - (void)drawRect:(CGRect)rect {
264  // Drawing code
265 }
266 */
267 
268 @end
MenuItem * menuItem
instancetype sharedInstance()
float usdaGalleryIdPickerHeightFloat
float usdaFeaturesWidthFloat
UIImageView * focusMenuItemImageView
UITextField * menuItemNameTextField
id< Z6ItemFocusDelegate > delegate
float usdaImageWidth
Singleton interface to both core and remote data sources.
NSInteger focusGallery
float usdaMenuItemNameFloat
float usdaImageHeightFloat
float usdaSideMarginWidthFloat
float usdaTopOfPageFloat