YMCreateGreetingTemplateVoiceView.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // YMCreateGreetingTemplateVoiceView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/25.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCreateGreetingTemplateVoiceView.h"
  9. #import "YMCreateGreetingTemplateViewModel.h"
  10. #import "YMRecordSoundView.h"
  11. @interface YMCreateGreetingTemplateVoiceView ()
  12. /// 创建打招呼模板VM
  13. @property (nonatomic, strong) YMCreateGreetingTemplateViewModel *viewModel;
  14. /// 提示标签
  15. @property (nonatomic, strong) UILabel *tipsLb;
  16. /// 模板录音视图
  17. @property (nonatomic, strong) YMRecordSoundView *templatesVoiceView;
  18. @end
  19. @implementation YMCreateGreetingTemplateVoiceView
  20. - (void)ym_setupViews{
  21. [self addSubview:self.tipsLb];
  22. [self addSubview:self.templatesVoiceView];
  23. [self setNeedsUpdateConstraints];
  24. [self updateConstraintsIfNeeded];
  25. }
  26. - (void)updateConstraints{
  27. [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.equalTo(self).offset(adapt(15));
  29. make.left.equalTo(self).offset(adapt(15));
  30. }];
  31. [self.templatesVoiceView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(15));
  33. make.left.equalTo(self).offset(adapt(15));
  34. make.right.equalTo(self).offset(adapt(-15));
  35. make.bottom.equalTo(self).offset(adapt(-15));
  36. }];
  37. [super updateConstraints];
  38. }
  39. - (void)ym_bindViewModel:(YMCreateGreetingTemplateViewModel *)viewModel{
  40. if (!viewModel) {
  41. return;
  42. }
  43. _viewModel = viewModel;
  44. }
  45. - (UILabel *)tipsLb{
  46. if (!_tipsLb) {
  47. _tipsLb = [[UILabel alloc]init];
  48. NSString *tipsStr = @"添加语音(限制5~15秒)";
  49. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:tipsStr];
  50. attributedString.yy_font = LCFont(13);
  51. attributedString.yy_color = HexColorFromRGB(0x333333);
  52. attributedString.yy_alignment = NSTextAlignmentLeft;
  53. //设置高亮色和点击事件
  54. [attributedString yy_setColor:HexColorFromRGB(0x9d9d9d) range:[tipsStr rangeOfString:@"(限制5~15秒)"]];
  55. _tipsLb.attributedText = attributedString;
  56. }
  57. return _tipsLb;
  58. }
  59. - (YMRecordSoundView *)templatesVoiceView{
  60. if (!_templatesVoiceView) {
  61. _templatesVoiceView = [[YMRecordSoundView alloc]initWithIsNeedSubmitButton:NO OperationSize:CGSizeMake(adapt(135), adapt(84))];
  62. _templatesVoiceView.minDuration = 5;
  63. _templatesVoiceView.maxDuration = 15;
  64. _templatesVoiceView.exportType = YMRecordSoundExportTypeAAC;
  65. @weakify(self)
  66. _templatesVoiceView.exportUrlBlock = ^(NSURL * _Nonnull voiceUrl, NSInteger voiceDuration) {
  67. @strongify(self)
  68. NSLog(@"录音地址%@",voiceUrl);
  69. self.viewModel.templateVoiceLocalUrl = voiceUrl;
  70. self.viewModel.templateVoiceDuration = voiceDuration;
  71. };
  72. }
  73. return _templatesVoiceView;
  74. }
  75. @end