// // YMCreateGreetingTemplateVoiceView.m // MSYOUPAI // // Created by YoMi on 2024/2/25. // Copyright © 2024 MS. All rights reserved. // #import "YMCreateGreetingTemplateVoiceView.h" #import "YMCreateGreetingTemplateViewModel.h" #import "YMRecordSoundView.h" @interface YMCreateGreetingTemplateVoiceView () /// 创建打招呼模板VM @property (nonatomic, strong) YMCreateGreetingTemplateViewModel *viewModel; /// 提示标签 @property (nonatomic, strong) UILabel *tipsLb; /// 模板录音视图 @property (nonatomic, strong) YMRecordSoundView *templatesVoiceView; @end @implementation YMCreateGreetingTemplateVoiceView - (void)ym_setupViews{ [self addSubview:self.tipsLb]; [self addSubview:self.templatesVoiceView]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(15)); make.left.equalTo(self).offset(adapt(15)); }]; [self.templatesVoiceView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(15)); make.left.equalTo(self).offset(adapt(15)); make.right.equalTo(self).offset(adapt(-15)); make.bottom.equalTo(self).offset(adapt(-15)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMCreateGreetingTemplateViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; } - (UILabel *)tipsLb{ if (!_tipsLb) { _tipsLb = [[UILabel alloc]init]; NSString *tipsStr = @"添加语音(限制5~15秒)"; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:tipsStr]; attributedString.yy_font = LCFont(13); attributedString.yy_color = HexColorFromRGB(0x333333); attributedString.yy_alignment = NSTextAlignmentLeft; //设置高亮色和点击事件 [attributedString yy_setColor:HexColorFromRGB(0x9d9d9d) range:[tipsStr rangeOfString:@"(限制5~15秒)"]]; _tipsLb.attributedText = attributedString; } return _tipsLb; } - (YMRecordSoundView *)templatesVoiceView{ if (!_templatesVoiceView) { _templatesVoiceView = [[YMRecordSoundView alloc]initWithIsNeedSubmitButton:NO OperationSize:CGSizeMake(adapt(135), adapt(84))]; _templatesVoiceView.minDuration = 5; _templatesVoiceView.maxDuration = 15; _templatesVoiceView.exportType = YMRecordSoundExportTypeAAC; @weakify(self) _templatesVoiceView.exportUrlBlock = ^(NSURL * _Nonnull voiceUrl, NSInteger voiceDuration) { @strongify(self) NSLog(@"录音地址%@",voiceUrl); self.viewModel.templateVoiceLocalUrl = voiceUrl; self.viewModel.templateVoiceDuration = voiceDuration; }; } return _templatesVoiceView; } @end