免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1888 | 回复: 3
打印 上一主题 下一主题

气泡聊天 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-20 20:28 |只看该作者 |倒序浏览
本帖最后由 feiyang10086 于 2012-01-20 20:29 编辑


气泡聊天







Ios代码
  1. 1.- (UIView *)bubbleView:(NSString *)text from:(BOOL)fromSelf {  
  2. 2.    UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero];  
  3. 3.    returnView.backgroundColor = [UIColor clearColor];  
  4. 4.      
  5. 5.    UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fromSelf ? @"bubbleSelf" : @"bubble" ofType:@"png"]];  
  6. 6.    UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:[bubble stretchableImageWithLeftCapWidth:21 topCapHeight:14]];  
  7. 7.      
  8. 8.    UIFont *font = [UIFont systemFontOfSize:12];  
  9. 9.    CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(150.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap];  
  10. 10.      
  11. 11.    UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(21.0f, 14.0f, size.width + 10, size.height + 10)];  
  12. 12.    bubbleText.backgroundColor = [UIColor clearColor];  
  13. 13.    bubbleText.font = font;  
  14. 14.    bubbleText.numberOfLines = 0;  
  15. 15.    bubbleText.lineBreakMode = UILineBreakModeCharacterWrap;  
  16. 16.    bubbleText.text = text;  
  17. 17.      
  18. 18.    bubbleImageView.frame = CGRectMake(0.0f, 0.0f, 200.0f, size.height + 40.0f);  
  19. 19.    if(fromSelf)  
  20. 20.        returnView.frame = CGRectMake(120.0f, 10.0f, 200.0f, size.height + 50.0f);  
  21. 21.    else  
  22. 22.        returnView.frame = CGRectMake(0.0f, 10.0f, 200.0f, size.height + 50.0f);  
  23. 23.      
  24. 24.    [returnView addSubview:bubbleImageView];  
  25. 25.    [bubbleImageView release];  
  26. 26.    [returnView addSubview:bubbleText];  
  27. 27.    [bubbleText release];  
  28. 28.      
  29. 29.    return [returnView autorelease];  
  30. 30.}  
复制代码
效果图:



论坛徽章:
0
2 [报告]
发表于 2012-01-20 20:30 |只看该作者
谢谢分享

论坛徽章:
0
3 [报告]
发表于 2012-01-23 23:49 |只看该作者
聊天啊。学习。

论坛徽章:
0
4 [报告]
发表于 2012-02-29 14:17 |只看该作者
呵呵,总是看见iOS的代码,看来的学习object-c了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP