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

#import "SelectAreaTableCell.h"

@implementation SelectAreaTableCell

- (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;
        [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:20];
        [self.contentView addConstraint:titleLeft];
        
        
        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_checkBoxButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:34];
        [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;
}


- (UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.contentView addSubview:_iconImageView];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_iconImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:23];
        [self.contentView addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleWidth = [NSLayoutConstraint constraintWithItem:_iconImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:13];
        [self.contentView addConstraint:titleWidth];
        
        // 右边
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_iconImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.contentView addConstraint:titleRight];
        
        // 高度
        NSLayoutConstraint *titleBottom = [NSLayoutConstraint constraintWithItem:_iconImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:8];
        [self.contentView addConstraint:titleBottom];
    }
    return _iconImageView;
}

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

    // Configure the view for the selected state
}

@end
