forked from dogo/SCLAlertView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCLSwitchView.m
More file actions
126 lines (97 loc) · 2.68 KB
/
Copy pathSCLSwitchView.m
File metadata and controls
126 lines (97 loc) · 2.68 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// SCLSwitchView.m
// SCLAlertView
//
// Created by André Felipe Santos on 27/01/16.
// Copyright © 2016 AnyKey Entertainment. All rights reserved.
//
#import "SCLSwitchView.h"
#import "SCLMacros.h"
@interface SCLSwitchView ()
@property (strong, nonatomic) UISwitch *switchKnob;
@property (strong, nonatomic) UILabel *switchLabel;
@end
#pragma mark
@implementation SCLSwitchView
#pragma mark - Constructors
- (instancetype)init
{
self = [super init];
if (self)
{
[self setup];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self)
{
[self setup];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setup];
}
return self;
}
#pragma mark - Initialization
- (void)setup
{
// Add switch knob
self.switchKnob = [[UISwitch alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.f)];
[self addSubview:self.switchKnob];
// Add switch label
CGFloat x, width, height;
x = self.switchKnob.frame.size.width + 8.0f;
width = self.frame.size.width - self.switchKnob.frame.size.width - 8.0f;
height = self.switchKnob.frame.size.height;
self.switchLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 0.0f, width, height)];
NSString *switchFontFamily = @"HelveticaNeue-Bold";
CGFloat switchFontSize = 12.0f;
self.switchLabel.numberOfLines = 1;
self.switchLabel.textAlignment = NSTextAlignmentLeft;
self.switchLabel.lineBreakMode = NSLineBreakByTruncatingTail;
self.switchLabel.adjustsFontSizeToFitWidth = YES;
self.switchLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
self.switchLabel.minimumScaleFactor = 0.5f;
self.switchLabel.font = [UIFont fontWithName:switchFontFamily size:switchFontSize];
self.switchLabel.textColor = UIColorFromHEX(0x4D4D4D);
[self addSubview:self.switchLabel];
}
#pragma mark - Getters
- (UIColor *)tintColor {
return self.switchKnob.tintColor;
}
- (UIColor *)labelColor {
return self.switchLabel.textColor;
}
- (UIFont *)labelFont {
return self.switchLabel.font;
}
- (NSString *)labelText {
return self.switchLabel.text;
}
- (BOOL)isSelected {
return self.switchKnob.isOn;
}
#pragma mark - Setters
- (void)setTintColor:(UIColor *)tintColor {
self.switchKnob.onTintColor = tintColor;
}
- (void)setLabelColor:(UIColor *)labelColor {
self.switchLabel.textColor = labelColor;
}
- (void)setLabelFont:(UIFont *)labelFont {
self.switchLabel.font = labelFont;
}
- (void)setLabelText:(NSString *)labelText {
self.switchLabel.text = labelText;
}
@end