Today's Menu  Portugal
journal and plan nutrition
Y5GradientButton.m
Go to the documentation of this file.
1 //
2 // Y5GradientButton.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 12/30/18.
6 // Copyright © 2018 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
9 #import "Y5GradientButton.h"
10 
11 @implementation Y5GradientButton
12 
13 id<Y5GradientButtonProtocol> mGradientButtonDelegate;
14 
15 - (instancetype) initWithFrame:(CGRect)frame andDelegate:(id<Y5GradientButtonProtocol>)delegate
16 {
17  self = [UIButton buttonWithType:UIButtonTypeRoundedRect];
18  if (self) {
20  [self setFrame:frame];
21 
22  [self setTitleEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
23  [self setTitle:@"Hey!" forState:UIControlStateNormal];
24  [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
25  [self setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
26  // UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:20.0];
27  UIFont *expandedFont = [UIFont fontWithName:@"Verdana-Bold" size:18.0];
28  [self.titleLabel setFont:expandedFont];
29  [self.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
30  [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
31  [self.titleLabel setAdjustsFontSizeToFitWidth:YES];
32  self.clipsToBounds = YES;
33 
34  CAGradientLayer *gradientLayer = [self makeGradientLayer:NO];
35  [self.layer addSublayer:gradientLayer];
36  }
37  return self;
38 }
39 
40 - (CAGradientLayer *) makeGradientLayer:(Boolean) status
41 {
42 
43  CAGradientLayer *gradientLayer = [CAGradientLayer layer];
44  CGRect overFlowBounds = self.layer.bounds;
45  overFlowBounds.size.height -= 2.0;
46  gradientLayer.frame = overFlowBounds;
47 
48  if (status) {
49  gradientLayer.colors = [NSArray arrayWithObjects:
50  (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
51  (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
52  nil];
53  } else {
54  gradientLayer.colors = [NSArray arrayWithObjects:
55  (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
56  (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
57  nil];
58  }
59 
60  gradientLayer.locations = [NSArray arrayWithObjects:
61  [NSNumber numberWithFloat:0.0f],
62  [NSNumber numberWithFloat:1.0f],
63  nil];
64 
65  gradientLayer.cornerRadius = 6; // refillButton.layer.cornerRadius;
66 
67  return gradientLayer;
68 }
69 
70 /*
71 // Only override drawRect: if you perform custom drawing.
72 // An empty implementation adversely affects performance during animation.
73 - (void)drawRect:(CGRect)rect {
74  // Drawing code
75 }
76 */
77 
78 @end
CAGradientLayer * makeGradientLayer:(Boolean status)
id< Y5GradientButtonProtocol > mGradientButtonDelegate
id< U7ParamEditControlDelegate > delegate