ChatCell
import UIKit
let chatCellHeight: CGFloat = 72
let chatCellInsetLeft = chatCellHeight + 8
class ChatCell:UITableViewCell {
let userPictureImageView:UIImageView
let userNameLabel:UILabel
let lastMessageTextLabel:UILabel
let lastMessageSentDateLable:UILabel
let userNameInitialsLabel:UILabel
override init(style:UITableViewCellStyle, reuseIdentifier:String?) {
let pictureSize:CGFloat = 64
userPictureImageView = UIImageView(frame:CGRect(x:8,y:(chatCellHeight-pictureSize)/2,width:pictureSize,height:pictureSize))
userPictureImageView.backgroundColor = UIColor(red:199/255.0,green:199/255.0,blue:204/255.0,alpha:1)
userPictureImageView.layer.cornerRadius = pictureSize/2
userPictureImageView.layer.masksToBounds = true//将位于它之下的层
userNameLabel = UILabel(frame:CGRectZero)
userNameLabel.backgroundColor = UIColor.whiteColor
userNameLabel.font = UIFont.systemFontOfSize(17)
lastMessageTextLabel = UILabel(frame:CGRectZero)
lastMessageTextLabel.backgroundColor = UIColor.whiteColor()
lastMessageTextLabel.font = UIFont.systemFontOfSize(15)
lastMessageTextLabel.numberOfLines= 2
lastMessageTextLabel.textColor = UIColor(red:142/255,green:142/255,blue:147/255,alpha:1)
lastMessageSentDateLabel = UILabel(frame:CGRectZero)
lastMessageSentDateLabel.autoresizingMask = .FlexibleLeftMargin
lastMessageSentDateLabel.backgroundColor = UIColor.whiteColor()
lastMessageSentDateLabel.font = UIFont.systemFontOfSize(15)
lastMessageSentDateLabel.textColor = lastMessageTextLabel.textColor
userNameInitialsLabel = UILabel(frame:CGRectZero)
userNameInitialsLabel.font = UIFont.systemFontOfSize(33)
userNameInitialsLabel.textAlignment = .Center
userNameInitialsLabel.textColor = UIColor.whiteColor()
super.init(style:style, reuseIdentifier:reuseIdentifier)
contentView.addSubView(userPictureImageView)
contentView.addSubView(userNameLabel)
contentView.addSubView(lastMessageTextLabel)
contentView.addSubView(lastMessageSentDataLabel)
userPictureImageView.addSubview(userNameInitialsLabel)
userNameLabel.setTranslateAutoresizingMaskIntoConstraints(false)
contentView.addConstraint(NSLayoutConstraint(item:userNameLabel,attribute:.Left,.Equal, toItem:contentView,attribute:.Left,multipler:1,constant:chatCellInsetLeft))
contentView.addConstraint(NSlayoutContrstraint(item: userNameLabel,attribute:.Top,
relatedBy:.Equal,toItem:contentView,attribute:.Top,multiplier:1,constant:6))
lastMessageTextLabel.setTranslatesAutoresizingMaskIntoConstraints(true)
super.init(style:style, reuseIdentifier:reuseIdentifier)
contentView.
lastMessageTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
contentView.addConstraint(NSLayoutConstraint(item:lastMessageTextLabel,attribute:.Left,relatedBy:.Equal,toItem:userNameLabel,attribute:.Left,mltipllier:1,constrant:0))
contentView.addConstraint(NSLayoutConstraint(item:lastMessageTextLabel,attribute:.Top,relatedBy:.Equal,toItem:contentView.,attribute:.Top,multiplier:1,constant:28))
contentView.addConstraint(NSLayoutConstraint(item:lastMessageTextLabel,attribute:.right,relatedBy:.Equal,toItem:contentView,attribute:.Right,multiplier:1,constant:-7))
contentView.addConstraint(NSLayoutConstraint(item:lastMessageTextLabel,attribute:.Bottom,relatedBy:.LessThanOrEquqal,toItem:contentView,attribute:.Bottom,multiplier:1,constant:-4))
lastMessageSentDateLabel.setTranslateAutoresizingMaskIntoConstrains(false)
contentView.addConstraint(NSLayoutConstraint(item:lastMessageSentDateLabel,attribute:.Left,elatedBy:.Equal,toItem:userNameLable,attribute:.Right,multiplierL1,constant:2))
contentView.addConstraint(NSLayoutConstraint(item:lastMessageSentDateLabel,attribute:.Right,relatedBy:.Equal,toItem:contentView,attribute:.Right,multipliter:1,constant:-7))
contentView.addConstraint(NSlabyoutConstraint(item:lastMessageSentDateLabel,attribute:.Baseline,relaedBy:.Equal,toItem:userNameLable,attrubute:.Baseline,multiplier:1,constant:0))
userNameInitialsLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
userPictureImageView.addConstraint(NSLayoutConstraint(item:userNameInitialsLabel,attribute:.CenterX,relatedBy:.Equal,toItem:userPictureImageView,attribute:.CenterX,multiplier:1,constant:0))
userPictureImageView.addConstraint(NSLayoutConstraint(item:userNameInitialsLabel,attribue:.CenterY,relatedBy:.Equal,toItem:userPictureImageView,attribute:.CenterY,multiplier:1,constant:-1))
}
required init(coder aDecoder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configureWithChat(chat:Chat) {
let user = chat.user
userPictureImageView.image = UIImage(named:user.pictureName())
if userPictureImageView.image == nil {
let initials = user.initials
if initials != nil {
userNameInitialsLabel.text = initials
userNameInitialsLabel.hidden = false
} else {
userPictureImageView.image = UIImage(named:"User0")
userNameInitialsLabel.hidden = true
}
} else {
userNameInitialsLabel.hidden = true
}
userNameLabel.text = user.name
lastMessageTextLabel.text = chat.lastMessageText
lastMessageSentDateLabel.text = chat.lastMessageSentDateString
}
}
ChatCell的更多相关文章
- 即时通讯UI-聊天界面(UITableView显示左右两人聊天)
目录 1.创建UITableView对象并设置相关属性 2.创建cellModel模型 //枚举类型 typedef enum { ChatMessageFrom = ,//来自对方的消息 ChatM ...
- Swift 2.0 : 'enumerate' is unavailable: call the 'enumerate()' method on the sequence
Swift 2.0 : 'enumerate' is unavailable: call the 'enumerate()' method on the sequence 如下代码: for (ind ...
- XMPP即时通讯(代码实现)
1.配置XMPP(XMPPConfig.m) 2.配置XMPPFramework框架 3.创建单例类(XMPPManager.h/XMPPManager.m)管理器 XMPPManager.m: #i ...
- UI进阶 即时通讯之XMPP好友列表、添加好友、获取会话内容、简单聊天
这篇博客的代码是直接在上篇博客的基础上增加的,先给出部分代码,最后会给出能实现简单功能的完整代码. UI进阶 即时通讯之XMPP登录.注册 1.好友列表 初始化好友花名册 #pragma mark - ...
- iOS中 蓝牙2.0详解/ios蓝牙设备详解 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博 整体布局如下: 程序结构如右图: 每日更新关注:http://weibo.com/hanjunqiang ...
- IOS XMPP总结
//前言:仿weixin实现一个即时通讯的案例,支持版本7.0以上 "准备工作 创建项目时使用git" /* 显示隐藏文件,看到git的文件夹 defaults write com ...
- iOS 聊天界面
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- iOS实现XMPP通讯(二)XMPP编程
项目概述 这是一个可以登录jabber账号,获取好友列表,并且能与好友进行聊天的项目. 使用的是第三方库XMPPFramework框架来实现XMPP通讯. 项目地址:XMPP-Project 项目准备 ...
随机推荐
- 命令行修复MBR分区
命令行修复MBR 1.shift+F10打开命令行 2.输入:diskpart 3.输入:list disk 查看磁盘信息 4.选择你要操作的磁盘:select disk 0 5.输入:clean,清 ...
- 【下载分】C语言for循环语句PK自我活动
想了解自己C语言for语句的掌握程度吗?敢和自己PK较量一番吗?參加"C语言for循环语句PK自我活动",仅仅要成绩70分以上.就可赢得CSDN下载分. 12道题目题库动态读取,每 ...
- Meth | phpstorm 2016.2 的最新破解方法(截止2016-8-1)
今天刚更新了phpstorm 2016.2版本,发现网上提供的破解地址都有问题,即*.lanyus.com及*.qinxi1992.cn下的全部授权服务器已遭JetBrains封杀. 最后网上找到一个 ...
- jboss7 Java API for RESTful Web Services (JAX-RS) 官方文档
原文:https://docs.jboss.org/author/display/AS7/Java+API+for+RESTful+Web+Services+(JAX-RS) Content Tuto ...
- HeaderViewListAdapter
该类其实就是普通使用的Adapter的一个包装类,就是为了添加header和footer而定义的.该类一般不直接使用,当ListView有header和footer时,ListView中会自动把Ada ...
- python与数值计算环境搭建
数值计算的编程的软件很多种,也见过一些编程绘图软件的对比. 利用Python进行数值计算,需要用到numpy(矩阵) ,scipy(公式符号), matplotlib(绘图)这些工具包. 1.Linu ...
- 使用WebUploader使用,及使用后测试横拍或竖拍图片图片方向不对等解决方案
WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...
- 全文索引--自定义chinese_lexer词典
全文索引它的数据字典本来就是自己加密过的数据格式,只有翻译过来了,才可以修改.这样修改后再生成它自己的数据格式文件,覆盖掉原来的,就会将新添加的关键词加入进去了!! 以下操作是在Oracle服务器安装 ...
- 【转】NSString / NSData / char* 类型之间的转换
原文 :http://www.cnblogs.com/pengyingh/articles/2341880.html NSString 转换成NSData 对象 NSData* xmlData = [ ...
- Objective-C 类,函数调用
// // main.m // L02HelloObjC // // Created by JinXin on 15/11/25. // Copyright © 2015年 JinXin. All r ...