145 lines
4.6 KiB
Mathematica
145 lines
4.6 KiB
Mathematica
|
|
//
|
||
|
|
// PYInputView.m
|
||
|
|
// Food
|
||
|
|
//
|
||
|
|
// Created by ko1o on 2019/7/16.
|
||
|
|
// Copyright © 2019年 ko1o. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "PYInputView.h"
|
||
|
|
#import "AmountKeyboard.h"
|
||
|
|
|
||
|
|
@interface PYInputView()
|
||
|
|
|
||
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
||
|
|
|
||
|
|
@property (nonatomic, strong) UIImageView *pickerView;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation PYInputView
|
||
|
|
|
||
|
|
+ (instancetype)inputViewWithType:(PYInputViewType)type
|
||
|
|
keyboardType:(UIKeyboardType)keyboardType
|
||
|
|
title:(NSString *)title
|
||
|
|
placeholder:(NSString *)placeholder
|
||
|
|
unit:(NSString *)unit
|
||
|
|
{
|
||
|
|
PYInputView *inputView = [[PYInputView alloc] init];
|
||
|
|
inputView.width = SCREEN_WIDTH - FIX_SIZE(32.0) * 2;
|
||
|
|
inputView.height = FIX_SIZE(50.0);
|
||
|
|
inputView.type = type;
|
||
|
|
inputView.centerX = SCREEN_WIDTH * 0.5;
|
||
|
|
|
||
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
||
|
|
titleLabel.height = inputView.height;
|
||
|
|
titleLabel.font = NORMAL_FONT;
|
||
|
|
titleLabel.textColor = COLOR_WITH_RGB(0x222222);
|
||
|
|
titleLabel.width = 0.0;
|
||
|
|
titleLabel.text = title;
|
||
|
|
[inputView addSubview:titleLabel];
|
||
|
|
inputView.titleLabel = titleLabel;
|
||
|
|
UITextField *textField = [[UITextField alloc] init];
|
||
|
|
textField.width = inputView.width;
|
||
|
|
textField.height = FIX_SIZE(44.0);
|
||
|
|
textField.placeholder = placeholder;
|
||
|
|
textField.keyboardType = keyboardType;
|
||
|
|
if (keyboardType ==UIKeyboardTypeDecimalPad) {
|
||
|
|
AmountKeyboard *keyboard = [AmountKeyboard initWithTextField:textField];
|
||
|
|
keyboard.changeTextBlock = ^(NSString *text) {
|
||
|
|
textField.text = text;
|
||
|
|
};
|
||
|
|
|
||
|
|
}
|
||
|
|
textField.font = MT_FONT_REGULAR_SIZE(15.0);
|
||
|
|
textField.textColor = COLOR_WITH_RGB(0x111111);
|
||
|
|
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
||
|
|
[inputView addSubview:textField];
|
||
|
|
inputView.textField = textField;
|
||
|
|
textField.centerY = inputView.height * 0.5;
|
||
|
|
|
||
|
|
UILabel *unitLabel = [[UILabel alloc] init];
|
||
|
|
unitLabel.font = SMALL_FONT;
|
||
|
|
unitLabel.textColor = TITLE_COLOR;
|
||
|
|
unitLabel.text = unit;
|
||
|
|
[unitLabel sizeToFit];
|
||
|
|
unitLabel.centerY = textField.centerY;
|
||
|
|
[inputView addSubview:unitLabel];
|
||
|
|
|
||
|
|
UIView *lineView = [[UIView alloc] init];
|
||
|
|
lineView.width = inputView.width;
|
||
|
|
lineView.height = 0.5;
|
||
|
|
lineView.backgroundColor = COLOR_WITH_RGB(0xEEEEEE);
|
||
|
|
lineView.bottom = inputView.bottom;
|
||
|
|
[inputView addSubview:lineView];
|
||
|
|
inputView.lineView = lineView;
|
||
|
|
|
||
|
|
UIImageView *pickerView = [[UIImageView alloc] init];
|
||
|
|
pickerView.image = ImageNamed(@"arrow_down");
|
||
|
|
pickerView.size = CGSizeMake(15, 15);
|
||
|
|
[inputView addSubview:pickerView];
|
||
|
|
inputView.pickerView = pickerView;
|
||
|
|
pickerView.hidden = YES;
|
||
|
|
pickerView.centerY = inputView.height * 0.5;
|
||
|
|
pickerView.right = inputView.width - 10;
|
||
|
|
if (type == PYInputViewTypeVerifyCode) {
|
||
|
|
// PYGetSmsCodeButton *smsCodeButton = [PYGetSmsCodeButton smsCodeButtonWithColor:COLOR_WITH_RGB(0xffa64c) type:PYGetSMSCodeTypeRegister];
|
||
|
|
// smsCodeButton.right = inputView.width;
|
||
|
|
// smsCodeButton.centerY = inputView.height * 0.5;
|
||
|
|
// textField.width = smsCodeButton.x - textField.x - 10;
|
||
|
|
// textField.keyboardType = UIKeyboardTypeNumberPad;
|
||
|
|
// [textField mt_setupLimitTextFieldWithBytesLength:6 delegate:nil];
|
||
|
|
// [inputView addSubview:smsCodeButton];
|
||
|
|
// inputView.smsCodeButton = smsCodeButton;
|
||
|
|
} else if (type == PYInputViewTypeForm) {
|
||
|
|
[titleLabel sizeToFit];
|
||
|
|
titleLabel.width = MAX(65, titleLabel.width);
|
||
|
|
titleLabel.height = inputView.height;
|
||
|
|
textField.left = titleLabel.right;
|
||
|
|
textField.width = inputView.width - textField.x - 10;
|
||
|
|
|
||
|
|
if (unit.length) {
|
||
|
|
unitLabel.right = inputView.width - 10;
|
||
|
|
textField.width = unitLabel.left - textField.x;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return inputView;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)setEnablePick:(BOOL)enablePick
|
||
|
|
{
|
||
|
|
_enablePick = enablePick;
|
||
|
|
self.pickerView.hidden = !enablePick;
|
||
|
|
|
||
|
|
self.textField.clearButtonMode = enablePick ? UITextFieldViewModeNever : UITextFieldViewModeWhileEditing;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)setTitleWidth:(CGFloat)titleWidth
|
||
|
|
{
|
||
|
|
self.titleLabel.width = titleWidth;
|
||
|
|
self.textField.x = self.titleLabel.right;
|
||
|
|
self.textField.width = self.width - self.textField.x - 10;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)setLead:(PYInputViewLineLead)lead
|
||
|
|
{
|
||
|
|
_lead = lead;
|
||
|
|
switch (lead) {
|
||
|
|
case PYInputViewLineLeadTitle:
|
||
|
|
_lineView.x = _titleLabel.x;
|
||
|
|
break;
|
||
|
|
case PYInputViewLineLeadField:
|
||
|
|
_lineView.x = _textField.x;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
_lineView.width = self.width - _lineView.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (NSString *)text
|
||
|
|
{
|
||
|
|
return self.textField.text;
|
||
|
|
}
|
||
|
|
@end
|