如何在自定义的tableview 自定义cellCell上实现类似微信的新消息提示

ios仿微信的demo - 走在左边 - ITeye技术网站
博客分类:
10月19日闲的蛋疼,做了个
仿微信的聊天工具
git地址:
ui参考的网上例子/news/520.html
服务端用 tomcat7的websocket
客户端
1.可以用浏览器
2.sockroket的ios客户端,ios8,开发工具xcode6
ios客户端代码如下代码:
ViewController.m
ViewController.m
BubbleDemo
Created by xiao7 on 14/10/19.
Copyright (c) 2014年 killinux. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
NSString *websocket_url = @"ws://192.168.0.102:8080/webs/websocket/test";
NSString *myName = @"haoning";
NSString *toName = @"all";
- (void)viewDidLoad {
[super viewDidLoad];
//----init data---begin----
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"weixin",@"name",@"这是一个测试",@"content", nil];
NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"haoning",@"name",@"hello",@"content", nil];
NSDictionary *dict7 = [NSDictionary dictionaryWithObjectsAndKeys:@"weixin",@"name",@",长数据测试。",@"content", nil];
_resultArray = [NSMutableArray arrayWithObjects:dict,dict1, nil];
[_resultArray addObject:dict7];
_resultArray = [[NSMutableArray alloc] init];
//----init data---end----
//websocket---begin---
_mywebSocket.delegate =
[_mywebSocket close];
_mywebSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:websocket_url]]];
_mywebSocket.delegate =
[_mywebSocket open];
NSLog(@"open success!");
//websocket---end----
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
//pragma websocket
- (void)webSocketDidOpen:(SRWebSocket *)webS
NSLog(@"Websocket Connected");
self.title = @"Connected!";
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)
NSLog(@":( Websocket Failed With Error %@", error);
_mywebSocket =
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)
NSLog(@"websocket Received \"%@\"", message);
NSArray *messageArray = [message componentsSeparatedByString:@","];
if(messageArray.count&3){
NSLog(@"error parameter not right:%@",message);
NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:@"haoning",@"name",message,@"content", nil];
[_resultArray addObject:dict8];
NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:messageArray[0],@"name",messageArray[2],@"content", nil];
[_resultArray addObject:dict8];
[tableViewList reloadData];
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasC
NSLog(@"WebSocket closed");
self.title = @"Connection Closed! (see logs)";
_mywebSocket =
//发送消息
- (IBAction)sendBubbleMessage:(id)sender {
NSString *thistext = messageTxt.
NSLog(@"sendBubbleMessage:%@",thistext);
NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:@"haoning",@"name",thistext,@"content", nil];
[_resultArray addObject:dict8];
[tableViewList reloadData];
NSString *sendMessage =[myName stringByAppendingFormat:@",%@,%@",toName,thistext];
[_mywebSocket send:sendMessage];
messageTxt.text=
//泡泡文本
- (UIView *)bubbleView:(NSString *)text from:(BOOL)fromSelf withPosition:(int)position{
//计算大小
UIFont *font = [UIFont systemFontOfSize:14];
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(180.0f, 20000.0f) lineBreakMode:NSLineBreakByWordWrapping];
// build single chat bubble cell with given text
UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero];
returnView.backgroundColor = [UIColor clearColor];
//背影图片
UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fromSelf?@"SenderAppNodeBkg_HL":@"ReceiverTextNodeBkg" ofType:@"png"]];
UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:[bubble stretchableImageWithLeftCapWidth:floorf(bubble.size.width/2) topCapHeight:floorf(bubble.size.height/2)]];
//NSLog(@"%f,%f",size.width,size.height);
UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(fromSelf?15.0f:22.0f, 20.0f, size.width+10, size.height+10)];
bubbleText.backgroundColor = [UIColor clearColor];
bubbleText.font =
bubbleText.numberOfLines = 0;
bubbleText.lineBreakMode = NSLineBreakByWordW
bubbleText.text =
bubbleImageView.frame = CGRectMake(0.0f, 14.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+20.0f);
if(fromSelf)
returnView.frame = CGRectMake(320-position-(bubbleText.frame.size.width+30.0f), 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
returnView.frame = CGRectMake(position, 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
[returnView addSubview:bubbleImageView];
[returnView addSubview:bubbleText];
return returnV
//泡泡语音
- (UIView *)yuyinView:(NSInteger)logntime from:(BOOL)fromSelf withIndexRow:(NSInteger)indexRow
withPosition:(int)position{
//根据语音长度
int yuyinwidth = 66+fromS
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = indexR
if(fromSelf)
button.frame =CGRectMake(320-position-yuyinwidth, 10, yuyinwidth, 54);
button.frame =CGRectMake(position, 10, yuyinwidth, 54);
//image偏移量
UIEdgeInsets imageI
imageInsert.top = -10;
imageInsert.left = fromSelf?button.frame.size.width/3:-button.frame.size.width/3;
button.imageEdgeInsets = imageI
[button setImage:[UIImage imageNamed:fromSelf?@"SenderVoiceNodePlaying":@"ReceiverVoiceNodePlaying"] forState:UIControlStateNormal];
UIImage *backgroundImage = [UIImage imageNamed:fromSelf?@"SenderVoiceNodeDownloading":@"ReceiverVoiceNodeDownloading"];
backgroundImage = [backgroundImage stretchableImageWithLeftCapWidth:20 topCapHeight:0];
[button setBackgroundImage:backgroundImage forState:UIControlStateNormal];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(fromSelf?-30:button.frame.size.width, 0, 30, button.frame.size.height)];
label.text = [NSString stringWithFormat:@"%d''",logntime];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.textAlignment = NSTextAlignmentC
label.backgroundColor = [UIColor clearColor];
[button addSubview:label];
#pragma UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return _resultArray.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
NSDictionary *dict = [_resultArray objectAtIndex:indexPath.row];
UIFont *font = [UIFont systemFontOfSize:14];
CGSize size = [[dict objectForKey:@"content"] sizeWithFont:font constrainedToSize:CGSizeMake(180.0f, 20000.0f) lineBreakMode:NSLineBreakByWordWrapping];
return size.height+44;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleN
for (UIView *cellView in cell.subviews){
[cellView removeFromSuperview];
NSDictionary *dict = [_resultArray objectAtIndex:indexPath.row];
//创建头像
UIImageView *
if ([[dict objectForKey:@"name"]isEqualToString:@"haoning"]) {
photo = [[UIImageView alloc]initWithFrame:CGRectMake(320-60, 10, 50, 50)];
[cell addSubview:photo];
photo.image = [UIImage imageNamed:@"photo1"];
if ([[dict objectForKey:@"content"] isEqualToString:@"0"]) {
[cell addSubview:[self yuyinView:1 from:YES withIndexRow:indexPath.row withPosition:65]];
[cell addSubview:[self bubbleView:[dict objectForKey:@"content"] from:YES withPosition:65]];
photo = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
[cell addSubview:photo];
photo.image = [UIImage imageNamed:@"photo"];
if ([[dict objectForKey:@"content"] isEqualToString:@"0"]) {
[cell addSubview:[self yuyinView:1 from:NO withIndexRow:indexPath.row withPosition:65]];
[cell addSubview:[self bubbleView:[dict objectForKey:@"content"] from:NO withPosition:65]];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
ViewController.h
ViewController.h
BubbleDemo
Created by xiao7 on 14/10/19.
Copyright (c) 2014年 killinux. All rights reserved.
#import &UIKit/UIKit.h&
#import "SocketRocket/SRWebSocket.h"
@interface ViewController : UIViewController&SRWebSocketDelegate&
IBOutlet UITableView *tableViewL
IBOutlet UITextField *messageT
@property (nonatomic, strong) NSMutableArray *resultA
@property (nonatomic, strong) SRWebSocket *mywebS
演示
chrome上
ios8系统上
html的客户端
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=utf-8"&
&title&Insert title here&/title&
&script type="text/javascript"&
String.prototype.startWith=function(s){
if(s==null||s==""||this.length==0||s.length&this.length)
if(this.substr(0,s.length)==s)
Date.prototype.format = function(format) {
"M+" : this.getMonth() + 1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
"S" : this.getMilliseconds()
if (/(y+)/.test(format))
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
for ( var k in o)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
function log(text) {
/* document.getElementById("log").innerHTML = (new Date).getTime() + ": "
+ text + "&br&" + document.getElementById("log").innerHTML; */
document.getElementById("log").innerHTML = new Date().format('yyyy-MM-dd hh:mm:ss') + ","
+ text + "&br&" + document.getElementById("log").innerHTML;
function enterSend(){
if(event.keyCode == 13){
document.getElementById("sendbtn").click();
function startServer() {
var url = document.getElementById("serverip").// "ws://192.168.0.102:8887";
if ('WebSocket' in window) {
ws = new WebSocket(url);
} else if ('MozWebSocket' in window) {
ws = new MozWebSocket(url);
log('浏览器不支持');
ws.onopen = function() {
log('唷嘻,连上了');
// 收到服务器发送的文本消息, event.data表示文本内容
ws.onmessage = function(event) {
var thisdata = event.
if(thisdata.startWith("open")){
//alert(thisdata);
document.getElementById("username").value=thisdata.split(" ")[1];
//log(event.data);
var showData=event.data.split(",");
log(showData[0]+"说:"+showData[2]);
ws.onclose = function() {
log('Closed! 刷新页面尝试连接.');
//document.getElementById("conbtn").disabled = "true";
//document.getElementById("stopbtn").removeAttribute('disabled');
function sendMessage() {
var textMessage = document.getElementById("textMessage").
var username = document.getElementById("username").
var toUser = "";
if (ws != null && textMessage != "") {
ws.send(username+","+toUser+","+textMessage);
document.getElementById("textMessage").value="";
function stopconn() {
ws.close();
//document.getElementById("conbtn").removeAttribute('disabled');
//document.getElementById("stopbtn").disabled = "true";
&body onload="startServer()"&
&input id="serverip" type="text" size="20"
value="ws://192.168.0.102:8080/webs/websocket/test" /&
&!-- ws://192.168.0.102:.155.153 --&
&!-- &input id="conbtn" type="button" onclick="startServer()" value="open" /&
&input id="stopbtn" type="button" onclick="stopconn()" value="stop" disabled="disabled"/& --&
您的名字:&input id="username" type="text"
/&&/br&&/br&
&input id="textMessage" type="text" size="20" onkeydown="enterSend()"
style="border:1;width:400px"
&input id="sendbtn" type="button" onclick="sendMessage()" value="Send"&
&div id="log"&&/div&
java的tomcat7的后台:
package com.
import java.io.DataInputS
import java.io.IOE
import java.io.PrintW
import java.net.S
import java.net.UnknownHostE
import java.nio.ByteB
import java.nio.CharB
import java.util.ArrayL
import java.util.HashM
import java.util.M
import java.util.R
import javax.servlet.http.HttpServletR
import org.apache.catalina.websocket.MessageI
import org.apache.catalina.websocket.StreamI
import org.apache.catalina.websocket.WebSocketS
import org.apache.catalina.websocket.WsO
public class HelloWorldWebSocketServlet extends WebSocketServlet {
public static Map&String,MyMessageInbound& mmiList
= new HashMap&String,MyMessageInbound&();
protected StreamInbound createWebSocketInbound(String subProtocol,
HttpServletRequest arg1) {
return new MyMessageInbound();
public int getUserCount(){
return mmiList.size();
private class MyMessageInbound extends MessageInbound {
public void onOpen(WsOutbound outbound) {
System.out.println("Open Client.");
this.myoutbound =
mykey ="open "+System.currentTimeMillis();;
mmiList.put(mykey, this);
System.out.println("mmiList size:"+mmiList.size());
outbound.writeTextMessage(CharBuffer.wrap(mykey));
} catch (IOException e) {
e.printStackTrace();
public void onClose(int status) {
System.out.println("Close Client.");
//mmiList.remove(this);
mmiList.remove(mykey);
protected void onBinaryMessage(ByteBuffer arg0) throws IOException {
protected void onTextMessage(CharBuffer message) throws IOException {
// TODO Auto-generated method stub
System.out.println("onText---&" + message.toString());
for (int i=0;i& mmiList.size();i++ ) {
MyMessageInbound mmib = (MyMessageInbound) mmiList.get(i);
CharBuffer buffer = CharBuffer.wrap(message);
mmib.myoutbound.writeTextMessage(buffer);
mmib.myoutbound.flush();
for (Map.Entry&String, MyMessageInbound& entry : mmiList.entrySet()) {
//System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
MyMessageInbound mmib = (MyMessageInbound) entry.getValue();
// String str = entry.getKey()+message.toString()
CharBuffer buffer = CharBuffer.wrap(message);
mmib.myoutbound.writeTextMessage(buffer);
mmib.myoutbound.flush();
String msg = "";
// 向服务器利用Socket发送信息
socket = new Socket("192.168.0.102", 5000);
// socket = new Socket("127.0.0.1",5000);
PrintWriter output = new PrintWriter(socket.getOutputStream());
output.write(message.toString());
output.flush();
// 这里是接收到Server的信息
DataInputStream input = new DataInputStream(
socket.getInputStream());
byte[] b = new byte[1024];
input.read(b);
// Server返回的信息
msg = new String(b).trim();
output.close();
input.close();
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
// 往浏览器发送信息
CharBuffer cb = CharBuffer.wrap(new StringBuilder(msg));
getWsOutbound().writeTextMessage(cb);*/
public static void main(String[] args) {
String message = "haoning";
String msg = "";
// 向服务器利用Socket发送信息
socket = new Socket("192.168.0.102", 5000);
// socket = new Socket("127.0.0.1",5000);
PrintWriter output = new PrintWriter(socket.getOutputStream());
output.write(message.toString());
output.flush();
// 这里是接收到Server的信息
DataInputStream input = new DataInputStream(socket.getInputStream());
byte[] b = new byte[1024];
input.read(b);
// Server返回的信息
msg = new String(b).trim();
output.close();
input.close();
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
&servlet-name&wsSnake&/servlet-name&
&servlet-class&com.hao.HelloWorldWebSocketServlet&/servlet-class&
&/servlet&
&servlet-mapping&
&servlet-name&wsSnake&/servlet-name&
&url-pattern&/websocket/test&/url-pattern&
&/servlet-mapping&
haoningabc
浏览: 526350 次
来自: 北京
http://www./WebSoc ...
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
leebyte 写道太NB了,期待早日用上Killinux!么 ...
太NB了,期待早日用上Killinux!
位大神有木有WebRTC的视频资料网站么?文字的有时候不太看得 ...iOS开发工程师(5)
可以侧滑的cell
反正我是发现目前好多apps都需要有这样的功能。希望大家可以受用吧。其实这样的cell的思路我有两个:1.在cell上加手势,2.使用系统自带的(iOS8.0之后更新的)。思路一得具体实现我就不多讲了,在我的代码里有,只是注释了,可以供大家参考一下。我们来讲思路二。
首先,在STB中自定义一个主页的cell,大致如下:
我这里取名叫yxHomeTableViewCell。同时我模拟了一个网络请求:
+ (RACSignal *)signalForApi:(NSString *)api withParameter:(NSDictionary *)para {
NSDictionary *dict = @{@"data":@[@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"jaslkj可能大量客户的数量可费劲了;卡e shi yige ceshi xiaoxi ",@"img":@"2",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"3",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"4",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"5",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"6",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"1",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"7",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"8",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"9",@"time":@"14:38"},@{@"title":@"nihao",@"message":@"zhege shi yige ceshi xiaoxi ",@"img":@"10",@"time":@"14:38"}]};
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id&RACSubscriber& subscriber) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSMutableArray &yxHomeTableViewCellModel *& *dataSource = [NSMutableArray array];
for (id obj in dict[@"data"]) {
[dataSource addObject:[yxHomeTableViewCellModel modelWithDictionary:obj]];
[subscriber sendNext:dataSource];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
很显然,我们回到yxHomeViewController.m后实现tableView的dataSource,你会得到这样的效果:
下面就是添加侧滑了。事实上,在iOS8.0以后,系统公布了一个api,可以让我们快速的添加上这些cell的按钮:
#pragma mark - UITableViewDelegate
- (nullable NSArray&UITableViewRowAction *& *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction * action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
action.backgroundColor = [UIColor redColor];
UITableViewRowAction * action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"标为未读" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
action1.backgroundColor = [UIColor lightGrayColor];
return @[action,action1];
效果如下:
是不是很简单!(关于MVC的我就不多讲了)。
ps:今天就到这里,其实项目中简单的页面就不用我多说了,就是几个tableView而已,目前正在写朋友圈里的东西,到时候就会有比较多的文字了,请亲们期待一下咯!!!
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2431次
排名:千里之外下次自动登录
关注移动互联网和移动APP开发工具、开发框架、测试工具、微信开发、Android源码、Android开源类库以及各种开源组件的IT科技网站
现在的位置:
ios 仿微信,短信聊天气泡
苹果短信的聊天气泡和的聊天气泡一直很经典,很小的一个气泡根据文字的多少适当变大变小。
其实实现很简单,主要是控件的自适应撑高,这里用到的是cell。
- (UIView*)bubbleView:(NSString
*)textimageName:(NSString
UIView *returnView=
[[UIViewalloc]
initWithFrame:CGRectZero];
returnView.backgroundColor=
[UIColorclearColor];~iphone
isEqualToString:@"1"])
[[UIImageimageWithContentsOfFile:[[NSBundlemainBundle]
pathForResource:@""ofType:@"png"]]resizableImageWithCapInsets:UIEdgeInsetsMake(15.0f,25.0f,16.0f,23.0f)];
[[UIImageimageNamed:@"ImageBubble~iphone"]stretchableImageWithLeftCapWidth:15topCapHeight:14];
UIImageView *bubbleImageView=
[[UIImageViewalloc]
initWithImage:bubble];
UIFont *font=
[UIFontsystemFontOfSize:13];
CGSize size=
[textsizeWithFont:font
constrainedToSize:CGSizeMake(220.0f,1000.0f)lineBreakMode:
NSLineBreakByWordWrapping];
CGSize new1=
[textsizeWithFont:font
constrainedToSize:CGSizeMake(220.0f,size.height)lineBreakMode:
NSLineBreakByWordWrapping];
UILabel*bubbleT
isEqualToString:@"1"]){
bubbleText
= [[UILabel
alloc] initWithFrame:CGRectMake(12.0f,5.0f,new1.width+10,new1.height+10)];
bubbleText
= [[UILabel
alloc] initWithFrame:CGRectMake(5.0f,5.0f,new1.width+10,new1.height+10)];
bubbleText.backgroundColor=
[UIColorclearColor];
bubbleText.font=
bubbleText.numberOfLines=
bubbleText.lineBreakMode=
NSLineBreakByWordW
bubbleText.text=
bubbleImageView.frame=
CGRectMake(0.0f,0.0f,new1.width+
20, new1.height+20.0f);
isEqualToString:@"1"]){
returnView.frame=
CGRectMake(40.0f,30.0f,new1.width+
20, new1.height+20.0f);
returnView.frame=
CGRectMake(260.0f-
new1.width,40.0f,new1.width+
20, new1.height+20.0f);
[returnView addSubview:bubbleImageView];
[returnView addSubview:bubbleText];
returnreturnView
这段代码可以直接使用,在tableview的代理方法里还要实现cell自适应的高度
- (CGFloat)tableView:(UITableView*)tableView
heightForRowAtIndexPath:(NSIndexPath*)indexPath
最后着重提出一点,其实网上很多类似的demo都可以实现此类效果,但有的demo拿过来发现气泡吹变形了,这可不是方法出了问题,是图片的问题,多找些气泡试试。lz就是被这个事情困扰了好久,换了好几个版本的方法发现
【上篇】【下篇】}

我要回帖

更多关于 自定义tablecell 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信