-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBFlatSegmentedControl.m
executable file
·69 lines (59 loc) · 2.49 KB
/
PBFlatSegmentedControl.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
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
//
// PBFlatSegmentedControl.m
// FlatUIlikeiOS7
//
// Created by Piotr Bernad on 11.06.2013.
// Copyright (c) 2013 Piotr Bernad. All rights reserved.
//
#import "PBFlatSegmentedControl.h"
#import "PBFlatSettings.h"
@implementation PBFlatSegmentedControl {
CGRect _rect;
}
- (void)awakeFromNib {
[super awakeFromNib];
self.layer.cornerRadius = 5.0f;
self.layer.borderWidth = 1.0f;
self.layer.borderColor = [[PBFlatSettings sharedInstance] mainColor].CGColor;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self apperance];
}
return self;
}
- (id)initWithItems:(NSArray *)items {
self = [super initWithItems:items];
if (self) {
[self apperance];
self.layer.cornerRadius = 5.0f;
self.layer.borderWidth = 1.0f;
self.layer.borderColor = [[PBFlatSettings sharedInstance] mainColor].CGColor;
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
_rect = self.bounds;
}
- (void)apperance {
// Set background images
UIImage *normalBackgroundImage = [UIImage imageWithColor:[[PBFlatSettings sharedInstance] mainColor] size:CGSizeMake(10.0f, 40.0f) andRoundSize:5.0f];
UIImage *selectedBackgroundImage = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(10.0f, 40.0f) andRoundSize:5.0f];
NSDictionary *attributes = @{NSForegroundColorAttributeName: [[PBFlatSettings sharedInstance] font],
NSForegroundColorAttributeName: [[PBFlatSettings sharedInstance] mainColor],
NSShadowAttributeName: [NSValue valueWithUIOffset:UIOffsetZero],
NSShadowAttributeName: [UIColor clearColor]};
[self setTitleTextAttributes:attributes forState:UIControlStateNormal];
NSDictionary *highlightedAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
[self setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
[self setBackgroundImage:selectedBackgroundImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:normalBackgroundImage
forState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[self setDividerImage:[UIImage imageWithColor:[UIColor clearColor]] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
@end