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
//
// TaxisView.m
// redstar
//
// Created by admin on 15/11/10.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "TaxisView.h"
@interface TaxisView ()
@property (nonatomic, strong) NSMutableArray *buttons;
@end
@implementation TaxisView
- (instancetype)init
{
self = [super init];
if (self) {
self.buttons = [NSMutableArray array];
[self setup];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.buttons = [NSMutableArray array];
[self setup];
}
return self;
}
- (void)setup
{
}
- (void)layoutSubviews
{
CGFloat buttonW = kScreenWidth;
CGFloat buttonH = self.frame.size.height / 3;
NSArray *titleArray = @[@"默认排序",@"时间顺序排序",@"时间逆序排序"];
for (int i = 0; i < 3; i++) {
UIButton *button = [[UIButton alloc] init];
button.titleLabel.font = [UIFont systemFontOfSize:15.0];
button.tag = kTAxisBtnTag + i + 1;
[button setTitleColor:kLightBlack forState:UIControlStateNormal];
[button setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
button.frame = CGRectMake(0, i * buttonH, buttonW, buttonH);
[button setTitle:titleArray[i] forState:UIControlStateNormal];
button.layer.borderWidth = 0.5;
button.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
button.layer.borderColor = kSeparateLineCGColor;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;
button.titleLabel.font = [UIFont systemFontOfSize:14.0];
[button setImage:[UIImage imageNamed:@"iconfont-duigou2"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"iconfont-duigou"] forState:UIControlStateSelected];
button.imageEdgeInsets = UIEdgeInsetsMake(0, kScreenWidth - 30, 0, 0);
button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
button.imageView.contentMode = UIViewContentModeRight;
button.titleLabel.contentMode = UIViewContentModeLeft;
[button addTarget:self action:@selector(touchDownForButton:) forControlEvents:UIControlEventTouchDown];
button.adjustsImageWhenHighlighted = NO;
[self addSubview:button];
[self.buttons addObject:button];
}
UIButton *tempBtn = [_buttons objectAtIndex:0];
tempBtn.selected = YES;
}
- (void)touchDownForButton:(UIButton *)button{
for (UIButton * b in self.buttons) {
b.selected = NO;
}
button.selected = YES;
if (_delegate) {
[_delegate timeChange:button];
}
}
@end