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 项目准备 ...
随机推荐
- Web前端之HTML
一. HTML介绍: 1.HTML:超文本标记语言. 2.HTML是由:标签和内容构成. 3.程序语言有两种:解释性语言(HTML.PHP.Python.Javascript)和编译型语言(C.C++ ...
- POJ 1686 Lazy Math Instructor (模似题+栈的运用) 各种坑
Problem Description A math instructor is too lazy to grade a question in the exam papers in which st ...
- Cocos2d-X学习——Android移植,使用第三方库.so被删掉问题
2014-05-26 导语:Cocos2dx在安卓上移植的时候,增加第三方库,却发现新加的so库被删掉了. 正文: 1.我的环境: cocos2d-x 2.2.3, ndk-r9 2.网上找了非常多, ...
- [c#]如何在form的webbrowser控件中获得鼠标坐标
如图这样,其实是要插入一个time的控件,这样才能使得坐标值会根据鼠标的移动而不停变化.time插件中写private void timer1_Tick(object sender, EventArg ...
- Android(java)学习笔记222:开发一个多界面的应用程序之不同界面间互相传递数据(短信助手案例的优化:请求码和结果码)
1.开启界面获取返回值 (1)采用一种特殊的方式开启Activity: startActivityForResult(intent , 0): (2)在被开启的Activi ...
- android基础篇学习心得
android技术中,线程.进程.JNI.IPC和各个小框架结构是基本功.在跟随高焕堂老师的android程序猿到架构师之路系列视频中 学习完基础篇之后,颇有些心得,记录下来. android开发就是 ...
- 【IOS】 XML解析和xml转plist文件(GDataXML)
iOS对于XML的解析有系统自带的SDK--NSXMLParser,鄙人愚拙,只会用GDataXML进行解析,这里仅介绍GData的使用.(以下图为例) 1.对于一个xml文件,先读取出来 NSDat ...
- Another app is currently holding the yum lock; waiting for it to exit... 怎么解决
Another app is currently holding the yum lock; waiting for it to exit... 怎么解决 这个问题说明你的程序yum程序正在运行,必须 ...
- Linux read/write fread/fwrite两者区别
Linux read/write fread/fwrite两者区别 1,fread是带缓冲的,read不带缓冲. 2,fopen是标准c里定义的,open是POSIX中定义的. 3,fread可以读一 ...
- SpringMVC10数据验证
/** * @NotBlank 作用在String * @NotEmpty 作用在集合上 * @NotNull 作用在基本数据类型上 * */ public class User { @NotNull ...