// // SysMsgTableViewCell.m // FirstLink // // Created by ascii on 14/12/26. // Copyright (c) 2014年 FirstLink. All rights reserved. // #import "SysMessageCell.h" @interface SysMessageCell () @end @implementation SysMessageCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self addAllSubviews]; } return self; } #pragma mark - Property - (UILabel*)headLabel { if (!_headLabel) { _headLabel = [[UILabel alloc] init]; _headLabel.font = [UIFont systemFontOfSize:15.0]; _headLabel.textColor = UIColorFromRGB(0x999999); _headLabel.text = @"系统消息"; } return _headLabel; } - (TTTAttributedLabel*)timeLabel { if (!_timeLabel) { _timeLabel = [[TTTAttributedLabel alloc] init]; _timeLabel.font = [UIFont systemFontOfSize:13.0]; _timeLabel.textColor = UIColorFromRGB(0x999999); _timeLabel.textAlignment = NSTextAlignmentRight; } return _timeLabel; } - (TTTAttributedLabel*)descLabel { if (!_descLabel) { _descLabel = [[TTTAttributedLabel alloc] init]; _descLabel.font = [UIFont systemFontOfSize:14.0]; _descLabel.textColor = UIColorFromRGB(0x333333); _descLabel.lineBreakMode = NSLineBreakByCharWrapping; _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop; _descLabel.numberOfLines = 0; } return _descLabel; } - (UIButton *)detailButton { if (!_detailButton) { _detailButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_detailButton setTitle:@"查看详情 >" forState:UIControlStateNormal]; [_detailButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; [_detailButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal]; _detailButton.layer.borderColor = [UIColor orangeColor].CGColor; } return _detailButton; } - (UIView*)makeNewLine { UIView *view = [[UIView alloc] init]; view.backgroundColor = UIColorFromRGB(0xe5e5e5); return view; } #pragma mark - - (void)addAllSubviews { WeakSelf(weakSelf); [self.contentView addSubview:self.headLabel]; [self.headLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.contentView).with.offset(15); make.top.equalTo(weakSelf.contentView).with.offset(8); make.size.mas_equalTo(CGSizeMake(75, 24)); }]; [self.contentView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.contentView).with.offset(-20); make.centerY.equalTo(weakSelf.headLabel.mas_centerY); make.width.mas_greaterThanOrEqualTo(40); make.height.mas_equalTo(20); }]; UIView *line = [self makeNewLine]; [self.contentView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.contentView); make.right.equalTo(weakSelf.contentView); make.top.equalTo(weakSelf.headLabel.mas_bottom).with.offset(8); make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale); }]; [self.contentView addSubview:self.detailButton]; [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(weakSelf.contentView).with.offset(-2); make.right.equalTo(weakSelf.contentView).with.offset(-15); make.width.mas_equalTo(80); make.height.mas_equalTo(36); }]; [self.contentView addSubview:self.descLabel]; [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.contentView).with.offset(15); make.right.equalTo(weakSelf.contentView).with.offset(-15); make.top.equalTo(line.mas_bottom).with.offset(13); make.bottom.equalTo(weakSelf.contentView).with.offset(-0); }]; } #pragma mark - Help Method + (CGFloat)cellHeightWith:(FKAppMessage*)item { if (!item.content) { return 44; } CGFloat height; int maxRow; // if (item.targetURL.length > 0) { // maxRow = 2; // height = (8 + 24 + 8 + 10 + 36 + 2 + 1); // } else { height = (8 + 24 + 8 + 13 + 36 + 2 + 1); maxRow = 100; // } CGSize size = [FLStringHelper sizeOfAttributeString:item.content font:[UIFont systemFontOfSize:14.0] width:(UISCREENWIDTH - 2*15) maxRow:maxRow]; height += size.height; return height; } @end