6位密码输入框

#import <UIKit/UIKit.h>

//_____________________________________________________________/

@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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值