Today's Menu  Portugal
journal and plan nutrition
Y3GradientButton.m
Go to the documentation of this file.
1 //
2 // Y3GradientButton.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 12/8/15.
6 // Copyright © 2015 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
9 #import "Y3GradientButton.h"
10 
11 @implementation Y3GradientButton
12 
13 #pragma mark - Accessories
14 
16 + (Y3GradientButton *)makeGradientButton:(NSString *) caption withFrame: (CGRect) menuButtonFrame {
17  menuButton = [Y3GradientButton buttonWithType:UIButtonTypeRoundedRect];
18  [menuButton setFrame:menuButtonFrame];
19 
20  [menuButton setBackgroundColor:[UIColor colorWithHue:0.23 saturation:0.9 brightness:1.0 alpha:1.0]];
21 
22  menuButton.layer.cornerRadius = 8;
23  menuButton.layer.borderColor = [[UIColor blackColor] CGColor];
24  menuButton.layer.borderWidth = 3.0;
25 
26  [menuButton setTitleEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
27  [menuButton setTitle:caption forState:UIControlStateNormal];
28  [menuButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
29  [menuButton setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
30  // UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:20.0];
31  UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:18.0];
32  [menuButton.titleLabel setFont:expandedFont];
33  [menuButton.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
34  [menuButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
35  [menuButton.titleLabel setAdjustsFontSizeToFitWidth:YES];
36  menuButton.clipsToBounds = YES;
37 
38  CAGradientLayer *gradientLayer = [self makeGradientLayer:NO];
39  [menuButton.layer addSublayer:gradientLayer];
40  return menuButton;
41 }
42 + (Y3GradientButton *)makeSingleCharacterGradientButton:(NSString *) caption withFrame: (CGRect) menuButtonFrame {
43  menuButton = [Y3GradientButton buttonWithType:UIButtonTypeRoundedRect];
44  [menuButton setFrame:menuButtonFrame];
45 
46  [menuButton setBackgroundColor:[UIColor colorWithHue:0.23 saturation:0.9 brightness:1.0 alpha:1.0]];
47 
48  menuButton.layer.cornerRadius = 8;
49  menuButton.layer.borderColor = [[UIColor blackColor] CGColor];
50  menuButton.layer.borderWidth = 3.0;
51 
52  [menuButton setTitleEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
53  [menuButton setTitle:caption forState:UIControlStateNormal];
54  [menuButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
55  [menuButton setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
56  // UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:20.0];
57  UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:40.0];
58  [menuButton.titleLabel setFont:expandedFont];
59  [menuButton.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
60  [menuButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
61  [menuButton.titleLabel setAdjustsFontSizeToFitWidth:YES];
62  menuButton.clipsToBounds = YES;
63 
64  CAGradientLayer *gradientLayer = [self makeGradientLayer:NO];
65  [menuButton.layer addSublayer:gradientLayer];
66  return menuButton;
67 }
68 
69 + (CAGradientLayer *) makeGradientLayer:(Boolean) status
70 {
71 
72  CAGradientLayer *gradientLayer = [CAGradientLayer layer];
73  CGRect overFlowBounds = menuButton.layer.bounds;
74  overFlowBounds.size.height -= 2.0;
75  gradientLayer.frame = overFlowBounds;
76 
77  if (status) {
78  gradientLayer.colors = [NSArray arrayWithObjects:
79  (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
80  (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
81  nil];
82  } else {
83  gradientLayer.colors = [NSArray arrayWithObjects:
84  (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
85  (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
86  nil];
87  }
88 
89  gradientLayer.locations = [NSArray arrayWithObjects:
90  [NSNumber numberWithFloat:0.0f],
91  [NSNumber numberWithFloat:1.0f],
92  nil];
93 
94  gradientLayer.cornerRadius = 6; // refillButton.layer.cornerRadius;
95 
96  return gradientLayer;
97 }
98 
99 -(void)showDepressed:(Boolean)state
100 {
101  NSLog(@"GradientButton: showDepressed: %@", ( state ? @"PUSHED" : @"RELEASED"));
102  // [self setBackgroundColor:[UIColor colorWithHue:0.13 saturation:0.9 brightness:1.0 alpha:1.0]];
103  [self.layer removeFromSuperlayer];
104 
105  CAGradientLayer *gradientLayer = [Y3GradientButton makeGradientLayer:state];
106  [self.layer addSublayer:gradientLayer];
107 
108 }
109 
110 - (void) showText:(NSString *) caption
111 {
112  [menuButton setTitle:caption forState:UIControlStateNormal];
113  [menuButton setNeedsDisplay];
114 }
115 
116 /*
117 // Only override drawRect: if you perform custom drawing.
118 // An empty implementation adversely affects performance during animation.
119 - (void)drawRect:(CGRect)rect {
120  // Drawing code
121 }
122 */
123 
124 @end
CAGradientLayer * makeGradientLayer:(Boolean status)
static Y3GradientButton * menuButton