-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCBDSwitchView.m
41 lines (32 loc) · 1.49 KB
/
CBDSwitchView.m
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
#import "CBDSwitchView.h"
@implementation CBDSwitchView
-(CBDSwitchView *)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
self.titleLabel.text = @"SWITCH";
self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.titleLabel];
self.theSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.theSwitch.translatesAutoresizingMaskIntoConstraints = NO;
[self.theSwitch setTintColor:[UIColor blackColor]];
[self.theSwitch setOnTintColor:[UIColor blackColor]];
[self addSubview:self.theSwitch];
[NSLayoutConstraint activateConstraints:@[
[self.theSwitch.topAnchor constraintEqualToAnchor:self.topAnchor constant:10],
[self.theSwitch.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-5],
[self.theSwitch.heightAnchor constraintEqualToConstant:30],
]];
[NSLayoutConstraint activateConstraints:@[
[self.titleLabel.topAnchor constraintEqualToAnchor:self.topAnchor constant:10],
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.theSwitch.leadingAnchor constant:-5],
[self.titleLabel.heightAnchor constraintEqualToConstant:30]
]];
[NSLayoutConstraint activateConstraints:@[
[self.heightAnchor constraintEqualToConstant:50],
]];
return self;
}
@end