From b1ef1733030c6349116c833b7fc888704566e56a Mon Sep 17 00:00:00 2001 From: tomomura Date: Wed, 8 Apr 2015 09:16:38 +0900 Subject: [PATCH 1/3] add initWithCorder in order to storyboard. --- DKCircleButton/DKCircleButton.m | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/DKCircleButton/DKCircleButton.m b/DKCircleButton/DKCircleButton.m index 99f0a82..80fb0ad 100644 --- a/DKCircleButton/DKCircleButton.m +++ b/DKCircleButton/DKCircleButton.m @@ -28,38 +28,55 @@ @implementation DKCircleButton @synthesize borderColor = _borderColor; @synthesize animateTap = _animateTap; + - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - _highLightView = [[UIView alloc] initWithFrame:frame]; - - _highLightView.userInteractionEnabled = YES; - _highLightView.alpha = 0; - _highLightView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5]; - - _borderColor = [UIColor whiteColor]; - _animateTap = YES; - _borderSize = DKCircleButtonBorderWidth; - - self.clipsToBounds = YES; - self.titleLabel.textAlignment = NSTextAlignmentCenter; - self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; - - _gradientLayerTop = [CAGradientLayer layer]; - _gradientLayerTop.frame = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height / 4); - _gradientLayerTop.colors = @[(id)[UIColor blackColor].CGColor, (id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.01].CGColor]; - - _gradientLayerBottom = [CAGradientLayer layer]; - _gradientLayerBottom.frame = CGRectMake(0.0, frame.size.height * 3 / 4, frame.size.width, frame.size.height / 4); - _gradientLayerBottom.colors = @[(id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.01].CGColor, (id)[UIColor blackColor].CGColor]; + [self commonInit] + } + + return self; +} - [self addSubview:_highLightView]; +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super initWithCoder:aDecoder] + + if (self) { + [self commonInit]; } return self; } + +- (void)commonInit { + _highLightView = [[UIView alloc] initWithFrame:self.frame]; + + _highLightView.userInteractionEnabled = YES; + _highLightView.alpha = 0; + _highLightView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5]; + + _borderColor = [UIColor whiteColor]; + _animateTap = YES; + _borderSize = DKCircleButtonBorderWidth; + + self.clipsToBounds = YES; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; + + _gradientLayerTop = [CAGradientLayer layer]; + _gradientLayerTop.frame = CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height / 4); + _gradientLayerTop.colors = @[(id)[UIColor blackColor].CGColor, (id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.01].CGColor]; + + _gradientLayerBottom = [CAGradientLayer layer]; + _gradientLayerBottom.frame = CGRectMake(0.0, self.frame.size.height * 3 / 4, self.frame.size.width, self.frame.size.height / 4); + _gradientLayerBottom.colors = @[(id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.01].CGColor, (id)[UIColor blackColor].CGColor]; + + [self addSubview:_highLightView]; +} + - (void)setDisplayShading:(BOOL)displayShading { _displayShading = displayShading; From bddfcd8e83e57f9189ea6af94f82c770b96d3750 Mon Sep 17 00:00:00 2001 From: tomomura Date: Wed, 8 Apr 2015 09:22:14 +0900 Subject: [PATCH 2/3] fix missing ';'. --- DKCircleButton/DKCircleButton.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DKCircleButton/DKCircleButton.m b/DKCircleButton/DKCircleButton.m index 80fb0ad..2c8e496 100644 --- a/DKCircleButton/DKCircleButton.m +++ b/DKCircleButton/DKCircleButton.m @@ -33,7 +33,7 @@ - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - [self commonInit] + [self commonInit]; } return self; @@ -41,7 +41,7 @@ - (id)initWithFrame:(CGRect)frame { - (id)initWithCoder:(NSCoder *)aDecoder { - self = [super initWithCoder:aDecoder] + self = [super initWithCoder:aDecoder]; if (self) { [self commonInit]; From 1be3632a5b0a55aff8354dceda475d67ec65235f Mon Sep 17 00:00:00 2001 From: tomomura Date: Wed, 8 Apr 2015 09:25:30 +0900 Subject: [PATCH 3/3] remove blank lines. --- DKCircleButton/DKCircleButton.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/DKCircleButton/DKCircleButton.m b/DKCircleButton/DKCircleButton.m index 2c8e496..8365da6 100644 --- a/DKCircleButton/DKCircleButton.m +++ b/DKCircleButton/DKCircleButton.m @@ -28,7 +28,6 @@ @implementation DKCircleButton @synthesize borderColor = _borderColor; @synthesize animateTap = _animateTap; - - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -50,7 +49,6 @@ - (id)initWithCoder:(NSCoder *)aDecoder return self; } - - (void)commonInit { _highLightView = [[UIView alloc] initWithFrame:self.frame];