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 项目准备 ...
随机推荐
- Java Web应用的开发模式
一.概述 从互联网诞生的第一天起,web从一个简单的静态页面,发展到今天五花八门.令人眼花缭乱的复杂应用,大到企业级的web应用系统,小到简单的SPA管理系统.在硬件性能提升的同时,通过各种技术实现了 ...
- 需要知道的开源的框架-IOS
1:SDWebImage,UIImageView+WebCache加载一张图片. 2:UIViewExt用于定位坐标很有用,可以直接拿到bottom,top,left,right. 转:http:// ...
- POJ 2075 Tangled in Cables (c++/java)
http://poj.org/problem?id=2075 题目大意: 给你一些人名,然后给你n条连接这些人名所拥有的房子的路,求用最小的代价求连接这些房子的花费是否满足要求. 思路: 昨天20分钟 ...
- Linux下一个Redis启动/关闭/重新启动服务脚本
脚本功能: 实现redis单机多实例情况下的正常启动.关闭.重新启动单个redis实例.完毕系统标准服务的下面经常使用功能: start|stop|status|restart 注:redis程序代 ...
- 18、MySQL内存体系架构及参数总结
内存结构: Mysql 内存分配规则是:用多少给多少,最高到配置的值,不是立即分配 图只做大概参考 全局缓存包括: global buffer(全局内存分配总和) = innodb_buffer ...
- 在Qt中使用sleep
关于sleep函数,我们先来看一下他的作用:sleep函数是使调用sleep函数的线程休眠,线程主动放弃时间片.当经过指定的时间间隔后,再启动线程,继续执行代码.sleep函数并不能起到定时的作用 ...
- 根据IP地址获取IP的详细信息
<?php header('Content-Type:text/html; charset=utf-8'); function ip_data() { $ip = GetIP(); $url = ...
- [转] linux之sed用法
sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为: sed ...
- 9.14noip模拟试题
中文题目名称 祖孙询问 比赛 数字 英文题目名称 tree mat num 可执行文件名 tree mat num 输入文件名 tree.in mat.in num.in 输出文件名 tree.out ...
- 【开源java游戏框架libgdx专题】-07-文件处理
介绍:文件处理在不同平台的文件管理是略有差异的 Desktop(Windows,Linux,Mac OS X等等):在桌面系统中,文件系统是一个大块的内存.文件可以通过当前的工作目录或者绝对路径被引用 ...