//_____________________________________________________________/
@interface SSGridPwdTF : UITextField
@end
//_____________________________________________________________/
@interface SSNonePerformTF : UITextField
@end
//_____________________________________________________________/
IB_DESIGNABLE
@interface SSGridPwdView : UIView
@property (nonatomic, strong) SSNonePerformTF *inputTF;
@property (nonatomic, strong) SSGridPwdTF *displayTF;
- (void)clearPwd;
@end
#import "SSGridPwdView.h"
//_____________________________________________________________/
@implementation SSGridPwdTF
/******************************************************************************
**** UIView Lifecycle Method ****
******************************************************************************/
#pragma mark -
#pragma mark UIView Lifecycle Method
- (void)initView
{
self.userInteractionEnabled = NO;
self.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.spellCheckingType = UITextSpellCheckingTypeNo;
self.autocorrectionType = UITextAutocorrectionTypeNo;
self.keyboardType = UIKeyboardTypeNumberPad;
self.secureTextEntry = YES;
self.adjustsFontSizeToFitWidth = YES;
self.borderStyle = UITextBorderStyleNone;
//4s CGRectMake(0, 0, (SWidth - 30)/12.0 -4, 50)];
float leftWidth = (SWidth - 30)/12.0 -4;
self.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, leftWidth, 50)];
self.leftView.backgroundColor = [UIColor clearColor];
self.leftViewMode = UITextFieldViewModeAlways;
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self initView];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self initView];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
// Drawing code
UIImage *imgTextfield = [UIImage imageNamed:@"password_deal"];
CGFloat textfieldY = 0;
CGFloat textfieldW = imgTextfield.size.width * YLBScale;
CGFloat textfieldX = 0;
CGFloat textfieldH = imgTextfield.size.height ;
[imgTextfield drawInRect:CGRectMake(textfieldX, textfieldY, textfieldW, textfieldH)];
}
@end
//_____________________________________________________________/
@implementation SSNonePerformTF
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
NSLog(@"%@, %@",sender, NSStringFromSelector(action));
if (action == @selector(cut:))
{
return NO;
}
else if(action == @selector(copy:))
{
return NO;
}
else if(action == @selector(paste:))
{
return NO;
}
else if(action == @selector(select:))
{
return NO;
}
else if(action == @selector(selectAll:))
{
return NO;
}
return NO;
}
@end
//_____________________________________________________________/
@implementation SSGridPwdView
- (void)clearPwd
{
self.inputTF.text = nil;
self.displayTF.text = nil;
}
/******************************************************************************
**** Default Lifecycle Method ****
******************************************************************************/
#pragma mark -
#pragma mark Default Lifecycle Method
- (void)initView
{
UIImage *imgTextfield = [UIImage imageNamed:@"password_deal"];
if (self.inputTF == nil)
{
CGRect inputFrm = CGRectMake(0, 0, imgTextfield.size.width * YLBScale , 50);
self.inputTF = [[SSNonePerformTF alloc] initWithFrame:inputFrm];
self.inputTF.secureTextEntry = YES;
self.inputTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.inputTF.autocorrectionType = UITextAutocorrectionTypeNo;
self.inputTF.spellCheckingType = UITextSpellCheckingTypeNo;
self.inputTF.adjustsFontSizeToFitWidth = YES;
self.inputTF.keyboardType = UIKeyboardTypeNumberPad;
}
[self addSubview:self.inputTF];
if (self.displayTF == nil)
{
CGRect displayFrm = CGRectMake(0, 0, imgTextfield.size.width *YLBScale +40 , 50);
self.displayTF = [[SSGridPwdTF alloc] initWithFrame:displayFrm];
float width = [self getKernWidth];
self.displayTF.defaultTextAttributes = @{NSKernAttributeName:@(width)};//4s:45
self.displayTF.backgroundColor = [UIColor whiteColor];
}
[self addSubview:self.displayTF];
}
- (float)getKernWidth{
float width = 0.0;
if (IsIphone4) {
width = 38.3;
}else if (IsIphone5){
width = 38.6;
}else if (IsIphone6){
width = 47.5;
}else if (IsIphone6p){
width = 53.0;
}else{
width = 47.5;
}
return width;
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self initView];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self initView];
}
return self;
}
@end