Files
yinmeng-ios/xplan-ios/Base/UI/SendGiftView/View/XPGiftBarView.m

345 lines
11 KiB
Mathematica
Raw Normal View History

2021-11-10 18:42:27 +08:00
//
// XPGiftBottomView.m
// xplan-ios
//
// Created by on 2021/11/9.
//
#import "XPGiftBarView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor+SendGift.h"
#import "UIImage+Utils.h"
///Model
#import "XPGiftCountModel.h"
#import "WalletInfoModel.h"
///View
#import "XPGiftCountCollectionViewCell.h"
2021-11-15 18:59:44 +08:00
@interface XPGiftBarView ()<UITextFieldDelegate>
///
@property (nonatomic,strong) UIStackView *stackView;
///
@property (nonatomic,strong) UIView *infoView;
///count
@property (nonatomic,strong) UIStackView *customCountStackView;
2021-11-10 18:42:27 +08:00
///
@property (nonatomic,strong) UILabel *balanceLabel;
///
@property (nonatomic,strong) UIStackView *rechargeStackView;
///
@property (nonatomic,strong) UILabel *rechargeLabel;
///
@property (nonatomic,strong) UIImageView *rechageImageView;
///
@property (nonatomic,strong) UIView *sendOperationView;
///
@property (nonatomic,strong) UILabel *countLabel;
///
@property (nonatomic,strong) UIButton *arrowButton;
///
@property (nonatomic,strong) UIButton *sendGiftButton;
2021-11-15 18:59:44 +08:00
///
//
@property (nonatomic, strong) UITextField *editTextFiled;
//
@property (nonatomic, strong) UIButton *sureButton;
2021-11-10 18:42:27 +08:00
@end
@implementation XPGiftBarView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Response
- (void)sendButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftBarView:didClickSendGift:)]) {
[self.delegate xPGiftBarView:self didClickSendGift:self.giftCountModel];
}
2021-11-10 18:42:27 +08:00
}
2021-11-15 18:59:44 +08:00
- (void)didTagRecharge:(UITapGestureRecognizer *)tap {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftBarViewDidClickRecharge:)]) {
[self.delegate xPGiftBarViewDidClickRecharge:self];
}
2021-11-10 18:42:27 +08:00
}
- (void)arrowButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftBarView:didClickCountButton:)]) {
sender.selected = !sender.selected;
[self.delegate xPGiftBarView:self didClickCountButton:sender];
}
2021-11-10 18:42:27 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor= [UIColor clearColor];
2021-11-15 18:59:44 +08:00
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.infoView];
[self.stackView addArrangedSubview:self.customCountStackView];
[self.infoView addSubview:self.balanceLabel];
[self.infoView addSubview:self.rechargeStackView];
[self.infoView addSubview:self.sendOperationView];
2021-11-10 18:42:27 +08:00
[self.rechargeStackView addArrangedSubview:self.rechargeLabel];
[self.rechargeStackView addArrangedSubview:self.rechageImageView];
[self.sendOperationView addSubview:self.countLabel];
[self.sendOperationView addSubview:self.arrowButton];
[self.sendOperationView addSubview:self.sendGiftButton];
2021-11-15 18:59:44 +08:00
[self.customCountStackView addArrangedSubview:self.editTextFiled];
[self.customCountStackView addArrangedSubview:self.sureButton];
2021-11-10 18:42:27 +08:00
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
2021-11-15 18:59:44 +08:00
make.height.mas_equalTo(85);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self);
}];
[self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
2021-11-10 18:42:27 +08:00
make.height.mas_equalTo(45);
}];
2021-11-15 18:59:44 +08:00
[self.customCountStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(40);
}];
2021-11-10 18:42:27 +08:00
[self.balanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(15);
make.centerY.mas_equalTo(self.sendOperationView);
}];
[self.rechargeStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.sendOperationView);
make.left.mas_equalTo(self.balanceLabel.mas_right).offset(12);
}];
[self.sendOperationView mas_makeConstraints:^(MASConstraintMaker *make) {
2021-11-15 18:59:44 +08:00
make.right.mas_equalTo(self.infoView).offset(-15);
2021-11-10 18:42:27 +08:00
make.bottom.mas_equalTo(-11);
make.height.mas_equalTo(30);
make.left.mas_equalTo(self.countLabel.mas_left).offset(-13);
}];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.sendGiftButton);
make.right.mas_equalTo(self.arrowButton.mas_left).offset(-2);
2021-11-10 18:42:27 +08:00
}];
[self.arrowButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(30, 30));
2021-11-10 18:42:27 +08:00
make.centerY.mas_equalTo(self.sendGiftButton);
make.right.mas_equalTo(self.sendGiftButton.mas_left).offset(-2);
2021-11-10 18:42:27 +08:00
}];
[self.sendGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(67, 30));
make.right.centerY.mas_equalTo(self.sendOperationView);
}];
2021-11-15 18:59:44 +08:00
[self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.width.mas_equalTo(@50);
}];
2021-11-10 18:42:27 +08:00
}
2021-11-15 18:59:44 +08:00
- (void)initEvents {
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTagRecharge:)];
[self.rechargeStackView addGestureRecognizer:tap];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSString *countStr = [self.editTextFiled.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSInteger count = [countStr integerValue];
if (count > 9999) {
return NO;
}
[self.editTextFiled resignFirstResponder];
self.editTextFiled.text = @"";
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *regex =@"[0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:string]) {
return YES;
}
return NO;
}
2021-11-10 18:42:27 +08:00
#pragma mark - Getters And Setters
- (void)setGiftCountModel:(XPGiftCountModel *)giftCountModel {
_giftCountModel = giftCountModel;
self.arrowButton.selected = NO;
if (_giftCountModel) {
self.countLabel.text = _giftCountModel.giftNumber;
}
}
- (void)setWalletInfoModel:(WalletInfoModel *)walletInfoModel {
_walletInfoModel = walletInfoModel;
if (_walletInfoModel) {
NSString * diamonds = _walletInfoModel.diamonds;
NSString * title = [NSString stringWithFormat:@"余额:%@", diamonds];
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13], NSForegroundColorAttributeName:[ThemeColor giftBalanceColor]}];
[attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor mainTextColor] range:[title rangeOfString:diamonds]];
self.balanceLabel.attributedText = attribute;
}
}
2021-11-10 18:42:27 +08:00
- (UILabel *)balanceLabel {
if (!_balanceLabel) {
_balanceLabel = [[UILabel alloc] init];
_balanceLabel.textColor = [ThemeColor mainTextColor];
_balanceLabel.font = [UIFont systemFontOfSize:13];
_balanceLabel.text = @"余额10000";
}
return _balanceLabel;
}
- (UIStackView *)rechargeStackView {
if (!_rechargeStackView) {
_rechargeStackView = [[UIStackView alloc] init];
_rechargeStackView.axis = UILayoutConstraintAxisHorizontal;
_rechargeStackView.distribution = UIStackViewDistributionFill;
_rechargeStackView.alignment = UIStackViewAlignmentCenter;
_rechargeStackView.spacing = 5;
}
return _rechargeStackView;
}
- (UILabel *)rechargeLabel {
if (!_rechargeLabel) {
_rechargeLabel = [[UILabel alloc] init];
_rechargeLabel.text = @"充值";
_rechargeLabel.font = [UIFont systemFontOfSize:13];
_rechargeLabel.textColor = [ThemeColor giftRechargeColor];
}
return _rechargeLabel;
}
- (UIImageView *)rechageImageView {
if (!_rechageImageView) {
_rechageImageView = [[UIImageView alloc] init];
_rechageImageView.userInteractionEnabled = YES;
_rechageImageView.image = [UIImage imageNamed:@"gift_bar_recharge_arrow"];
}
return _rechageImageView;
}
- (UIView *)sendOperationView {
if (!_sendOperationView) {
_sendOperationView = [[UIView alloc] init];
_sendOperationView.layer.masksToBounds = YES;
_sendOperationView.layer.cornerRadius = 15;
_sendOperationView.layer.borderColor = [ThemeColor appMainColor].CGColor;
_sendOperationView.layer.borderWidth = 1;
}
return _sendOperationView;
}
- (UILabel *)countLabel {
if (!_countLabel) {
_countLabel = [[UILabel alloc] init];
_countLabel.textAlignment = NSTextAlignmentCenter;
_countLabel.textColor = [ThemeColor mainTextColor];
_countLabel.text = @"1";
_countLabel.font = [UIFont systemFontOfSize:13];
}
return _countLabel;
}
- (UIButton *)arrowButton {
if (!_arrowButton) {
_arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_arrowButton setImage:[UIImage imageNamed:@"gift_bar_count_arrow"] forState:UIControlStateNormal];
[_arrowButton setImage:[UIImage imageNamed:@"gift_bar_count_up_arrow"] forState:UIControlStateSelected];
[_arrowButton addTarget:self action:@selector(arrowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _arrowButton;
}
- (UIButton *)sendGiftButton {
if (!_sendGiftButton) {
_sendGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_sendGiftButton setTitle:@"赠送" forState:UIControlStateNormal];
[_sendGiftButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
[_sendGiftButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
_sendGiftButton.titleLabel.font = [UIFont systemFontOfSize:13];
_sendGiftButton.layer.masksToBounds = YES;
_sendGiftButton.layer.cornerRadius = 15;
[_sendGiftButton addTarget:self action:@selector(sendButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _sendGiftButton;
}
2021-11-15 18:59:44 +08:00
- (UITextField *)editTextFiled {
if (!_editTextFiled) {
_editTextFiled = [[UITextField alloc] init];
NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:@"请输入赠送数额" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17], NSForegroundColorAttributeName:[ThemeColor appMainColor]}];
_editTextFiled.attributedPlaceholder = attribute;
_editTextFiled.borderStyle = UITextBorderStyleNone;
_editTextFiled.returnKeyType = UIReturnKeyDone;
_editTextFiled.delegate = self;
_editTextFiled.textColor = [ThemeColor mainTextColor];
_editTextFiled.keyboardType = UIKeyboardTypeNumberPad;
}
return _editTextFiled;
}
- (UIButton *)sureButton {
if (!_sureButton) {
_sureButton = [[UIButton alloc] init];
[_sureButton setTitle:@"确定" forState:UIControlStateNormal];
_sureButton.titleLabel.textColor = [ThemeColor mainTextColor];
_sureButton.titleLabel.font = [UIFont systemFontOfSize:15];
_sureButton.backgroundColor = [ThemeColor appMainColor];
_sureButton.layer.cornerRadius = 5.0;
_sureButton.layer.masksToBounds = YES;
[_sureButton addTarget:self action:@selector(sendButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _sureButton;
}
- (UIView *)infoView {
if (!_infoView) {
_infoView = [[UIView alloc] init];
_infoView.backgroundColor = [UIColor clearColor];
}
return _infoView;
}
- (UIStackView *)customCountStackView {
if (!_customCountStackView) {
_customCountStackView = [[UIStackView alloc] init];
_customCountStackView.axis = UILayoutConstraintAxisHorizontal;
_customCountStackView.distribution = UIStackViewDistributionEqualSpacing;
_customCountStackView.alignment = UIStackViewAlignmentCenter;
_customCountStackView.spacing = 10;
}
return _customCountStackView;
}
2021-11-10 18:42:27 +08:00
@end