Today's Menu  Portugal
journal and plan nutrition
P2SnapMealInfoView.m
Go to the documentation of this file.
1 //
2 // P2SnapMealInfoView.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 "P2SnapMealInfoView.h"
10 #import "Z5DataController.h"
11 #import "Z5TextField.h"
12 
13 @interface P2SnapMealInfoView ()
14 
15 @property (strong, nonatomic) Meal *snapMeal;
16 
17 @end
18 
19 @implementation P2SnapMealInfoView
20 {
21 UIImageView *snapMealImageView;
22 UIButton *reviewApprovalButton;
24 
25 id<P2SnapMealInfoProtocol>mMealInfoDelegate;
26 
30 }
32 {
33  return 300;
34 }
35 
36 //- (instancetype) initWithImage:(UIImage *)image inFrame:(CGRect)frame delegate:(id<P2SnapMealInfoProtocol>)delegate
37 //{
38 // self = [super initWithFrame:frame];
39 // if (self) {
40 // mMealInfoDelegate = delegate;
41 // [self originate];
42 // [snapMealImageView setImage:image];
43 // }
44 // return self;
45 //}
46 - (instancetype) initWithMeal:(Meal *)meal inFrame:(CGRect)frame delegate:(id<P2SnapMealInfoProtocol>)delegate
47 {
48  self = [super initWithFrame:frame];
49  if (self) {
50  _focusMeal = meal;
51 
53  [self originate];
54 
55  UIImage *mealImage = [UIImage imageWithData:meal.photo];
56  [snapMealImageView setImage:mealImage];
57  }
58  return self;
59 }
60 - (void) originate
61 {
62  float totalWidth = self.bounds.size.width;
63  float totalHeight = self.bounds.size.height;
64  mealCaptionFrame = CGRectMake(6, 6, totalWidth - 12 - 60, 60);
65  reviewApproveFrame = CGRectMake(totalWidth-60, 6, 60, 60);
66  focusMealImageFrame = CGRectMake(6, 74, totalWidth - 12, totalHeight - 78);
67 
68  snapMealImageView = [[UIImageView alloc] initWithFrame:focusMealImageFrame];
69  [snapMealImageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
70  [snapMealImageView.layer setBorderWidth: 2.0];
71  snapMealImageView.layer.cornerRadius = 8.0f;
72  snapMealImageView.layer.masksToBounds = YES;
73  snapMealImageView.image = [UIImage imageWithData:_focusMeal.photo];
74  [self addSubview:snapMealImageView];
75 
76  UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:22];
77  NSDictionary *attribs = @{
78  NSForegroundColorAttributeName: [UIColor blackColor],
79  NSFontAttributeName: herefont
80  };
81  snapMealCaptionTextField = [[Z5TextField alloc] initWithFrame:mealCaptionFrame];
82  [snapMealCaptionTextField setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
83 
84  reviewApprovalButton = [[UIButton alloc] initWithFrame:reviewApproveFrame];
85  UIImage *reviewApprovalImage = [UIImage imageNamed:@"finishIcon60.png"];
86  [reviewApprovalButton setImage:reviewApprovalImage forState:UIControlStateNormal];
87  [reviewApprovalButton addTarget:mMealInfoDelegate action:@selector(reviewComplete) forControlEvents:UIControlEventTouchUpInside];
88  [self addSubview:reviewApprovalButton];
89 
90  NSString *focusName = [_focusMeal caption];
91  if (focusName) {
92  NSMutableAttributedString *attributedText =
93  [[NSMutableAttributedString alloc] initWithString:focusName
94  attributes:attribs];
95  [snapMealCaptionTextField setAttributedText:attributedText];
96  } else {
97  [snapMealCaptionTextField setPlaceholder:@"enter menu item name"];
98  }
99  [snapMealCaptionTextField setTextAlignment:NSTextAlignmentCenter];
100  snapMealCaptionTextField.layer.cornerRadius = 8.0f;
101  snapMealCaptionTextField.layer.masksToBounds = YES;
102  [snapMealCaptionTextField setDelegate:self];
103  [self addSubview:snapMealCaptionTextField];
104 }
105 
106 - (void) appear: (CGRect) bound
107 {
108  NSLog(@"MenuMealInfoView.appear: width: %3.2f outer: %3.2f", self.bounds.size.width, bound.size.width);
109 
110  [snapMealImageView setFrame:focusMealImageFrame];
111  [snapMealCaptionTextField setFrame:mealCaptionFrame];
112 }
113 
114 
115 
116 
117 #pragma mark - UITextFieldDelegate
118 - (void)textFieldDidEndEditing:(UITextField *)textField
119 {
120  [self.focusMeal setCaption:[textField text]];
121 }
122 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
123  [textField resignFirstResponder];
124  return NO;
125 }
126 
127 @end
id< P2SnapMealInfoProtocol > mMealInfoDelegate
CGRect reviewApproveFrame
instancetype sharedInstance()
CGRect focusMealImageFrame
id< U7ParamEditControlDelegate > delegate
Singleton interface to both core and remote data sources.
CGRect mealCaptionFrame
UITextField * snapMealCaptionTextField
UIButton * reviewApprovalButton