AUInputBox is a single-line input box that supports the arrangement of a title on the left side and an image button on the right side.
API description
typedef NS_ENUM(NSInteger, AUInputBoxType)
{
AUInputBoxTypeMobileNumber, // Mobile phone number
AUInputBoxTypeCreditCard, // Credit card
AUInputBoxTypeBankCard, // Debit card
AUInputBoxTypeAmount, // Amount
AUInputBoxTypeIDNumber, // ID card
AUInputBoxTypeNotEmpty, // Not empty
AUInputBoxTypeAlipayAccount, // mPaaS app account
AUInputBoxTypeNone // No authentication
};
typedef enum AUInputBoxStyle
{
AUInputBoxStyleNone, // No background image.
AUInputBoxStyleiOS6, // Rounded background image.
AUInputBoxStyleiOS7 // Non-rounded background image.
} AUInputBoxStyle;
/**
The single-line input box with title text and a button image.
*/
@interface AUInputBox : UIView
#pragma mark - AUInputBox property.
// The text input box.
@property(strong, nonatomic) AUTextField *textField;
@property(strong, nonatomic) NSString *textFieldText;
@property(strong, nonatomic) NSString *textFieldFormat;
@property(assign, nonatomic) CGFloat horizontalMargin;
@property(assign, nonatomic) CGFloat textFieldHorizontalMargin;
// The button.
@property(strong, nonatomic) UIButton *iconButton;
@property(assign, nonatomic) BOOL hidesButtonWhileNotEmpty;
@property(assign, nonatomic) BOOL hidesButton;
// The label displayed on the left part of the input box.
@property(nonatomic, readonly) UILabel *titleLabel;
@property(nonatomic, assign) CGFloat titleLabelWidth;
The style, authenticator, background image, and input box type.
@property(assign, nonatomic) AUInputBoxStyle style;
@property(readonly, nonatomic) UIImageView *backgroundImage;
@property(assign, nonatomic) AUInputBoxType inputBoxType;
#pragma mark - The AUInputBox static method.
/**
* Create an input box component.
* @param originY The Y coordinator of the input box.
* @param type The type of the text input box.
* @return The input box component.
*/
+ (instancetype)inputboxWithOriginY:(CGFloat)originY inputboxType:(AUInputBoxType)type;
/**
* Create an input box component with an icon button.
* @param originY The Y coordinator of the input box.
* @param icon The icon on the button, 44x44.
* @param type The type of the text input box.
* @return The input box component with a button.
*/
+ (instancetype)inputboxWithOriginY:(CGFloat)originY buttonIcon:(UIImage *)icon inputboxType:(AUInputBoxType)type;
/**
* @return The control height. The default value is 44. The value is 47 for iPhone6 plus.
*/
+ (float)heightOfControl;
#pragma mark - The AUInputBox instance method.
- (instancetype)initWithFrame:(CGRect)frame inputboxType:(AUInputBoxType)type;
- (void)buildIconButton:(UIImage *)icon;
/**
* Add a space to the text in the specified format.
* @param text The text content.
* @return The text to which a space has been added.
*/
- (NSString *)formatText:(NSString *)text;
/**
* Add an icon by using this method for inputBox without any icon specified during the initialization.
* @param icon The icon on the button.
*
*/
- (void)setRightButtonIcon:(UIImage *)icon;
/**
* Check the input validity.
*/
- (BOOL)checkInputValidity;
/**
* Filter text. Only digits are allowed. The maximum length is specified.
* The parameter is the delegate parameter and the maximum length is specified by maxLength.
*/
- (BOOL)shouldChangeRange:(NSRange)range replacementString:(NSString *)string withMaxLength:(int)maxLength;
/**
* Specify the maximum length.
* @maxLength Maximum length, excluding format spaces.
*/
- (BOOL)shouldChangeRange:(NSRange)range replacementString:(NSString *)string withFormatStringMaxLength:(int)maxLength;
Code sample
Single-line input box
AUInputBox *inputBox = [AUInputBox inputboxWithOriginY:startY inputboxType:AUInputBoxTypeNone]; inputBox.titleLabel.text = @"Label"; inputBox.textField.placeholder = @"Please enter text as prompted"; [self.view addSubview:inputBox];
Icon
AUInputBox *iconInputBox = [AUInputBox inputboxWithOriginY:startY buttonIcon:image inputboxType:AUInputBoxTypeNone]; iconInputBox.titleLabel.text = @"Label"; iconInputBox.textField.placeholder = @"Please enter text as prompted"; [self.view addSubview:iconInputBox];