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

44.小项目:QQ聊天界面 M部分

时间:2015-08-11 07:18:37      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

---------- CZMessage.h ----------

#import <Foundation/Foundation.h>


typedef enum

{

    CZMessageTypeMe = 0,

    CZMessageTypeOther

}CZMessageType;


@interface CZMessage : NSObject


@property (copy, nonatomic) NSString *text;

@property (copy, nonatomic) NSString *time;

@property (assign, nonatomic) CZMessageType type;



@property (assign, nonatomic) BOOL hiddenTime;


+ (instancetype)messageWithDict:(NSDictionary *)dict;

- (instancetype)initWithDict:(NSDictionary *)dict;


@end

---------- CZMessage.m ----------

#import "CZMessage.h"


@implementation CZMessage


+ (instancetype)messageWithDict:(NSDictionary *)dict

{

    return [[self alloc] initWithDict:dict];

}


- (instancetype)initWithDict:(NSDictionary *)dict

{

    if (self = [super init])

    {

        [self setValuesForKeysWithDictionary:dict];

    }

    return self;

}


@end

---------- CZMessageFrame.h ----------

#define CZTimeFont [UIFont systemFontOfSize:13]

#define CZTextFont [UIFont systemFontOfSize:15]


#import <UIKit/UIKit.h>


@class CZMessage;


@interface CZMessageFrame : NSObject

@property (strong, nonatomic) CZMessage *message;

@property (assign, nonatomic, readonly) CGRect timeF;

@property (assign, nonatomic, readonly) CGRect iconF;

@property (assign, nonatomic, readonly) CGRect textF;

@property (assign, nonatomic, readonly) CGFloat cellHeight;


@end 

---------- CZMessageFrame.m ---------- 

#import "CZMessageFrame.h"

#import "CZMessage.h"


#define CZMargin 10

#define CZIconW 40

#define CZIconH 40


@implementation CZMessageFrame


- (void)setMessage:(CZMessage *)message

{

    _message = message;

    if (message.hiddenTime == NO)

    {

        CGFloat timeW = [UIScreen mainScreen].bounds.size.width;

        CGFloat timeH = 35;

        _timeF = CGRectMake(0, 0, timeW, timeH);

    }

    CGFloat iconX;

    CGFloat iconY = CGRectGetMaxY(_timeF) + CZMargin;

    CGFloat textY = iconY;

    CGFloat textX;

    CGFloat textMaxW = 150;

    NSDictionary *attrs = @{ NSFontAttributeName : CZTextFont };

    CGSize textSize = [message.text boundingRectWithSize:CGSizeMake(textMaxW, MAXFLOAT) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;

    CGFloat textW = textSize.width + 40;

    CGFloat textH = textSize.height + 30;

    if (message.type == CZMessageTypeOther) {

        iconX = CZMargin;

        textX = iconX + CZIconW + CZMargin;

    } else {

        iconX = [UIScreen mainScreen].bounds.size.width - CZMargin - CZIconW;

        textX = iconX - CZMargin - textW;

    }

    _iconF = CGRectMake(iconX, iconY, CZIconW, CZIconH);

    _textF = CGRectMake(textX, textY, textW, textH);

    CGFloat maxH = MAX(CGRectGetMaxY(_iconF), CGRectGetMaxY(_textF));

    _cellHeight = maxH + CZMargin;

}


@end

 

44.小项目:QQ聊天界面 M部分

标签:

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

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