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
//
// IBTSegmentContainer.m
// XFFruit
//
// Created by Xummer on 4/11/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTSegmentContainer.h"
#define SEGMENT_LEFT_PADDING (15)
@implementation IBTSegmentContainer
#pragma mark - Life Cycle
- (id)initWithItems:(NSArray *)items {
self = [super init];
if (self) {
self.segmentControl = [[IBTSegmentedControl alloc] initWithItems:items];
[self addSubview:_segmentControl];
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self _init];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
_segmentControl.frame = (CGRect){
.origin.x = SEGMENT_LEFT_PADDING,
.origin.y = (CGRectGetHeight(self.bounds) - SEGMENT_HEIGHT) * .5f,
.size.width = CGRectGetWidth(self.bounds) - 2 * SEGMENT_LEFT_PADDING,
.size.height = SEGMENT_HEIGHT
};
}
#pragma mark - Private Method
- (void)_init {
self.backgroundColor = [UIColor whiteColor];
IBTUIView *greyLine = [[IBTUIView alloc] initWithFrame:(CGRect){
.origin.x = 0,
.origin.y = CGRectGetHeight(self.bounds) - 1,
.size.width = CGRectGetWidth(self.bounds),
.size.height = 1
}];
greyLine.backgroundColor = IBT_CELL_GREY_LINE_COLOR;
greyLine.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[self addSubview:greyLine];
}
@end