//
//  TaxisView.m
//  redstar
//
//  Created by admin on 15/11/10.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "TaxisView.h"

@implementation TaxisView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    [self.defaultBtn setTitle:@"默认排序" forState:UIControlStateNormal];
    [self.sequenceBtn setTitle:@"时间顺序排序" forState:UIControlStateNormal];

    [self.changeoverBtn setTitle:@"时间逆序排序" forState:UIControlStateNormal];

}

#pragma mark - Lazy loading
- (UIButton *)defaultBtn
{
    if (!_defaultBtn) {
        _defaultBtn = [[UIButton alloc] init];
        _defaultBtn.layer.borderWidth = 0.5;
        _defaultBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
        _defaultBtn.layer.borderColor = kSeparateLineCGColor;
        _defaultBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_defaultBtn setTitleColor:kInspectSectionButtonTextColor forState:UIControlStateNormal];
        _defaultBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;
        _defaultBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [self addSubview:_defaultBtn];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_defaultBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_defaultBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self addConstraint:titleLeft];
        
        // 右边
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_defaultBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self addConstraint:titleRight];
        
        // 右边
        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_defaultBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.sequenceBtn attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0];
        [self addConstraint:titleHeight];
    }
    return _defaultBtn;
}

- (UIButton *)sequenceBtn
{
    if (!_sequenceBtn) {
        _sequenceBtn = [[UIButton alloc] init];
        _sequenceBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
        _sequenceBtn.translatesAutoresizingMaskIntoConstraints = NO;
        _sequenceBtn.layer.borderColor = kSeparateLineCGColor;
        _sequenceBtn.layer.borderWidth = 0.5;
        [_sequenceBtn setTitleColor:kInspectSectionButtonTextColor forState:UIControlStateNormal];
        _sequenceBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        _sequenceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;

        [self addSubview:_sequenceBtn];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_sequenceBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_defaultBtn attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_sequenceBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self addConstraint:titleLeft];
        
        // 右边
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_sequenceBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self addConstraint:titleRight];
        
        // 右边
        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_sequenceBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.changeoverBtn attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0];
        [self addConstraint:titleHeight];
    }
    return _sequenceBtn;
}

- (UIButton *)changeoverBtn
{
    if (!_changeoverBtn) {
        _changeoverBtn = [[UIButton alloc] init];
        _changeoverBtn.layer.borderColor = kSeparateLineCGColor;
        _changeoverBtn.layer.borderWidth = 0.5;
        _changeoverBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
        _changeoverBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;
        _changeoverBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_changeoverBtn setTitleColor:kInspectSectionButtonTextColor forState:UIControlStateNormal];
        _changeoverBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [self addSubview:_changeoverBtn];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_changeoverBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_sequenceBtn attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_changeoverBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self addConstraint:titleLeft];
        
        // 右边
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_changeoverBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self addConstraint:titleRight];
        
        // 右边
        NSLayoutConstraint *titleBottom = [NSLayoutConstraint constraintWithItem:_changeoverBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:titleBottom];
    }
    return _changeoverBtn;
}

@end
