ios php 聊天_iOS开发之微信聊天页面实现

聊天界面的效果图如下:在下面的聊天界面中中用到了3类cell,一类是显示文字和表情的,一类是显示录音的,一类是显示图片的。当点击图片时会跳转到另一个Controller中来进行图片显示,在图片显示页面中添加了一个捏合的手势。点击播放按钮,会播放录制的音频,cell的大学会根据内容的多少来调整,而cell中textView的高度是通过约束来设置的。一,定义我们要用的cell,代码如下:1,显示表情和...
摘要由CSDN通过智能技术生成

聊天界面的效果图如下:在下面的聊天界面中中用到了3类cell,一类是显示文字和表情的,一类是显示录音的,一类是显示图片的。当点击图片时会跳转到另一个Controller中来进行图片显示,在图片显示页面中添加了一个捏合的手势。点击播放按钮,会播放录制的音频,cell的大学会根据内容的多少来调整,而cell中textView的高度是通过约束来设置的。

5941b2541a510e094f333b0a5b9fefc8.png

一,定义我们要用的cell,代码如下:

1,显示表情和text的cell,代码如下,需要根据NSMutableAttributedString求出bound,然后改变cell上的ImageView和TextView的宽度的约束值,动态的调整气泡的大小,具体代码如下:#import "TextCell.h"

@interface TextCell()

@property (strong, nonatomic) IBOutlet UIImageView *headImageView;

@property (strong, nonatomic) IBOutlet UIImageView *chatBgImageView;

@property (strong, nonatomic) IBOutlet UITextView *chatTextView;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *chatBgImageWidthConstraint;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *chatTextWidthConstaint;

@property (strong, nonatomic) NSMutableAttributedString *attrString;

@end

@implementation TextCell

-(void)setCellValue:(NSMutableAttributedString *)str

{

//移除约束

[self removeConstraint:_chatBgImageWidthConstraint];

[self removeConstraint:_chatTextWidthConstaint];

self.attrString = str;

NSLog(@"%@",self.attrString);

//由text计算出text的宽高

CGRect bound = [self.attrString boundingRectWithSize:CGSizeMake(150, 1000) options:NSStringDrawingUsesLineFragmentOrigin context:nil];

//根据text的宽高来重新设置新的约束

//背景的宽

NSString *widthImageString;

NSArray *tempArray;

widthImageString = [NSString stringWithFormat:@"H:[_chatBgImageView(%f)]", bound.size.width+45];

tempArray = [NSLayoutConstraint constraintsWithVisualFormat:widthImageString options:0 metrics:0 views:NSDictionaryOfVariableBindings(_chatBgImageView)];

_chatBgImageWidthConstraint = tempArray[0];

[self addConstraint:self.chatBgImageWidthConstraint];

widthImageString = [NSString stringWithFormat:@"H:[_chatTextView(%f)]", bound.size.width+20];

tempArray = [NSLayoutConstraint constraintsWithVisualFormat:widthImageString options:0 metrics:0 views:NSDictionaryOfVariableBindings(_chatTextView)];

_chatBgImageWidthConstraint = tempArray[0];

[self addConstraint:self.chatBgImageWidthConstraint];

//设置图片

UIImage *image = [UIImage imageNamed:@"chatfrom_bg_normal.png"];

image = [image resizableImageWithCapInsets:(UIEdgeInsetsMake(image.size.height * 0.6, image.size.width * 0.4, image.size.height * 0.3, image.size.width * 0.4))];

//image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];

[self.chatBgImageView setImage:image];

self.chatTextView.attributedText = str;

}

@end

2.显示图片的cell,通过block回调把图片传到Controller中,用于放大图片使用。#import "MyImageCell.h"

@interface MyImageCell()

@property (strong, nonatomic) IBOutlet UIImageView *bgImageView;

@property (strong, nonatomic) IBOutlet UIButton *imageButton;

@property (strong, nonatomic) ButtonImageBlock imageBlock;

@property (strong, nonatomic) UIImage *buttonImage;

@end

@implementation MyImageCell

-(void)setCellValue:(UIImage *)sendImage

{

self.buttonImage = sendImage;

UIImage *image = [UIImage imageNamed:@"chatto_bg_normal.png"];

image = [image resizableImageWithCapInsets:(UIEdgeInsetsMake(image.size.height * 0.6, image.size.width * 0.4, image.size.height * 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值