|
// |
|
// PCFancyButton.m |
|
// RoundButton Test |
|
// |
|
// Created by Pablo Isidoro Carrillo Alvarez on 11/09/2013. |
|
// Copyright (c) 2013 Pablo Isidoro Carrillo Alvarez. |
|
// |
|
// Permission is hereby granted, free of charge, to any person obtaining a copy |
|
// of this software and associated documentation files (the "Software"), to deal |
|
// in the Software without restriction, including without limitation the rights |
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
// copies of the Software, and to permit persons to whom the Software is |
|
// furnished to do so, subject to the following conditions: |
|
// |
|
// The above copyright notice and this permission notice shall be included in |
|
// all copies or substantial portions of the Software. |
|
// |
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
// THE SOFTWARE. |
|
|
|
|
|
#import "PCFancyButton.h" |
|
|
|
@implementation PCFancyButton |
|
|
|
- (id)initWithFrame:(CGRect)frame |
|
{ |
|
if((self = [super initWithFrame:frame])){ |
|
[self setupView]; |
|
} |
|
|
|
return self; |
|
} |
|
|
|
- (void)awakeFromNib { |
|
|
|
[self setupView]; |
|
} |
|
|
|
# pragma mark - main |
|
|
|
- (void)setupView |
|
{ |
|
//Configuring round border for button images. |
|
self.imageView.layer.cornerRadius=_cornerRadius; |
|
self.imageView.layer.masksToBounds=YES; |
|
|
|
//Configuring cornerRadius for the layer of the button |
|
self.layer.cornerRadius = _cornerRadius; |
|
|
|
//Configuring border |
|
self.layer.borderWidth = 4.0f; |
|
self.layer.borderColor = [UIColor colorWithRed:167.0/255.0 green:140.0/255.0 blue:98.0/255.0 alpha:1].CGColor; |
|
|
|
//Configuring shadow |
|
self.layer.shadowColor = [UIColor blackColor].CGColor; |
|
self.layer.shadowRadius = 1; |
|
|
|
[self clearHighlightView]; |
|
|
|
//If you want to use gradients just uncomment the line below and configure as you wish |
|
/* |
|
CAGradientLayer *gradient = [CAGradientLayer layer]; |
|
gradient.frame = self.layer.bounds; |
|
gradient.cornerRadius = _cornerRadius; |
|
gradient.colors = [NSArray arrayWithObjects: |
|
(id)[UIColor colorWithWhite:1.0f alpha:1.0f].CGColor, |
|
(id)[UIColor colorWithWhite:1.0f alpha:0.0f].CGColor, |
|
(id)[UIColor colorWithWhite:0.0f alpha:0.0f].CGColor, |
|
(id)[UIColor colorWithWhite:0.0f alpha:0.4f].CGColor, |
|
nil]; |
|
float height = gradient.frame.size.height; |
|
gradient.locations = [NSArray arrayWithObjects: |
|
[NSNumber numberWithFloat:0.0f], |
|
[NSNumber numberWithFloat:0.2*30/height], |
|
[NSNumber numberWithFloat:1.0-0.1*30/height], |
|
[NSNumber numberWithFloat:1.0f], |
|
nil]; |
|
[self.layer addSublayer:gradient]; |
|
*/ |
|
} |
|
|
|
- (void)highlightView |
|
{ |
|
self.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); |
|
self.layer.shadowOpacity = 0.25; |
|
} |
|
|
|
- (void)clearHighlightView { |
|
self.layer.shadowOffset = CGSizeMake(2.0f, 2.0f); |
|
self.layer.shadowOpacity = 0.5; |
|
} |
|
|
|
- (void)setHighlighted:(BOOL)highlighted |
|
{ |
|
if (highlighted) { |
|
[self highlightView]; |
|
} else { |
|
[self clearHighlightView]; |
|
} |
|
[super setHighlighted:highlighted]; |
|
} |
|
|
|
|
|
@end |