123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // YMCreateGreetingTemplateImageView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/25.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMCreateGreetingTemplateImageView.h"
- #import "YMCreateGreetingTemplateViewModel.h"
- @interface YMCreateGreetingTemplateImageView ()
- /// 创建打招呼模板VM
- @property (nonatomic, strong) YMCreateGreetingTemplateViewModel *viewModel;
- /// 提示标签
- @property (nonatomic, strong) UILabel *tipsLb;
- /// 模板图片视图
- @property (nonatomic, strong) UIImageView *templateImageView;
- /// 删除模板图片按钮
- @property (nonatomic, strong) UIButton *deleteTemplateImageBtn;
- @end
- @implementation YMCreateGreetingTemplateImageView
- - (void)ym_setupViews{
-
- [self addSubview:self.tipsLb];
- [self addSubview:self.templateImageView];
- [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.templateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(15));
- make.left.equalTo(self).offset(adapt(15));
- make.bottom.equalTo(self).offset(adapt(-15));
- make.width.height.mas_equalTo(adapt(100));
- }];
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMCreateGreetingTemplateViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[[[[RACObserve(self.viewModel, templateImageUrl) ignore:nil] distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * templateImageUrl) {
- @strongify(self)
- [self.templateImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:templateImageUrl]];
- }];
-
-
- }
- - (UILabel *)tipsLb{
- if (!_tipsLb) {
- _tipsLb = [[UILabel alloc]init];
- NSString *tipsStr = @"添加图片(仅可添加一张)";
- 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:@"(仅可添加一张)"]];
- _tipsLb.attributedText = attributedString;
- }
- return _tipsLb;
- }
- - (UIImageView *)templateImageView{
- if (!_templateImageView) {
- _templateImageView = [[UIImageView alloc]init];
- _templateImageView.image = ImageByName(@"ym_edit_profile_add_icon");
- // _templateImageView.contentMode = UIViewContentModeScaleAspectFill;
- // _templateImageView.backgroundColor = HexColorFromRGB(0xF6F6F6);
- // _templateImageView.layer.cornerRadius = adapt(8);
- // _templateImageView.clipsToBounds = YES;
- _templateImageView.userInteractionEnabled = YES;
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_templateImageView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel openImagePickerPopupView];
- }];
- }
- return _templateImageView;
- }
- - (UIButton *)deleteTemplateImageBtn{
- if (!_deleteTemplateImageBtn) {
- _deleteTemplateImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- WS(weakSelf)
- [[[_deleteTemplateImageBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- weakSelf.templateImageView.image = ImageByName(@"ym_edit_profile_add_icon");
- weakSelf.viewModel.templateImageUrl = @"";
- }];
- }
- return _deleteTemplateImageBtn;
- }
- @end
|