PictureTableCell.m 16.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  PictureTableCell.m
//  redstar
//
//  Created by admin on 15/11/1.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "PictureTableCell.h"
admin's avatar
admin committed
10
#import <UIImageView+WebCache.h>
11 12 13 14 15 16 17 18

@interface PictureTableCell ()
@property (nonatomic, strong) UILabel *hotLabel;
@end

@implementation PictureTableCell


admin's avatar
admin committed
19
- (void)setPictureList:(PictureListModel *)pictureList
20
{
admin's avatar
admin committed
21 22 23 24 25
    _pictureList = pictureList;
    if (pictureList.attachments.count != 0) {
        NSDictionary *dict = pictureList.attachments[0];
        NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,dict[@"fileUrl"]]];
        [self.titleImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"default_pic"]];
admin's avatar
admin committed
26
        
admin's avatar
admin committed
27 28 29 30 31 32 33 34
    } else {
        self.titleImageView.image = [UIImage imageNamed:@"default_pic"];
    }


    self.titleLabel.text = [NSString stringWithFormat:@"%@", pictureList.title];
    self.detailsLabel.text = [NSString stringWithFormat:@"%@", pictureList.content];
    if (pictureList.submitTime == nil || pictureList.submitTime == NULL || [pictureList.submitTime isEqual:[NSNull null]]) {
admin's avatar
admin committed
35
        self.dateLabel.text = [NSString stringWithFormat:@""];
admin's avatar
admin committed
36
    } else {
admin's avatar
admin committed
37
        self.dateLabel.text = [[NSString stringWithFormat:@"%@",pictureList.submitTime] substringToIndex:10];
admin's avatar
admin committed
38
    }
admin's avatar
admin committed
39
    self.adressLabel.text = [NSString stringWithFormat:@"%@", pictureList.store_name];
admin's avatar
admin committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53
    
    if (pictureList.hotspot) {
        self.hotLabel.hidden = NO;
    } else {
        self.hotLabel.hidden = YES;
    }
    
    if (pictureList.myLike) {
        self.thumbBtn.selected = YES;
    } else {
        self.thumbBtn.selected = NO;
    }
    
    [self.thumbBtn setTitle:[NSString stringWithFormat:@"%d", pictureList.likeCount] forState:UIControlStateNormal];
admin's avatar
admin committed
54
    [self.commentBtn setTitle:[NSString stringWithFormat:@"%d", pictureList.commentCount] forState:UIControlStateNormal];
55 56
}

admin's avatar
admin committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

//裁剪图片
- (UIImage *)cutImage:(UIImage*)image
{
    //压缩图片
    CGSize newSize;
    CGImageRef imageRef = nil;
    
    if ((image.size.width / image.size.height) < (((kScreenWidth - 20 * 3) / 2) / 90)) {
        newSize.width = image.size.width;
        newSize.height = image.size.width * 90 / ((kScreenWidth - 20 * 3) / 2);
        
        imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(0, fabs(image.size.height - newSize.height) / 2, newSize.width, newSize.height));
        
    } else {
        newSize.height = image.size.height;
        newSize.width = image.size.height * ((kScreenWidth - 20 * 3) / 2) / 90;
        
        imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(fabs(image.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));
        
    }
    
    return [UIImage imageWithCGImage:imageRef];
}


83 84 85 86 87 88
#pragma mark - Lazy loading
- (UIImageView *)titleImageView
{
    if (!_titleImageView) {
        _titleImageView = [[UIImageView alloc] init];
        _titleImageView.translatesAutoresizingMaskIntoConstraints = NO;
89 90
        _titleImageView.contentMode = UIViewContentModeScaleAspectFill;
        _titleImageView.clipsToBounds = YES;
91 92
        [self.contentView addSubview:_titleImageView];
        
admin's avatar
admin committed
93
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_titleImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:28];
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
        [self.contentView addConstraint:titleImageTop];
        
        NSLayoutConstraint *titleImageLeft = [NSLayoutConstraint constraintWithItem:_titleImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:15];
        [self.contentView addConstraint:titleImageLeft];
        
        NSLayoutConstraint *titleImageWidth = [NSLayoutConstraint constraintWithItem:_titleImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:85];
        [self.contentView addConstraint:titleImageWidth];
        
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_titleImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60];
        [self.contentView addConstraint:titleImageHeight];
    }
    return _titleImageView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
admin's avatar
admin committed
112 113
        _titleLabel.textColor = kPictureCellTitleColor;

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        _titleLabel.font = [UIFont systemFontOfSize:17.0];
        _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [self.contentView addSubview:_titleLabel];
        
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:16];
        [self.contentView addConstraint:titleImageTop];
        
        NSLayoutConstraint *titleImageLeft = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:10];
        [self.contentView addConstraint:titleImageLeft];
        
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.hotLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.contentView addConstraint:titleRight];
        
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
        [self.contentView addConstraint:titleImageHeight];
    }
    return _titleLabel;
}
- (UILabel *)hotLabel
{
    if (!_hotLabel) {
        _hotLabel = [[UILabel alloc] init];
        _hotLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _hotLabel.backgroundColor = kHotBackGroundColor;
        _hotLabel.textColor = [UIColor whiteColor];
admin's avatar
admin committed
139
        _hotLabel.font = [UIFont boldSystemFontOfSize:12.0];
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
        _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:20];
        [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];
        _detailsLabel.font = [UIFont systemFontOfSize:15.0];
        _detailsLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _detailsLabel.numberOfLines = 0;
admin's avatar
admin committed
168 169
        _detailsLabel.textColor = kPictureCellDetailsColor;

170 171 172 173 174 175 176 177 178 179 180
        [self.contentView addSubview:_detailsLabel];
        
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.contentView addConstraint:titleImageTop];
        
        NSLayoutConstraint *titleImageLeft = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:10];
        [self.contentView addConstraint:titleImageLeft];
        
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-15];
        [self.contentView addConstraint:titleRight];
        
admin's avatar
admin committed
181
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_detailsLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:23];
182 183 184 185 186
        [self.contentView addConstraint:titleImageHeight];
    }
    return _detailsLabel;
}

admin's avatar
admin committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
- (UILabel *)adressLabel
{
    if (!_adressLabel) {
        _adressLabel = [[UILabel alloc] init];
        _adressLabel.font = [UIFont systemFontOfSize:14.0];
        _adressLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _adressLabel.numberOfLines = 0;
        _adressLabel.textColor = kLightGray;
        
        [self.contentView addSubview:_adressLabel];
        
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_adressLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.detailsLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.contentView addConstraint:titleImageTop];
        
        NSLayoutConstraint *titleImageLeft = [NSLayoutConstraint constraintWithItem:_adressLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:10];
        [self.contentView addConstraint:titleImageLeft];
        
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_adressLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-15];
        [self.contentView addConstraint:titleRight];
        
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_adressLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:23];
        [self.contentView addConstraint:titleImageHeight];
    }
    return _adressLabel;
}

213 214 215 216 217 218
- (UILabel *)dateLabel
{
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _dateLabel.font = [UIFont systemFontOfSize:14.0];
admin's avatar
admin committed
219 220
        _dateLabel.textColor = kPictureCellDateColor;

221 222
        [self.contentView addSubview:_dateLabel];
        
admin's avatar
admin committed
223
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:7];
224 225
        [self.contentView addConstraint:titleImageTop];
        
admin's avatar
admin committed
226
        NSLayoutConstraint *titleImageLeft = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:5];
227 228 229 230 231
        [self.contentView addConstraint:titleImageLeft];
        
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.thumbBtn attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.contentView addConstraint:titleRight];
        
admin's avatar
admin committed
232
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
233
        [self.contentView addConstraint:titleImageHeight];
234
        
admin's avatar
admin committed
235
        NSLayoutConstraint *titleImageBottom = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5];
236
        [self.contentView addConstraint:titleImageBottom];
237 238 239 240 241 242 243 244 245
    }
    return _dateLabel;
}

- (ZanButton *)thumbBtn
{
    if (!_thumbBtn) {
        _thumbBtn = [[ZanButton alloc] init];
        [_thumbBtn setImage:[UIImage imageNamed:@"commend"] forState:UIControlStateNormal];
admin's avatar
admin committed
246
        [_thumbBtn setImage:[UIImage imageNamed:@"commend_after"] forState:UIControlStateSelected];
247 248
        _thumbBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_thumbBtn setTitleColor:kNavigationBarColor forState:UIControlStateNormal];
admin's avatar
admin committed
249
        _thumbBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
250 251
        [self.contentView addSubview:_thumbBtn];
        
admin's avatar
admin committed
252
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:8];
253 254 255 256 257
        [self.contentView addConstraint:titleImageTop];
        
        NSLayoutConstraint *titleImageWidth = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.commentBtn attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
        [self.contentView addConstraint:titleImageWidth];
        
admin's avatar
admin committed
258
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.commentBtn attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-3];
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
        [self.contentView addConstraint:titleRight];
        
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_thumbBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
        [self.contentView addConstraint:titleImageHeight];
    }
    return _thumbBtn;
}

- (ZanButton *)commentBtn
{
    if (!_commentBtn) {
        _commentBtn = [[ZanButton alloc] init];
        [_commentBtn setImage:[UIImage imageNamed:@"comment"] forState:UIControlStateNormal];
        _commentBtn.translatesAutoresizingMaskIntoConstraints = NO;
        [_commentBtn setTitleColor:kNavigationBarColor forState:UIControlStateNormal];
admin's avatar
admin committed
274
        _commentBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
275 276
        [self.contentView addSubview:_commentBtn];
        
admin's avatar
admin committed
277
        NSLayoutConstraint *titleImageTop = [NSLayoutConstraint constraintWithItem:_commentBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.titleImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:8];
278 279
        [self.contentView addConstraint:titleImageTop];
        
admin's avatar
admin committed
280
        NSLayoutConstraint *titleImageWidth = [NSLayoutConstraint constraintWithItem:_commentBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60];
281 282
        [self.contentView addConstraint:titleImageWidth];
        
admin's avatar
admin committed
283
        NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_commentBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-8];
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
        [self.contentView addConstraint:titleRight];
        
        NSLayoutConstraint *titleImageHeight = [NSLayoutConstraint constraintWithItem:_commentBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
        [self.contentView addConstraint:titleImageHeight];
    }
    return _commentBtn;
}
- (void)awakeFromNib {
    // Initialization code
}

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

    // Configure the view for the selected state
}

@end