IOS类似于微信和qq的泡泡语音

本文介绍了一个用于构建语音消息UI组件的方法,该组件能够根据发送者身份调整位置,并展示语音消息的长度。组件包括背景图片、播放按钮及语音时长标签。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 未简化 不可复用 仅供参考

//泡泡语音
- (UIView *)yuyinView:(NSInteger)logntime from:(BOOL)fromSelf withIndexRow:(NSInteger)indexRow withPosition:(int)position{

//根据语音长度
int yuyinwidth = 66+fromSelf;

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = indexRow;
if(fromSelf)
    button.frame =CGRectMake(320-position-yuyinwidth, 10, yuyinwidth, 54);
else
    button.frame =CGRectMake(position, 10, yuyinwidth, 54);

//image偏移量
UIEdgeInsets imageInsert;
imageInsert.top = -10;
imageInsert.left = fromSelf?button.frame.size.width/3:-button.frame.size.width/3;
button.imageEdgeInsets = imageInsert;

[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 = NSTextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[button addSubview:label];

return button;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值