美文网首页
支付密码框

支付密码框

作者: 薰衣草儿 | 来源:发表于2017-02-08 17:50 被阅读48次

做支付,大多时候需要都是一个六位数的密码界面,闲来无事,就写了个小demo.话不多说,开代码

在密码输入框的.h文件中

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)#define boxWidth (SCREEN_WIDTH -70)/6 //密码框的宽度

@class PassWordView;@protocol PassWordViewDelegate

@optional

- (void)passwordView:(PassWordView *)passwordView withPasswordString:(NSString *)password;

@end

@interface PassWordView : UIView@property (nonatomic,assign)id delegate;

- (instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title;

//标题

@property (nonatomic,strong)UILabel *label_title;

@property (nonatomic,strong)UITextField *textField;

//假的输入框

@property (nonatomic,strong)UIView *viewBox1;

@property (nonatomic,strong)UIView *viewBox2;

@property (nonatomic,strong)UIView *viewBox3;

@property (nonatomic,strong)UIView *viewBox4;

@property (nonatomic,strong)UIView *viewBox5;

@property (nonatomic,strong)UIView *viewBox6;

//密码点

@property (nonatomic,strong)UILabel *labelPoint1;

@property (nonatomic,strong)UILabel *labelPoint2;

@property (nonatomic,strong)UILabel *labelPoint3;

@property (nonatomic,strong)UILabel *labelPoint4;

@property (nonatomic,strong)UILabel *labelPoint5;

@property (nonatomic,strong)UILabel *labelPoint6;

@end

.m文件中

@implementation PassWordView

- (instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title{

self = [super initWithFrame:frame];

if (self) {

//标题

_label_title = [[UILabel alloc] init];

_label_title.frame = CGRectMake(0, 20, SCREEN_WIDTH, 20);

_label_title.text = title;

_label_title.textAlignment = NSTextAlignmentCenter;

_label_title.textColor = [UIColor grayColor];

[self addSubview:_label_title];

//textFiled

_textField = [[UITextField alloc] init];

_textField.frame = CGRectMake(0, 0, 0, 0);

_textField.delegate = self;

_textField.keyboardType = UIKeyboardTypeNumberPad;

[_textField addTarget:self action:@selector(textFiledDidChange:) forControlEvents:UIControlEventEditingChanged];

[self addSubview:_textField];

//假的输入框

_viewBox1 = [self creatFalseTextFiledWithFrame:CGRectMake(10, 60, boxWidth, boxWidth)];

[self addSubview:_viewBox1];

_viewBox2 = [self creatFalseTextFiledWithFrame:CGRectMake(20+boxWidth*1, _viewBox1.frame.origin.y, boxWidth, boxWidth)];

[self addSubview:_viewBox2];

_viewBox3 = [self creatFalseTextFiledWithFrame:CGRectMake(30+boxWidth*2, _viewBox1.frame.origin.y, boxWidth, boxWidth)];

[self addSubview:_viewBox3];

_viewBox4 = [self creatFalseTextFiledWithFrame:CGRectMake(40+boxWidth*3, _viewBox1.frame.origin.y, boxWidth, boxWidth)];

[self addSubview:_viewBox4];

_viewBox5 = [self creatFalseTextFiledWithFrame:CGRectMake(50+boxWidth*4, _viewBox1.frame.origin.y, boxWidth, boxWidth)];

[self addSubview:_viewBox5];

_viewBox6 = [self creatFalseTextFiledWithFrame:CGRectMake(60+boxWidth*5, _viewBox1.frame.origin.y, boxWidth, boxWidth)];

[self addSubview:_viewBox6];

//密码点

_labelPoint1 = [self creatPasswordPointWithSuperView:_viewBox1];

_labelPoint2 = [self creatPasswordPointWithSuperView:_viewBox2];

_labelPoint3 = [self creatPasswordPointWithSuperView:_viewBox3];

_labelPoint4 = [self creatPasswordPointWithSuperView:_viewBox4];

_labelPoint5 = [self creatPasswordPointWithSuperView:_viewBox5];

_labelPoint6 = [self creatPasswordPointWithSuperView:_viewBox6];

}

return self;

}

//创建假的输入框

- (UIView *)creatFalseTextFiledWithFrame:(CGRect)frame{

UIView *view = [[UIView alloc] initWithFrame:frame];

[view.layer setBorderWidth:1.0];

view.layer.borderColor = [[UIColor grayColor] CGColor];

return view;

}

这个非常简单 ,因为我也是菜鸟一枚,有什么错误的地方还请各位大神多多指教

下面是demo连接:http://www.jianshu.com/writer#/notebooks/8035700/notes/8516833

效果如下

相关文章

网友评论

      本文标题:支付密码框

      本文链接:https://www.haomeiwen.com/subject/apxbittx.html