45.小项目:QQ聊天界面 V部分

---------- CZMessageCell.h ----------

#import <UIKit/UIKit.h>


@class CZMessageFrame;


@interface CZMessageCell : UITableViewCell


@property (strong, nonatomic) CZMessageFrame *messageFrame;


+ (instancetype)cellWithTableView:(UITableView *)tableView;


@end

---------- CZMessageCell.m ----------

#import "CZMessageCell.h"

#import "CZMessage.h"

#import "CZMessageFrame.h"

#import "UIImage+CZHelp.h"


@interface CZMessageCell ()


@property (weak, nonatomic) UILabel *timeLabel;

@property (weak, nonatomic) UIImageView *iconView;

@property (weak, nonatomic) UIButton *textBtn;


@end


@implementation CZMessageCell


+ (instancetype)cellWithTableView:(UITableView *)tableView

{

    static NSString *ID = @"cell";

    CZMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (cell == nil)

    {

        cell = [[CZMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];

    }

    return cell;

}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self)

    {

        UILabel *timeLabel = [[UILabel alloc] init];

        timeLabel.font = CZTimeFont;

        timeLabel.textAlignment = NSTextAlignmentCenter;

        [self.contentView addSubview:timeLabel];

        self.timeLabel = timeLabel;

        UIImageView *iconView = [[UIImageView alloc] init];

        iconView.layer.cornerRadius = 8;

        iconView.clipsToBounds = YES;

        [self.contentView addSubview:iconView];

        self.iconView = iconView;

        UIButton *textBtn = [[UIButton alloc] init];

        textBtn.titleLabel.font = CZTextFont;

        textBtn.titleLabel.numberOfLines = 0;

        [self.contentView addSubview:textBtn];

        self.textBtn = textBtn;

        self.backgroundColor = [UIColor clearColor];

    }

    return self;

}


- (void)setMessageFrame:(CZMessageFrame *)messageFrame

{

    _messageFrame = messageFrame;

    CZMessage *msg = messageFrame.message;

    if (msg.hiddenTime) {

        self.timeLabel.hidden = YES;

    } else {

        self.timeLabel.hidden = NO;

        self.timeLabel.text = msg.time;

        self.timeLabel.frame = messageFrame.timeF;

    }

    self.iconView.image = [UIImage imageNamed:(msg.type == CZMessageTypeMe) ? @"me" : @"other"];

    self.iconView.frame = messageFrame.iconF;

    [self.textBtn setTitle:msg.text forState:UIControlStateNormal];

    self.textBtn.frame = messageFrame.textF;

    NSString *normal, *high;

    if (msg.type == CZMessageTypeOther)

    {

        normal = @"chat_recive_nor";

        high = @"chat_recive_press_pic";

        [self.textBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    } else {

        normal = @"chat_send_nor";

        high = @"chat_send_press_pic";

        [self.textBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    }

    self.textBtn.contentEdgeInsets = UIEdgeInsetsMake(15, 20, 15, 20);

    [self.textBtn setBackgroundImage:[UIImage resizedImageNamed:normal] forState:UIControlStateNormal];

    [self.textBtn setBackgroundImage:[UIImage resizedImageNamed:high] forState:UIControlStateHighlighted];

}


@end

 

转载于:https://www.cnblogs.com/lixiang2015/p/4719811.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值