///  控制层

#import "HMViewController.h"
#import "HMMessageModel.h"
#import "HMMessageCell.h"
#import "HMMessageFrameModel.h"
@interface HMViewController ()<UITableViewDataSource,UITableViewDelegate> @property (nonatomic, strong)NSMutableArray *messages; @end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. } - (NSMutableArray *)messages
{
if (_messages == nil) { NSArray * array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"messages.plist" ofType:nil]]; NSMutableArray *messageArr = [NSMutableArray array];
for (NSDictionary *dict in array) {
HMMessageModel *messga = [HMMessageModel messageWithDict:dict]; HMMessageFrameModel *fm = [[HMMessageFrameModel alloc]init];
fm.message = messga; [messageArr addObject:fm];
} _messages = messageArr;
} return _messages;
}
//隐藏状态栏
- (BOOL)prefersStatusBarHidden
{
return YES;
} #pragma mark tableview数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.messages.count;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
HMMessageFrameModel *model = self.messages[indexPath.row];
return model.cellH;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HMMessageCell *cell = [HMMessageCell messageCellWithTableView:tableView];
HMMessageFrameModel *model = self.messages[indexPath.row]; cell.frameMessage = model; return cell;
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@interface HMViewController : UIViewController

@end

///   model.h

#import <Foundation/Foundation.h>
typedef enum {
HMMessageModelGatsby = ,//Gatsby
HMMessageModelJobs//Jobs
}HMMessageModelType;
@interface HMMessageModel : NSObject //正文
@property (nonatomic, copy)NSString *text; //时间
@property (nonatomic, copy)NSString *time; //发送类型
@property (nonatomic, assign)HMMessageModelType type; - (instancetype)initWithDict:(NSDictionary *)dict; + (instancetype)messageWithDict:(NSDictionary *)dict; @end

*****model.m

#import "HMMessageModel.h"

@implementation HMMessageModel

- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dict];
} return self;
} + (instancetype)messageWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
} @end

******modelframe.h

#import <Foundation/Foundation.h>
@class HMMessageModel;
@interface HMMessageFrameModel : NSObject //时间的frame
@property (nonatomic, assign,readonly)CGRect timeF; //正文的frame
@property (nonatomic, assign,readonly)CGRect textViewF; //图片
@property (nonatomic, assign,readonly)CGRect iconF; //cell
@property (nonatomic, assign,readonly)CGFloat cellH; //数据模型
@property (nonatomic, strong)HMMessageModel *message;
@end

******modelframe.m

#import "HMMessageFrameModel.h"
#import "Constant.h"
#import "HMMessageModel.h"
@implementation HMMessageFrameModel - (void)setMessage:(HMMessageModel *)message
{
_message = message; CGFloat padding = ;
//1. 时间
CGFloat timeX = ;
CGFloat timeY = ;
CGFloat timeW = bScreenWidth;
CGFloat timeH = bNormalH; _timeF = CGRectMake(timeX, timeY, timeW, timeH); //2.头像
CGFloat iconX;
CGFloat iconY = CGRectGetMaxY(_timeF);
CGFloat iconW = bIconW;
CGFloat iconH = bIconH; if (message.type == HMMessageModelGatsby) {//自己发的 iconX = bScreenWidth - iconW - padding; }else{//别人发的
iconX = padding;
} _iconF = CGRectMake(iconX, iconY, iconW, iconH);
//3.正文 CGFloat textX;
CGFloat textY = iconY; CGSize textMaxSize = CGSizeMake(, MAXFLOAT);
CGSize textRealSize = [message.text boundingRectWithSize:textMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:bBtnFont} context:nil].size; if (message.type == HMMessageModelGatsby) {
textX = bScreenWidth - iconW - padding - textMaxSize.width;
}else{
textX = padding + iconW;
} // _textViewF = CGRectMake(textX, textY, <#CGFloat width#>, <#CGFloat height#>)
_textViewF = (CGRect){{textX,textY},textRealSize}; //4.cell高度 CGFloat iconMaxY = CGRectGetMaxY(_iconF);
CGFloat textMaxY = CGRectGetMaxY(_textViewF); _cellH = MAX(iconMaxY, textMaxY); } @end

////****cell.h

#import <UIKit/UIKit.h>
@class HMMessageFrameModel;
@interface HMMessageCell : UITableViewCell + (instancetype)messageCellWithTableView:(UITableView *)tableview; //frame 的模型
@property (nonatomic, strong)HMMessageFrameModel *frameMessage; @end

////****cell.m

#import "HMMessageCell.h"
#import "HMMessageFrameModel.h"
#import "HMMessageModel.h"
#import "Constant.h"
@interface HMMessageCell()
//时间
@property (nonatomic, weak)UILabel *time;
//正文
@property (nonatomic, weak)UIButton *textView;
//用户头像
@property (nonatomic, weak)UIImageView *icon; @end @implementation HMMessageCell
+ (instancetype)messageCellWithTableView:(UITableView *)tableview
{
static NSString *ID = @"messageCell";
HMMessageCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
} return cell;
}
// 初始化控件
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//1.时间
UILabel *time = [[UILabel alloc]init];
time.textAlignment = NSTextAlignmentCenter;
time.font = [UIFont systemFontOfSize:13.0f];
[self.contentView addSubview:time];
self.time = time; //1.正文
UIButton *textView = [[UIButton alloc]init];
textView.backgroundColor = [UIColor grayColor];
textView.titleLabel.font = bBtnFont;
textView.titleLabel.numberOfLines = ;//自动换行
[self.contentView addSubview:textView];
self.textView = textView; //1.头像
UIImageView *icon = [[UIImageView alloc]init];
[self.contentView addSubview:icon];
self.icon = icon; }
return self;
}
// 设置位置和值
- (void)setFrameMessage:(HMMessageFrameModel *)frameMessage
{
_frameMessage = frameMessage; HMMessageModel *model = frameMessage.message; //1.时间
self.time.frame = frameMessage.timeF;
self.time.text = model.time; //2.头像
self.icon.frame = frameMessage.iconF;
if (model.type == HMMessageModelGatsby) {
self.icon.image = [UIImage imageNamed:@"Gatsby"];
}else{
self.icon.image = [UIImage imageNamed:@"Jobs"];
} //3.正文
self.textView.frame = frameMessage.textViewF;
[self.textView setTitle:model.text forState:UIControlStateNormal]; }
@end

IOS第九天(1:QQ聊天界面frame模型)的更多相关文章

  1. IOS第九天(2:QQ聊天界面键盘优化 和自动回复)

    ***********controller.m #import "HMViewController.h" #import "HMMessageModel.h" ...

  2. IOS第九天(3:QQ聊天界面通知的使用)

    #import <Foundation/Foundation.h> #import "Person.h" #import "XQCompany.h" ...

  3. QQ聊天界面的布局和设计(IOS篇)-第二季

    QQChat Layout - 第二季 本来第二季是快写好了, 也花了点功夫, 结果gitbook出了点问题, 给没掉了.有些细节可能会一带而过, 如有疑问, 相互交流进步~. 在第一季中我们完成了Q ...

  4. QQ聊天界面的布局和设计(IOS篇)-第一季

    我写的源文件整个工程会再第二季中发上来~,存在百度网盘, 感兴趣的童鞋, 可以关注我的博客更新,到时自己去下载~.喵~~~ QQChat Layout - 第一季 一.准备工作 1.将假数据messa ...

  5. Objective-c——UI基础开发第八天(QQ聊天界面)

    一.知识点: QQ聊天界面 双模型的使用(dataModel和frameModel) UITextField的使用 通知的使用 拉伸图片的两种方法(slicing/image对象的resizeable ...

  6. IOS开发学习笔记043-QQ聊天界面实现

    QQ聊天界面实现 效果如下: 实现过程: 1.首先实现基本界面 头像使用 UIImageView : 文字消息使用 UIButton 标签使用 UILable :水平居中 所有元素在一个cell中,在 ...

  7. 高仿qq聊天界面

    高仿qq聊天界面,给有需要的人,界面效果如下: 真心觉得做界面非常痛苦,给有需要的朋友. chat.xml <?xml version="1.0" encoding=&quo ...

  8. 在WEB项目中调用QQ通讯组件打开QQ聊天界面

    在很多WEB项目中,需要提供在线服务的功能,加上自己的联系方式,例如:QQ,不用添加QQ好友也可以交谈,那这到底是怎么实现的呢? 对于这个功能,需要提到一个组件,即“QQ通讯组件”.QQ通讯组件是一种 ...

  9. Android 内部启动其他应用,以及打开指定qq聊天界面

    在自己应用中打开第三方应用,有好多种方法,这里举例一种: //以打开微信为例,前提需要知道打开应用的包名,一般一个发布版本的应用,包名不会轻易改变的,但是,打开QQ就要注意了,毕竟QQ的发布版本有不下 ...

随机推荐

  1. XSS 跨站脚本攻击之构造剖析(一)

    1.XSS-Filter:跨站脚本过滤器,用于分析用户提交的输入,并消除潜在的跨站脚本攻击 (1)XSS Filter实际上是一段精心编写的过滤函数作用是过滤XSS跨站脚本代码: (2)绕过XSS F ...

  2. DSP using MATLAB示例 Example3.5

    代码: n = [0:10]; x = (0.9*exp(j*pi/3)).^n; % x(n) = k = -200:200; w = (pi/100)*k; % [0,pi] axis divid ...

  3. DOM--6 向应用程序中加入ajax

    组合技术 适当的ajax时对已有技术和下列思想的组合 语义化(X)HTML标记 文档对象模型(DOM) JavaScript XML 不同浏览器中,公共XMLHttpRequest方法 open(me ...

  4. [工作中的设计模式]观察者模式observer

    一.模式解析 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 观察者模式又叫订阅发布模式, ...

  5. js渐隐渐入渐出效果 fadeOut fadeIn

    //fadeOut //function start function fadeOut(ele,speed){ var ele=document.getElementById(ele); var op ...

  6. 转:delphi异常捕获try except语句 和 try finally语句用法

    转:http://www.java123.net/v/936977.html      2015-06-24 09:27:48 一直写程序都没管他们,也尽量很少用,今天终于想把他给弄个明白,在网上找来 ...

  7. 【CLR in c#】属性

    1.无参属性 1.为什么有字段还需要属性呢? 因为字段很容易写出不恰当的代码,破坏对象的状态,比如Age=-1.人的年纪不可能为负数.使用属性后你可以缓存某些值或者推迟创建一些内部对象,你可以以线程安 ...

  8. Problem to create "New Database Diagram" in Microsoft SQL Server Management Studio for SQL Server 2012

    Error: when click "New Database Diagram", a error popped up and said "Attempted to re ...

  9. iOS之07-三大特性之多态 + NSString类

    多态 1.没有继承就没有多态 2.代码体现:父类类型的指针指向子类对象 类的创建: #import <Foundation/Foundation.h> // 动物 @interface A ...

  10. <fieldset>

    legend{text-align:center;} <fieldset> <legend>爱好<legend>(为fieldset定义标题) <input ...