//
//  SelectStoreTableCell.m
//  redstar
//
//  Created by admin on 15/12/15.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "SelectStoreTableCell.h"

@implementation SelectStoreTableCell
//- (UIButton *)storeButton1
//{
//    if (!_storeButton1) {
//        _storeButton1 = [[UIButton alloc] init];
//        _storeButton1.translatesAutoresizingMaskIntoConstraints = NO;
//        _storeButton1.backgroundColor = [UIColor lightGrayColor];
//        [self.contentView addSubview:_storeButton1];
//        
//        // 顶端
//        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_storeButton1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
//        [self.contentView addConstraint:titleTop];
//        
//        // 右边
//        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_storeButton1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-5];
//        [self.contentView addConstraint:titleRight];
//        
//        // 左边
//        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_storeButton1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
//        [self.contentView addConstraint:titleLeft];
//        
//        // 高度
//        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_storeButton1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
//        [self.contentView addConstraint:titleHeight];
//        
//        // 高度
//        NSLayoutConstraint *titleBottom = [NSLayoutConstraint constraintWithItem:_storeButton1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5];
//        [self.contentView addConstraint:titleBottom];
//    }
//    return _storeButton1;
//}
//
//- (UIButton *)storeButton2
//{
//    if (!_storeButton2) {
//        _storeButton2 = [[UIButton alloc] init];
//        _storeButton2.translatesAutoresizingMaskIntoConstraints = NO;
//        _storeButton2.backgroundColor = [UIColor lightGrayColor];
//        [self.contentView addSubview:_storeButton2];
//        
//        // 顶端
//        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_storeButton2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
//        [self.contentView addConstraint:titleTop];
//        
//        // 右边
//        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_storeButton2 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
//        [self.contentView addConstraint:titleRight];
//        
//        // 左边
//        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_storeButton2 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:5];
//        [self.contentView addConstraint:titleLeft];
//        
//        // 高度
//        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_storeButton2 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
//        [self.contentView addConstraint:titleHeight];
//    }
//    return _storeButton2;
//}

- (CheckBoxButton *)checkBoxButton
{
    if (!_checkBoxButton) {
        _checkBoxButton = [[CheckBoxButton alloc] init];
        [_checkBoxButton setTitleColor:kLightBlack forState:UIControlStateNormal];
        [_checkBoxButton setTitleColor:kSelectStoreColor forState:UIControlStateSelected];
        _checkBoxButton.titleLabel.font = [UIFont systemFontOfSize:17.0];
        _checkBoxButton.translatesAutoresizingMaskIntoConstraints = NO;
        [_checkBoxButton setImage:[UIImage imageNamed:@"uncheck_box"] forState:UIControlStateNormal];
        [_checkBoxButton setImage:[UIImage imageNamed:@"check_box"] forState:UIControlStateSelected];
        _checkBoxButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
        _checkBoxButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _checkBoxButton.imageView.contentMode = UIViewContentModeRight;
        _checkBoxButton.titleLabel.contentMode = UIViewContentModeLeft;
        [_checkBoxButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_checkBoxButton];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_checkBoxButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:8];
        [self.contentView addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_checkBoxButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:80];
        [self.contentView addConstraint:titleLeft];
        
        
        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_checkBoxButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
        [self.contentView addConstraint:titleHeight];
        
        // 高度
        NSLayoutConstraint *titleBottom = [NSLayoutConstraint constraintWithItem:_checkBoxButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-8];
        [self.contentView addConstraint:titleBottom];
    }
    return _checkBoxButton;
}
- (void)click:(CheckBoxButton *)sender
{
    sender.selected = !sender.selected;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
