QuestionListTableCell.m 13.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//
//  QuestionListTableCell.m
//  redstar
//
//  Created by admin on 15/11/2.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "QuestionListTableCell.h"

@implementation QuestionListTableCell
#pragma mark - System Methods
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setup];
    }
    return self;
}

#pragma mark - Private Methods
- (void)setup
{
    self.titleLabel.textColor = kQuestionCellTitleColor;
25
    
26 27
}

admin's avatar
admin committed
28 29 30 31 32
- (void)setQuestion:(QuestionModel *)question
{
    _question = question;
    
    // 标题
33 34 35 36 37 38 39 40 41 42
   // self.titleLabel.text = [NSString stringWithFormat:@"%@",question.title];
    
    
//    NSString *intro = [NSString stringWithFormat:@"%@", question.content];
//    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:intro];
//    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//    [paragraphStyle setLineSpacing:3];
//    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, intro.length)];
//    [self.detailsLabel setAttributedText:attributedString];
    
admin's avatar
admin committed
43
    // 反馈(副标题)
44
    self.detailsLabel.text = [NSString stringWithFormat:@"%@", question.content];
admin's avatar
admin committed
45
    // 服务类型
46
    self.stateLabel.text = [NSString stringWithFormat:@"%@", question.category];
admin's avatar
admin committed
47 48
    // 提报时间
    self.dateLabel.text = [NSString stringWithFormat:@"提报时间:%@", question.submitTime];
49 50 51 52 53 54 55 56
    // 点赞数
    [self.thumbBtn setTitle:[NSString stringWithFormat:@"%d", question.likeCount] forState:UIControlStateNormal];
    
    if (question.hotspot) {
        self.hotLabel.hidden = NO;
    } else {
        self.hotLabel.hidden = YES;
    }
57 58 59 60 61 62
    
    if (question.myLike) {
        self.thumbBtn.selected = YES;
    } else {
        self.thumbBtn.selected = NO;
    }
admin's avatar
admin committed
63 64
}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#pragma mark - lazy laoding
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
        [self.contentView addSubview:_titleLabel];
        
        // 顶端
        NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10];
        [self.contentView addConstraint:titleTop];
        
        // 左边
        NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.contentView addConstraint:titleLeft];
        
        // 右边
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.hotLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-15];
        [self.contentView addConstraint:titleRight];
        
        // 高度
        NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
        [self.contentView addConstraint:titleHeight];
    }
    return _titleLabel;
}

- (UILabel *)hotLabel
{
    if (!_hotLabel) {
        _hotLabel = [[UILabel alloc] init];
97
        _hotLabel.font = [UIFont boldSystemFontOfSize:12.0];
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        _hotLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _hotLabel.backgroundColor = kHotBackGroundColor;
        _hotLabel.textColor = [UIColor whiteColor];
        _hotLabel.text = @"HOT";
        _hotLabel.textAlignment = NSTextAlignmentCenter;
        _hotLabel.layer.cornerRadius = 3;
        [self.contentView addSubview:_hotLabel];
        
        // 顶端
        NSLayoutConstraint *hotTop = [NSLayoutConstraint constraintWithItem:_hotLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:15];
        [self.contentView addConstraint:hotTop];
        
        // 左边
        NSLayoutConstraint *hotWidth = [NSLayoutConstraint constraintWithItem:_hotLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:34];
        [self.contentView addConstraint:hotWidth];
        
        // 右边
        NSLayoutConstraint *hotRight = [NSLayoutConstraint constraintWithItem:_hotLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.contentView addConstraint:hotRight];
        
        // 高度
        NSLayoutConstraint *hotHeight = [NSLayoutConstraint constraintWithItem:_hotLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:15];
        [self.contentView addConstraint:hotHeight];
    }
    return _hotLabel;
}

- (UILabel *)detailsLabel
{
    if (!_detailsLabel) {
        _detailsLabel = [[UILabel alloc] init];
admin's avatar
admin committed
129
        _detailsLabel.font = [UIFont systemFontOfSize:15.0];
130
        _detailsLabel.numberOfLines = 2;
131 132 133 134 135
        _detailsLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _detailsLabel.textColor = kQuestionCellTitleColor;
        [self.contentView addSubview:_detailsLabel];
        
        // 顶端
136
        NSLayoutConstraint *detailsTop = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:8];
137 138 139 140 141 142
        [self.contentView addConstraint:detailsTop];
        
        // 左边
        NSLayoutConstraint *detailsLeft = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.contentView addConstraint:detailsLeft];
        
143 144 145
//        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.hotLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-15];
//        [self.contentView addConstraint:titleRight];

146
        // 右边
147
        NSLayoutConstraint *detailsRight = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.hotLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-10];
148
        [self.contentView addConstraint:detailsRight];
149 150 151 152 153

        
//        // 右边
//        NSLayoutConstraint *detailsRight = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
//        [self.contentView addConstraint:detailsRight];
154 155
        
        // 高度
156
        NSLayoutConstraint *detailsHeight = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
157 158 159 160 161 162 163 164 165 166 167
        [self.contentView addConstraint:detailsHeight];
    }
    return _detailsLabel;
}

- (UILabel *)stateLabel
{
    if (!_stateLabel) {
        _stateLabel = [[UILabel alloc] init];
        _stateLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _stateLabel.textColor = kQuestionStateColor;
admin's avatar
admin committed
168 169
        _stateLabel.font = [UIFont systemFontOfSize:14.0];

170 171 172
        [self.contentView addSubview:_stateLabel];
        
        // 顶端
173
        NSLayoutConstraint *stateTop = [NSLayoutConstraint constraintWithItem:_stateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.detailsLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        [self.contentView addConstraint:stateTop];
        
        // 左边
        NSLayoutConstraint *stateLeft = [NSLayoutConstraint constraintWithItem:_stateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.contentView addConstraint:stateLeft];
        
        // 右边
        NSLayoutConstraint *stateRight = [NSLayoutConstraint constraintWithItem:_stateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.contentView addConstraint:stateRight];
        
        // 高度
        NSLayoutConstraint *stateHeight = [NSLayoutConstraint constraintWithItem:_stateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:16];
        [self.contentView addConstraint:stateHeight];
    }
    return _stateLabel;
}

- (UILabel *)dateLabel
{
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _dateLabel.textColor = kQuestionStateColor;
admin's avatar
admin committed
197
        _dateLabel.font = [UIFont systemFontOfSize:14.0];
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        [self.contentView addSubview:_dateLabel];
        
        // 顶端
        NSLayoutConstraint *stateTop = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.stateLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
        [self.contentView addConstraint:stateTop];
        
        // 左边
        NSLayoutConstraint *stateLeft = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.contentView addConstraint:stateLeft];
        
        // 右边
        NSLayoutConstraint *stateRight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.thumbBtn attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.contentView addConstraint:stateRight];
        
        // 高度
        NSLayoutConstraint *stateHeight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:16];
        [self.contentView addConstraint:stateHeight];
215 216 217 218
        // 高度
        NSLayoutConstraint *stateBottom = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-8];
        [self.contentView addConstraint:stateBottom];
        
219 220 221 222 223 224 225 226 227
    }
    return _dateLabel;
}

- (ZanButton *)thumbBtn
{
    if (!_thumbBtn) {
        _thumbBtn = [[ZanButton alloc] init];
        _thumbBtn.translatesAutoresizingMaskIntoConstraints = NO;
228
        _thumbBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
229 230
        [_thumbBtn setTitleColor:kNavigationBarColor forState:UIControlStateNormal];
        [_thumbBtn setImage:[UIImage imageNamed:@"commend"] forState:UIControlStateNormal];
231
        [_thumbBtn setImage:[UIImage imageNamed:@"commend_after"] forState:UIControlStateSelected];
232 233 234 235 236 237 238
        [self.contentView addSubview:_thumbBtn];
        
        // 顶端
        NSLayoutConstraint *stateTop = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.stateLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:2];
        [self.contentView addConstraint:stateTop];
        
        // 左边
admin's avatar
admin committed
239
        NSLayoutConstraint *stateWidth = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:65];
240 241 242
        [self.contentView addConstraint:stateWidth];
        
        // 右边
admin's avatar
admin committed
243
        NSLayoutConstraint *stateRight = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-15];
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
        [self.contentView addConstraint:stateRight];
        
        // 高度
        NSLayoutConstraint *stateHeight = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
        [self.contentView addConstraint:stateHeight];
    }
    return _thumbBtn;
}

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

    // Configure the view for the selected state
}

@end