-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomButton.m
More file actions
63 lines (49 loc) · 1.93 KB
/
CustomButton.m
File metadata and controls
63 lines (49 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// CustomButton.m
// IBPreview
//
// Created by Sudheendra K Kaanugovi on 4/3/15.
// Copyright (c) 2015 Sudhy Studios. All rights reserved.
//
#import "CustomButton.h"
@implementation CustomButton
//This method is called if the button is used in StoryBoard
-(instancetype) initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder]){
[self setupCustomButtonProperties];
}
return self;
}
//You can call this init method if you want button to load programmatically by passing the CGRect frame where it has to render
-(instancetype) initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame]){
[self setupCustomButtonProperties];
}
return self;
}
//This is the magic and important method that gets called in the interface builder where the storyboard or xib has button of type Self Class
-(void) prepareForInterfaceBuilder
{
[self setupCustomButtonProperties];
}
//Setting some properties of the button
- (void) setupCustomButtonProperties{
// Set the button Text Color
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
// Set the button Background Color
[self setBackgroundColor:[UIColor blackColor]];
CAGradientLayer *btnGradient = [CAGradientLayer layer];
btnGradient.frame = self.bounds;
btnGradient.colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:102.0f / 255.0f green:102.0f / 255.0f blue:102.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:51.0f / 255.0f green:51.0f / 255.0f blue:51.0f / 255.0f alpha:1.0f] CGColor],
nil];
[self.layer insertSublayer:btnGradient atIndex:0];
CALayer *btnLayer = [self layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:self.cornerRadius];
}
@end