TaxisView.m 2.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//
//  TaxisView.m
//  redstar
//
//  Created by admin on 15/11/10.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "TaxisView.h"

11 12 13 14
@interface TaxisView ()
@property (nonatomic, strong) NSMutableArray *buttons;
@end

15 16 17 18 19 20
@implementation TaxisView

- (instancetype)init
{
    self = [super init];
    if (self) {
21
        self.buttons = [NSMutableArray array];
22 23 24 25 26 27 28 29 30
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
31
        self.buttons = [NSMutableArray array];
32 33 34 35 36 37 38
        [self setup];
    }
    return self;
}

- (void)setup
{
39 40
    
    
41 42
}

43
- (void)layoutSubviews
44
{
45 46 47
    CGFloat buttonW = kScreenWidth;
    CGFloat buttonH = self.frame.size.height / 3;
    
admin's avatar
admin committed
48 49 50 51 52 53 54
    NSArray *titleArray;
    if (self.tag == 3928342) {
        titleArray = @[@"默认排序",@"按时间顺序排序",@"按时间逆序排序"];
    } else {
        titleArray = @[@"默认排序",@"按点赞数由大到小排序",@"按点赞数由小到大排序"];
    }
        
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    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];
78
    }
79 80
    UIButton *tempBtn = [_buttons objectAtIndex:0];
    tempBtn.selected = YES;
81 82 83
}


84 85 86
- (void)touchDownForButton:(UIButton *)button{
    for (UIButton * b in self.buttons) {
        b.selected = NO;
87
    }
88 89 90
    
    button.selected = YES;
    
admin's avatar
admin committed
91
    if (_delegate) {
92
        [_delegate timeChange:button];
admin's avatar
admin committed
93
    }
94 95 96
    
    
    
admin's avatar
admin committed
97 98
}

99 100 101



102
@end