163 lines
5.5 KiB
Objective-C
163 lines
5.5 KiB
Objective-C
//
|
|
// PIInputRedPacketView.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2023/10/18.
|
|
//
|
|
|
|
#import "PIInputRedPacketView.h"
|
|
@interface PIInputRedPacketView()<UITextFieldDelegate>
|
|
///容器
|
|
@property(nonatomic,strong) UIStackView *pi_stackView;
|
|
///红包图标
|
|
@property(nonatomic,strong) UIImageView *pi_iconView;
|
|
///标题
|
|
@property(nonatomic,strong) UILabel *pi_titleView;
|
|
///数量
|
|
@property(nonatomic,strong) MSBaseTextField *pi_textField;
|
|
///分割线
|
|
@property(nonatomic,strong) UIView *pi_lineView;
|
|
///单位
|
|
@property(nonatomic,strong) UILabel *pi_unitView;
|
|
@end
|
|
@implementation PIInputRedPacketView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self installUI];
|
|
[self installConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)installUI{
|
|
[self setCornerWithLeftTopCorner:kGetScaleWidth(8) rightTopCorner:kGetScaleWidth(8) bottomLeftCorner:kGetScaleWidth(8) bottomRightCorner:kGetScaleWidth(8) size:CGSizeMake(kGetScaleWidth(327), kGetScaleWidth(48))];
|
|
self.backgroundColor = UIColorFromRGB(0xF8F8FA);
|
|
[self addSubview:self.pi_stackView];
|
|
[self addSubview:self.pi_textField];
|
|
[self addSubview:self.pi_lineView];
|
|
[self addSubview:self.pi_unitView];
|
|
|
|
[self.pi_stackView addArrangedSubview:self.pi_iconView];
|
|
[self.pi_stackView addArrangedSubview:self.pi_titleView];
|
|
|
|
}
|
|
-(void)installConstraints{
|
|
[self.pi_stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(12));
|
|
make.height.mas_equalTo(kGetScaleWidth(32));
|
|
make.centerY.equalTo(self);
|
|
|
|
}];
|
|
[self.pi_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(kGetScaleWidth(30));
|
|
make.height.mas_equalTo(kGetScaleWidth(32));
|
|
}];
|
|
[self.pi_titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kGetScaleWidth(22));
|
|
}];
|
|
[self.pi_unitView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(16));
|
|
make.centerY.equalTo(self);
|
|
}];
|
|
[self.pi_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(46));
|
|
make.height.mas_equalTo(kGetScaleWidth(26));
|
|
make.width.mas_equalTo(kGetScaleWidth(1));
|
|
make.centerY.equalTo(self);
|
|
|
|
}];
|
|
[self.pi_textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(59));
|
|
make.height.mas_equalTo(kGetScaleWidth(22));
|
|
make.leading.equalTo(self.pi_stackView.mas_trailing).mas_offset(kGetScaleWidth(10));
|
|
make.centerY.equalTo(self);
|
|
}];
|
|
}
|
|
- (void)setPi_title:(NSString *)pi_title{
|
|
_pi_title = pi_title;
|
|
_pi_titleView.text = _pi_title;
|
|
}
|
|
- (void)setIsHiddenIcon:(BOOL)isHiddenIcon{
|
|
_isHiddenIcon = isHiddenIcon;
|
|
_pi_iconView.hidden = _isHiddenIcon;
|
|
}
|
|
-(void)setUnitTitle:(NSString *)unitTitle{
|
|
_unitTitle = unitTitle;
|
|
_pi_unitView.text = _unitTitle;
|
|
}
|
|
#pragma mark -UITextFieldDelegate
|
|
|
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
|
return [self validateNumber:string];
|
|
}
|
|
|
|
- (BOOL)validateNumber:(NSString*)number {
|
|
BOOL res = YES;
|
|
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
|
|
int i = 0;
|
|
while (i < number.length) {
|
|
NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
|
|
NSRange range = [string rangeOfCharacterFromSet:tmpSet];
|
|
if (range.length == 0) {
|
|
res = NO;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
return res;
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (NSString *)redPacketNum{
|
|
return self.pi_textField.text;
|
|
}
|
|
- (UIStackView *)pi_stackView {
|
|
if (!_pi_stackView) {
|
|
_pi_stackView = [[UIStackView alloc] init];
|
|
_pi_stackView.distribution = UIStackViewDistributionFill;
|
|
_pi_stackView.alignment = UIStackViewAlignmentCenter;
|
|
_pi_stackView.spacing = kGetScaleWidth(4);
|
|
}
|
|
return _pi_stackView;
|
|
}
|
|
- (UIImageView *)pi_iconView{
|
|
if(!_pi_iconView){
|
|
_pi_iconView = [UIImageView new];
|
|
_pi_iconView.image = kImage(@"pi_red_packet_icon_logo");
|
|
}
|
|
return _pi_iconView;
|
|
}
|
|
- (UILabel *)pi_titleView{
|
|
if(!_pi_titleView){
|
|
_pi_titleView = [UILabel labelInitWithText:@"" font:kFontRegular(16) textColor:UIColorFromRGB(0x322F4D)];
|
|
}
|
|
return _pi_titleView;
|
|
}
|
|
- (MSBaseTextField *)pi_textField{
|
|
if(!_pi_textField){
|
|
_pi_textField = [[MSBaseTextField alloc]init];
|
|
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:@"0" attributes:@{NSFontAttributeName:kFontRegular(16),NSForegroundColorAttributeName:UIColorFromRGB(0xB3B3C3)}];
|
|
_pi_textField.attributedPlaceholder = placeholder;
|
|
_pi_textField.textColor = UIColorFromRGB(0x322F4D);
|
|
_pi_textField.font = kFontMedium(16);
|
|
_pi_textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_pi_textField.textAlignment = NSTextAlignmentRight;
|
|
_pi_textField.delegate = self;
|
|
}
|
|
return _pi_textField;
|
|
}
|
|
- (UIView *)pi_lineView{
|
|
if(!_pi_lineView){
|
|
_pi_lineView = [UIView new];
|
|
_pi_lineView.backgroundColor = UIColorFromRGB(0xEBEEF5);
|
|
}
|
|
return _pi_lineView;
|
|
}
|
|
- (UILabel *)pi_unitView{
|
|
if(!_pi_unitView){
|
|
_pi_unitView = [UILabel labelInitWithText:@"" font:kFontRegular(16) textColor:UIColorFromRGB(0x767585)];
|
|
}
|
|
return _pi_unitView;
|
|
}
|
|
@end
|