/************************************************************ * * EaseMob CONFIDENTIAL * __________________ * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. * * NOTICE: All information contained herein is, and remains * the property of EaseMob Technologies. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from EaseMob Technologies. */ #import "CustomerListCell.h" @implementation CustomerListCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor whiteColor]; self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self layoutAllComponents]; } return self; } #pragma mark - Generate Properties - (APAvatarImageView *)headView { if (!_headView) { _headView = [[APAvatarImageView alloc] init]; _headView.borderColor = [UIColor whiteColor]; _headView.borderWidth = 0.0; _headView.cornerRadius = 3.0; } return _headView; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.font = [UIFont systemFontOfSize:14.0]; _nickLabel.textColor = [UIColor blackColor]; // _nickLabel.backgroundColor = [UIColor redColor]; } return _nickLabel; } - (UILabel *)messageLabel { if (!_messageLabel) { _messageLabel = [[UILabel alloc] init]; _messageLabel.font = [UIFont systemFontOfSize:13.0]; _messageLabel.textColor = UIColorFromRGB(0x999999); } return _messageLabel; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [[UILabel alloc] init]; _timeLabel.font = [UIFont systemFontOfSize:12.0]; _timeLabel.textAlignment = NSTextAlignmentRight; _timeLabel.textColor = [UIColor lightGrayColor]; // _timeLabel.backgroundColor = [UIColor redColor]; } return _timeLabel; } - (UILabel *)unreadLabel { if (!_unreadLabel) { _unreadLabel = [[UILabel alloc] init]; _unreadLabel.textColor = [UIColor whiteColor]; _unreadLabel.backgroundColor = UIColorFromRGB(0x00c8a9); _unreadLabel.textAlignment = NSTextAlignmentCenter; _unreadLabel.font = [UIFont systemFontOfSize:11]; _unreadLabel.layer.cornerRadius = 8; _unreadLabel.clipsToBounds = YES; } return _unreadLabel; } #pragma mark - Layout - (void)layoutAllComponents { WeakSelf(weakSelf); [self.contentView addSubview:self.headView]; [self.headView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.contentView).with.offset(15); make.centerY.equalTo(weakSelf.contentView); make.size.mas_equalTo(CGSizeMake(36, 36)); }]; [self.contentView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.contentView).with.offset(-12); make.top.equalTo(weakSelf.headView.mas_top).with.offset(-2); make.size.mas_equalTo(CGSizeMake(100, 20)); }]; [self.contentView addSubview:self.nickLabel]; [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.headView.mas_right).with.offset(14); make.right.equalTo(weakSelf.timeLabel.mas_left).with.offset(4); make.top.equalTo(weakSelf.headView.mas_top).with.offset(-2); make.height.mas_equalTo(20); }]; [self.contentView addSubview:self.messageLabel]; [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.headView.mas_right).with.offset(14); make.right.equalTo(weakSelf.contentView).with.offset(-12); make.bottom.equalTo(weakSelf.headView.mas_bottom).with.offset(4); make.height.mas_equalTo(20); }]; [self.contentView addSubview:self.unreadLabel]; [self.unreadLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.headView.mas_right).with.offset(-6); make.top.equalTo(weakSelf.headView.mas_top).with.offset(-6); make.width.mas_greaterThanOrEqualTo(16); make.height.mas_equalTo(16); }]; } #pragma mark - Unread Label - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if (![_unreadLabel isHidden]) { _unreadLabel.backgroundColor = [UIColor redColor]; } } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{ [super setHighlighted:highlighted animated:animated]; if (![_unreadLabel isHidden]) { _unreadLabel.backgroundColor = [UIColor redColor]; } } @end