首页 > 其他 > 详细

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

时间:2015-08-11 07:14:09      阅读:226      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!