// // YMMineWealthView.m // MSYOUPAI // // Created by YoMi on 2024/2/15. // Copyright © 2024 MS. All rights reserved. // #import "YMMineWealthView.h" #import "YMMineViewModel.h" @interface YMMineWealthView () /// 我的VM @property (nonatomic, strong) YMMineViewModel *viewModel; /// 背景视图 @property (nonatomic, strong) UIView *bgv; /// 我的余额视图 @property (nonatomic, strong) UIView *myBalanceView; /// 我的余额图标 @property (nonatomic, strong) UIImageView *myBalanceIcon; /// 我的余额内容标签 @property (nonatomic, strong) UILabel *myBalanceContentLb; /// 我的余额标题标签 @property (nonatomic, strong) UILabel *myBalanceTitleLb; /// 我的收益视图 @property (nonatomic, strong) UIView *myEarningsView; /// 我的收益图标 @property (nonatomic, strong) UIImageView *myEarningsIcon; /// 我的收益内容标签 @property (nonatomic, strong) UILabel *myEarningsContentLb; /// 我的收益标题标签 @property (nonatomic, strong) UILabel *myEarningsTitleLb; @end @implementation YMMineWealthView - (void)ym_setupViews{ [self addSubview:self.bgv]; [self addSubview:self.myBalanceView]; [self.myBalanceView addSubview:self.myBalanceIcon]; [self.myBalanceView addSubview:self.myBalanceContentLb]; [self.myBalanceView addSubview:self.myBalanceTitleLb]; [self addSubview:self.myEarningsView]; [self.myEarningsView addSubview:self.myEarningsIcon]; [self.myEarningsView addSubview:self.myEarningsContentLb]; [self.myEarningsView addSubview:self.myEarningsTitleLb]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.bgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.equalTo(self).offset(adapt(0)); make.left.equalTo(self).offset(adapt(15)); make.right.equalTo(self).offset(adapt(-15)); make.height.mas_equalTo(adapt(89)); }]; [self.myBalanceView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(8)); make.bottom.equalTo(self).offset(adapt(-8)); make.left.equalTo(self.bgv.mas_left).offset(adapt(8)); }]; [self.myEarningsView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(8)); make.bottom.equalTo(self).offset(adapt(-8)); make.left.equalTo(self.myBalanceView.mas_right).offset(adapt(10)); make.right.equalTo(self.bgv).offset(adapt(-8)); make.width.equalTo(self.myBalanceView); }]; // NSArray *btnArr = @[self.myBalanceView,self.myEarningsView]; // // // 实现masonry水平固定控件宽度方法 // // axisType 横排还是竖排 // // fixedSpacing 两个控件间隔 // // leadSpacing 第一个控件与边缘的间隔 // // tailSpacing 最后一个控件与边缘的间隔 // [btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(20) leadSpacing:adapt(15) tailSpacing:adapt(15)]; // // // 设置array的垂直方向的约束 // [btnArr mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self).offset(adapt(8)); // make.bottom.equalTo(self).offset(adapt(-8)); // //make.height.mas_equalTo(adapt(73)); // }]; [self.myBalanceTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myBalanceView.mas_top).offset(adapt(10)); make.left.equalTo(self.myBalanceView.mas_left).offset(adapt(10)); }]; [self.myBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myBalanceView.mas_top).offset(adapt(10)); make.right.equalTo(self.myBalanceView.mas_right).offset(adapt(-10)); make.width.height.mas_equalTo(adapt(16)); }]; [self.myBalanceContentLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myBalanceTitleLb.mas_bottom).offset(adapt(8)); make.left.equalTo(self.myBalanceTitleLb.mas_left).offset(0); }]; [self.myEarningsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myEarningsView.mas_top).offset(adapt(10)); make.left.equalTo(self.myEarningsView.mas_left).offset(adapt(10)); }]; [self.myEarningsIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myEarningsView.mas_top).offset(adapt(10)); make.right.equalTo(self.myEarningsView.mas_right).offset(adapt(-10)); make.width.height.mas_equalTo(adapt(16)); }]; [self.myEarningsContentLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.myEarningsTitleLb.mas_bottom).offset(adapt(8)); make.left.equalTo(self.myEarningsTitleLb.mas_left).offset(0); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMMineViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; RAC(self.myBalanceContentLb, text) = RACObserve(self.viewModel, userBalance); RAC(self.myEarningsContentLb, text) = RACObserve(self.viewModel, userEarnings); } - (UIView *)bgv{ if (!_bgv) { _bgv = [[UIView alloc]init]; _bgv.backgroundColor = HexColorFromRGB(0xFFFFFF); _bgv.userInteractionEnabled = YES; _bgv.layer.cornerRadius = adapt(12); _bgv.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner; _bgv.layer.masksToBounds = YES; } return _bgv; } - (UIView *)myBalanceView{ if (!_myBalanceView) { _myBalanceView = [[UIView alloc]init]; _myBalanceView.backgroundColor = rgba(255, 102, 169, 1); _myBalanceView.layer.cornerRadius = adapt(10); _myBalanceView.layer.masksToBounds = YES; _myBalanceView.userInteractionEnabled = YES; //[_myBalanceView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xFDDEF2),HexColorFromRGB(0xFFF6FC),HexColorFromRGB(0xFFD6F2),] locations:@[@0, @0.5, @1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)]; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_myBalanceView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel gotoAccountBalance]; }]; } return _myBalanceView; } - (UIImageView *)myBalanceIcon{ if (!_myBalanceIcon) { _myBalanceIcon = [[UIImageView alloc]init]; _myBalanceIcon.image = ImageByName(@"ym_mine_diamond_icon"); } return _myBalanceIcon; } - (UILabel *)myBalanceContentLb{ if (!_myBalanceContentLb) { _myBalanceContentLb = [[UILabel alloc]init]; _myBalanceContentLb.font = LCBoldFont(21); _myBalanceContentLb.textColor = UIColor.whiteColor; _myBalanceContentLb.textAlignment = NSTextAlignmentLeft; _myBalanceContentLb.text = @"0"; } return _myBalanceContentLb; } - (UILabel *)myBalanceTitleLb{ if (!_myBalanceTitleLb) { _myBalanceTitleLb = [[UILabel alloc]init]; _myBalanceTitleLb.font = LCFont(11); _myBalanceTitleLb.textColor = UIColor.whiteColor; _myBalanceTitleLb.textAlignment = NSTextAlignmentLeft; _myBalanceTitleLb.text = @"我的余额"; } return _myBalanceTitleLb; } - (UIView *)myEarningsView{ if (!_myEarningsView) { _myEarningsView = [[UIView alloc]init]; _myEarningsView.backgroundColor = rgba(255, 190, 84, 1); _myEarningsView.layer.cornerRadius = adapt(10); _myEarningsView.layer.masksToBounds = YES; _myEarningsView.userInteractionEnabled = YES; //[_myEarningsView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xEAD7FE),HexColorFromRGB(0xF9F6FF),HexColorFromRGB(0xEAD7FE),] locations:@[@0, @0.5, @1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)]; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_myEarningsView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel gotoMyEarnings]; }]; } return _myEarningsView; } - (UIImageView *)myEarningsIcon{ if (!_myEarningsIcon) { _myEarningsIcon = [[UIImageView alloc]init]; _myEarningsIcon.image = ImageByName(@"ym_mine_coin_icon"); } return _myEarningsIcon; } - (UILabel *)myEarningsContentLb{ if (!_myEarningsContentLb) { _myEarningsContentLb = [[UILabel alloc]init]; _myEarningsContentLb.font = LCBoldFont(17); _myEarningsContentLb.textColor = UIColor.whiteColor; _myEarningsContentLb.textAlignment = NSTextAlignmentLeft; _myEarningsContentLb.text = @"0"; } return _myEarningsContentLb; } - (UILabel *)myEarningsTitleLb{ if (!_myEarningsTitleLb) { _myEarningsTitleLb = [[UILabel alloc]init]; _myEarningsTitleLb.font = LCFont(12); _myEarningsTitleLb.textColor = UIColor.whiteColor; _myEarningsTitleLb.textAlignment = NSTextAlignmentLeft; _myEarningsTitleLb.text = @"我的收益"; } return _myEarningsTitleLb; } @end