123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- //
- // 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 *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.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{
-
- 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(10));
- make.bottom.equalTo(self).offset(adapt(-10));
- make.height.mas_equalTo(adapt(64));
- }];
-
- [self.myBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.myBalanceView.mas_centerY);
- make.left.equalTo(self.myBalanceView).offset(adapt(11));
- make.width.height.mas_equalTo(adapt(44));
- }];
-
- [self.myBalanceContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.myBalanceIcon.mas_top);
- make.left.equalTo(self.myBalanceIcon.mas_right).offset(8);
- make.right.equalTo(self.myBalanceView).offset(adapt(-5));
- }];
-
- [self.myBalanceTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.myBalanceContentLb.mas_bottom).offset(adapt(3));
- make.left.equalTo(self.myBalanceIcon.mas_right).offset(8);
- }];
-
- [self.myEarningsIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.myEarningsView.mas_centerY);
- make.left.equalTo(self.myEarningsView).offset(adapt(5));
- make.width.height.mas_equalTo(adapt(44));
- }];
-
- [self.myEarningsContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.myEarningsIcon.mas_top);
- make.left.equalTo(self.myEarningsIcon.mas_right).offset(8);
- make.right.equalTo(self.myEarningsView).offset(adapt(-5));
- }];
-
- [self.myEarningsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.myEarningsContentLb.mas_bottom).offset(adapt(3));
- make.left.equalTo(self.myEarningsIcon.mas_right).offset(8);
- }];
-
-
- [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 *)myBalanceView{
- if (!_myBalanceView) {
- _myBalanceView = [[UIView alloc]init];
- _myBalanceView.backgroundColor = HexColorFromRGB(0xFFF8F0);
- _myBalanceView.layer.cornerRadius = adapt(8);
- _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 = HexColorFromRGB(0x292929);
- _myBalanceContentLb.textAlignment = NSTextAlignmentLeft;
- _myBalanceContentLb.text = @"0";
- }
- return _myBalanceContentLb;
- }
- - (UILabel *)myBalanceTitleLb{
- if (!_myBalanceTitleLb) {
- _myBalanceTitleLb = [[UILabel alloc]init];
- _myBalanceTitleLb.font = LCFont(11);
- _myBalanceTitleLb.textColor = HexColorFromRGBA(0x000000,0.45);
- _myBalanceTitleLb.textAlignment = NSTextAlignmentLeft;
- _myBalanceTitleLb.text = @"我的余额";
- }
- return _myBalanceTitleLb;
- }
- - (UIView *)myEarningsView{
- if (!_myEarningsView) {
- _myEarningsView = [[UIView alloc]init];
- _myEarningsView.backgroundColor = HexColorFromRGB(0xF2FAFF);
- _myEarningsView.layer.cornerRadius = adapt(8);
- _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 = HexColorFromRGB(0x292929);
- _myEarningsContentLb.textAlignment = NSTextAlignmentLeft;
- _myEarningsContentLb.text = @"0";
- }
- return _myEarningsContentLb;
- }
- - (UILabel *)myEarningsTitleLb{
- if (!_myEarningsTitleLb) {
- _myEarningsTitleLb = [[UILabel alloc]init];
- _myEarningsTitleLb.font = LCFont(11);
- _myEarningsTitleLb.textColor = HexColorFromRGBA(0x000000,0.45);
- _myEarningsTitleLb.textAlignment = NSTextAlignmentLeft;
- _myEarningsTitleLb.text = @"我的收益";
- }
- return _myEarningsTitleLb;
- }
- @end
|