|
//
// searchHistoryCell.m
// ThePaperBase
//
// Created by Huixin on 15/7/27.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "searchHistoryCell.h"
@interface searchHistoryCell ()
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIView *line;
@property(nonatomic, strong) UIButton *deleteBtn;
@end
@implementation searchHistoryCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
// self.selectionStyle = UITableViewCellSelectionStyleGray;
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.line];
[self.contentView addSubview:self.deleteBtn];
[self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top).offset(14.5);
make.left.equalTo(self.contentView.left).offset(10);
make.height.mas_equalTo(@20);
}];
[self.deleteBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top);
make.left.equalTo(self.titleLabel.right);
make.right.equalTo(self.contentView.right);
make.bottom.equalTo(self.line.top);
make.width.mas_equalTo(@40);
}];
[self.line makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.bottom).offset(14);
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right).offset(-10);
make.height.mas_equalTo(@0.5);
}];
[self.deleteBtn setImageEdgeInsets:UIEdgeInsetsMake(20, 12.5, 21, 20)];
}
return self;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
_titleLabel.backgroundColor = [UIColor clearColor];
}
return _titleLabel;
}
- (UIView*)line {
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (UIButton*)deleteBtn {
if (!_deleteBtn) {
_deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteBtn setImage:Image(@"setting/search_clearIcon.png") forState:UIControlStateNormal];
_deleteBtn.backgroundColor = [UIColor clearColor];
[_deleteBtn addTarget:self action:@selector(doDelete:) forControlEvents:UIControlEventTouchUpInside];
}
return _deleteBtn;
}
- (void)setSearchStr:(NSString *)str {
_searchStr = str;
_titleLabel.text = str;
}
- (void)doDelete:(id)sender {
if ([self.delegate respondsToSelector:@selector(deleteStrAtIndex:)]) {
id view = [self superview];
while (view && [view isKindOfClass:[UITableView class]] == NO) {
view = [view superview];
}
NSInteger row = [(UITableView*)view indexPathForCell:self].row;
[self.delegate deleteStrAtIndex:row];
}
}
@end
|