码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-11 07:16:05      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

---------- 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

 

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

标签:

原文地址:http://www.cnblogs.com/lixiang2015/p/4719811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!