123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // SessionListCell.m
- // FirstLink
- //
- // Created by Lemon on 15/4/20.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "SessionListCell.h"
- @interface SessionListCell ()
- @end
- @implementation SessionListCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
- [self layoutAllComponents];
- }
- return self;
- }
- #pragma mark - Generate Properties
- - (APAvatarImageView *)iconView {
- if (!_iconView) {
- _iconView = [[APAvatarImageView alloc] init];
- _iconView.borderColor = [UIColor whiteColor];
- }
- return _iconView;
- }
- - (UILabel *)tagLabel {
- if (!_tagLabel) {
- _tagLabel = [[UILabel alloc] init];
- _tagLabel.font = [UIFont systemFontOfSize:16.0];
- _tagLabel.textColor = UIColorFromRGB(0x333333);
- }
- return _tagLabel;
- }
- - (UILabel *)unreadLabel {
- if (!_unreadLabel) {
- _unreadLabel = [[UILabel alloc] init];
- _unreadLabel.textColor = [UIColor whiteColor];
- _unreadLabel.backgroundColor = UIColorFromRGB(0xff676b);
- _unreadLabel.textAlignment = NSTextAlignmentCenter;
- _unreadLabel.font = [UIFont systemFontOfSize:11];
- _unreadLabel.layer.cornerRadius = 8;
- _unreadLabel.clipsToBounds = YES;
- }
- return _unreadLabel;
- }
- - (UILabel *)messageLabel {
- if (!_messageLabel) {
- _messageLabel = [[UILabel alloc] init];
- _messageLabel.font = [UIFont systemFontOfSize:14.0];
- _messageLabel.textColor = UIColorFromRGB(0xcccccc);
- _messageLabel.textAlignment = NSTextAlignmentRight;
- }
- return _messageLabel;
- }
- - (APAvatarImageView *)headView {
- if (!_headView) {
- _headView = [[APAvatarImageView alloc] init];
- _headView.borderColor = [UIColor whiteColor];
- _headView.borderWidth = 0;
- _headView.cornerRadius = 3;
- }
- return _headView;
- }
- #pragma mark - Layout
- - (void)layoutAllComponents {
- WeakSelf(weakSelf);
-
- [self.contentView addSubview:self.iconView];
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.contentView).with.offset(15);
- make.centerY.equalTo(weakSelf.contentView);
- make.size.mas_equalTo(CGSizeMake(35, 35));
- }];
-
- [self.contentView addSubview:self.tagLabel];
- [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.iconView.mas_right).with.offset(6);
- make.centerY.equalTo(weakSelf.contentView);
- make.size.mas_equalTo(CGSizeMake(66, 30));
- }];
-
- [self.contentView addSubview:self.unreadLabel];
- [self.unreadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.iconView.mas_right).with.offset(-8);
- make.top.equalTo(weakSelf.iconView.mas_top).with.offset(-4);
- make.width.mas_greaterThanOrEqualTo(16);
- make.height.mas_equalTo(16);
- }];
-
- [self.contentView addSubview:self.headView];
- [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(weakSelf.contentView).with.offset(-16);
- make.centerY.equalTo(weakSelf.contentView);
- make.size.mas_equalTo(CGSizeMake(32, 32));
- }];
- [self.contentView addSubview:self.messageLabel];
- [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.tagLabel.mas_right).with.offset(10);
- make.right.equalTo(weakSelf.headView.mas_left).with.offset(-10);
- make.centerY.equalTo(weakSelf.contentView);
- make.height.mas_equalTo(30);
- }];
- }
- #pragma mark -
- - (void)setCellType:(SessionListCellType)cellType {
- _cellType = cellType;
- switch (cellType) {
- case SessionListCellTypeDefault: {
- self.messageLabel.hidden = YES;
- self.headView.hidden = YES;
- break;
- }
- case SessionListCellTypeMessage: {
- self.messageLabel.hidden = NO;
- self.headView.hidden = NO;
- break;
- }
- default:
- break;
- }
- }
- - (void)setUnreadNumberString:(NSString *)value {
- if (value.intValue <= 0) {
- self.unreadLabel.hidden = YES;
- } else {
- self.unreadLabel.hidden = NO;
- self.unreadLabel.text = value;
- }
- }
- - (void)setMessageText:(NSString *)text {
- if (!text || text.length == 0) {
- self.messageLabel.hidden = YES;
- } else {
- self.messageLabel.hidden = NO;
- self.messageLabel.text = text;
- }
- }
- @end
|