123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- //
- // PindanMSGTableViewCell.m
- // FirstLink
- //
- // Created by Lemon on 15/4/27.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "PindanMessageCell.h"
- @interface PindanMessageCell ()
- @end
- @implementation PindanMessageCell
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self addAllSubViews];
- }
- return self;
- }
- #pragma mark - Generate Properties
- - (UIImageView *)photoView {
- if (!_photoView) {
- _photoView = [[UIImageView alloc] init];
- _photoView.layer.borderWidth = 1.0;//[UIScreen mainScreen].scale;
- _photoView.layer.borderColor = UIColorFromRGB(0xe5e5e5).CGColor;
- }
- return _photoView;
- }
- - (UILabel *)timeLabel {
- if (!_timeLabel) {
- _timeLabel = [[UILabel alloc] init];
- _timeLabel.font = [UIFont systemFontOfSize:13];
- _timeLabel.textColor = UIColorFromRGB(0x7a7a7a);
- // _timeLabel.backgroundColor = [UIColor redColor];
- }
- return _timeLabel;
- }
- - (UIImageView*)unreadView {
- if (!_unreadView) {
- _unreadView = [[UIImageView alloc] init];
- _unreadView.backgroundColor = UIColorFromRGB(0x00c8a9);
- _unreadView.layer.cornerRadius = 4;
- }
- return _unreadView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.font = [UIFont systemFontOfSize:13];
- _titleLabel.textColor = UIColorFromRGB(0x333333);
- }
- return _titleLabel;
- }
- - (TTTAttributedLabel*)descLabel {
- if (!_descLabel) {
- _descLabel = [[TTTAttributedLabel alloc] init];
- _descLabel.font = [UIFont systemFontOfSize:14];
- _descLabel.textColor = UIColorFromRGB(0x333333);
- _descLabel.lineBreakMode = NSLineBreakByCharWrapping;
- _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
- _descLabel.numberOfLines = 0;
- // _descLabel.backgroundColor = [UIColor redColor];
- }
- return _descLabel;
- }
- - (UIButton *)detailButton {
- if (!_detailButton) {
- _detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_detailButton setTitle:@"查看详情" forState:UIControlStateNormal];
- [_detailButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
- [_detailButton setTitleColor:UIColorFromRGB(0x999999)
- forState:UIControlStateNormal];
- _detailButton.layer.borderColor = [UIColor orangeColor].CGColor;
- _detailButton.userInteractionEnabled = NO;
-
- _detailButton.imageEdgeInsets = UIEdgeInsetsMake(0, -12, 0, 0);
- _detailButton.transform = CGAffineTransformMakeScale(-1.0, 1.0);
- _detailButton.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
- _detailButton.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
- [_detailButton setImage:[UIImage imageNamed:@"thin_right_arrow"] forState:UIControlStateNormal];
- }
- return _detailButton;
- }
- #pragma mark - Layout
- - (void)addAllSubViews {
- [self.contentView addSubview:self.photoView];
- [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView);
- make.size.mas_equalTo(CGSizeMake(75, 75));
- }];
-
- [self.contentView addSubview:self.unreadView];
- [self.unreadView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).offset(-4);
- make.top.equalTo(self.photoView.mas_top).offset(-2);
- make.size.mas_equalTo(CGSizeMake(8, 8));
- }];
-
- [self.contentView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).with.offset(15);
- make.right.equalTo(self.contentView).offset(-15);
- make.top.equalTo(self.contentView).offset(6);
- make.height.mas_equalTo(34);
- }];
-
- [self.contentView addSubview:self.descLabel];
- [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).offset(15);
- make.right.equalTo(self.contentView).offset(-15);
- make.top.equalTo(self.titleLabel.mas_bottom).offset(0);
- }];
- self.descConstraint = [NSLayoutConstraint constraintWithItem:self.descLabel
- attribute:NSLayoutAttributeHeight
- relatedBy:NSLayoutRelationEqual
- toItem:self
- attribute:NSLayoutAttributeHeight
- multiplier:1.0
- constant:0];
-
- [self.contentView addSubview:self.timeLabel];
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).offset(15);
- make.top.equalTo(self.descLabel.mas_bottom).offset(6);
- make.width.mas_greaterThanOrEqualTo(40);
- make.height.mas_equalTo(20);
- }];
-
- [self.contentView addSubview:self.detailButton];
- [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-15);
- make.centerY.equalTo(self.timeLabel);
- make.width.mas_greaterThanOrEqualTo(80);
- make.height.mas_equalTo(36);
- }];
- }
- #pragma mark -
- - (void)setUnreadViewWith:(NSString *)status {
- if (!status) {
- self.unreadView.hidden = YES;
- }
-
- if ([status isEqualToString:@"1"]) {
- self.unreadView.hidden = NO;
- } else {
- self.unreadView.hidden = YES;
- }
- }
- - (void)layoutWithTitle:(BOOL)isWithTitle {
- if (isWithTitle) {
- [self.descLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).offset(15);
- make.right.equalTo(self.contentView).offset(-15);
- make.top.equalTo(self.titleLabel.mas_bottom).offset(0);
- }];
- } else {
- [self.descLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.photoView.mas_right).offset(15);
- make.right.equalTo(self.contentView).offset(-15);
- make.top.equalTo(self.contentView).offset(18);
- }];
- }
- }
- #pragma mark - Helper
- + (CGFloat)titleHeightWith:(NSString *)title {
- return [FLStringHelper sizeOfAttributeString:title
- font:[UIFont systemFontOfSize:13]
- width:(UISCREENWIDTH - 15 - 75 - 2*15)
- maxRow:100].height;
- }
- + (CGFloat)cellHeightWith:(NSString *)title isWithTitle:(BOOL)isWithTitle {
- CGFloat offset = (isWithTitle ? 22 : 0);
- CGFloat otherHeight = (18 + offset + 6 + 20 + 16 + 1);
- CGFloat titleHeight = [PindanMessageCell titleHeightWith:title];
-
- return MAX(110, otherHeight + titleHeight);
- }
- @end
|