源码参考
<h5>
支付密码---样式虽然不好看,但是麻雀虽小五脏俱全:
Pay_TextField 类, 定义键盘框
Pay_maskView 类键盘框及上面的信息。
代理方法:输入密码之后去网络请求
- (void)Pay_maskViewPassWord:(NSString *)password;
</h5>
<h6>
Pay_maskView.h:类
</h6>
<pre>
/*清空字符串/
- (void)removeTextField;
实例化键盘框
+(Pay_maskView *)showWithDelegateOwer:( id) target andAddView:(UIView *)view;
</pre>
<h6>
Pay_maskView.m:类 设置 输入框的样式 修改框的颜色
define LinebgColor [UIColor redColor]
define DotLabelbgColor [UIColor redColor]
</h6>
<pre>
// 监听键盘-
(void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardChangeFrame:)
name:UIKeyboardWillChangeFrameNotification object:nil];
}-
(void)keyboardChangeFrame:(NSNotification *)note
{
// 0.取出键盘动画的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];// 1.取得键盘最后的frame
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];// 2.计算控制器的view需要平移的距离
CGFloat transformY = keyboardFrame.origin.y - self.frame.size.height;// 3.执行动画
[UIView animateWithDuration:duration animations:^{
self.transform = CGAffineTransformMakeTranslation(0, transformY);
}];
}
</pre>
<h6>
Pay_TextField 输入框的属性样式
</h6>
<pre>
-
(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.layer.borderColor = [UIColor redColor].CGColor;
self.layer.borderWidth = 1;
self.tintColor = [UIColor clearColor];
self.textColor = [UIColor clearColor];
self.keyboardType = UIKeyboardTypeNumberPad;
CGFloat Width = self.frame.size.width / kPasswordLength;
for (int i = 0; i < kPasswordLength; i++) {CGFloat lineX = i \* Width; CGFloat lineY = 0; CGFloat lineW = 1; CGFloat lineH = self.frame.size.height; UIView \*line = [[UIView alloc] init]; line.backgroundColor = LinebgColor; line.frame = CGRectMake(lineX, lineY, lineW, lineH); [self addSubview:line]; UILabel \*dotLabel = [[UILabel alloc] init]; CGFloat dotLabelW = 10; CGFloat dotLabelH = 10; CGFloat dotLabelX = lineX + (Width - dotLabelW) \* 0.5; CGFloat dotLabelY = (lineH - dotLabelH) \* 0.5; dotLabel.frame = CGRectMake(dotLabelX, dotLabelY, dotLabelW, dotLabelH); dotLabel.layer.masksToBounds = YES; dotLabel.layer.cornerRadius = dotLabelW \* 0.5; dotLabel.backgroundColor = DotLabelbgColor; dotLabel.hidden = YES; dotLabel.tag = kDotTag + i; [self addSubview:dotLabel]; } UIView \*view = [[UIView alloc] init]; view.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); view.userInteractionEnabled = NO; view.backgroundColor = [UIColor clearColor]; [self addSubview:view];
}
return self;
}
</pre>