Commit ea061a49 authored by Steven杜宇's avatar Steven杜宇

// add 验证码输入框

parent ecf52386
......@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
04F526AF2B32D4B600FC6CE6 /* YHPersonalCenterCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F526AE2B32D4B600FC6CE6 /* YHPersonalCenterCell.swift */; };
04F526C12B3A657000FC6CE6 /* YHValidateCodeInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F526C02B3A657000FC6CE6 /* YHValidateCodeInputView.swift */; };
04FAC5432B32BA5F00D24B36 /* YHHomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04FAC5422B32BA5F00D24B36 /* YHHomeViewController.swift */; };
04FAC5452B32BA7000D24B36 /* YHMyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04FAC5442B32BA7000D24B36 /* YHMyViewController.swift */; };
04FAC54A2B32CF1000D24B36 /* YHNetRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04FAC5492B32CF1000D24B36 /* YHNetRequest.swift */; };
......@@ -78,6 +79,7 @@
/* Begin PBXFileReference section */
04F526AE2B32D4B600FC6CE6 /* YHPersonalCenterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPersonalCenterCell.swift; sourceTree = "<group>"; };
04F526BF2B39733000FC6CE6 /* galaxy-Bridge-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "galaxy-Bridge-Header.h"; sourceTree = "<group>"; };
04F526C02B3A657000FC6CE6 /* YHValidateCodeInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHValidateCodeInputView.swift; sourceTree = "<group>"; };
04FAC5422B32BA5F00D24B36 /* YHHomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHHomeViewController.swift; sourceTree = "<group>"; };
04FAC5442B32BA7000D24B36 /* YHMyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMyViewController.swift; sourceTree = "<group>"; };
04FAC5492B32CF1000D24B36 /* YHNetRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHNetRequest.swift; sourceTree = "<group>"; };
......@@ -164,6 +166,7 @@
isa = PBXGroup;
children = (
04F526AE2B32D4B600FC6CE6 /* YHPersonalCenterCell.swift */,
04F526C02B3A657000FC6CE6 /* YHValidateCodeInputView.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -633,6 +636,7 @@
A52DF2402B3316A0006618D6 /* YHBouncesContentView.swift in Sources */,
A52DF2362B330A21006618D6 /* YHBaseViewController.swift in Sources */,
A52DF0BF2B330A20006618D6 /* Date-Extension.swift in Sources */,
04F526C12B3A657000FC6CE6 /* YHValidateCodeInputView.swift in Sources */,
A52DF0CD2B330A20006618D6 /* BsGestureTableView.swift in Sources */,
A52DF0DD2B330A20006618D6 /* BsConstant.swift in Sources */,
A52DF2512B33177F006618D6 /* BsHUDErrorView.swift in Sources */,
......
......@@ -19,7 +19,7 @@ struct PersonalModuleItem {
}
}
class YHMyViewController: YHBaseViewController {
class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect.zero, style:.plain)
tableView.backgroundColor = UIColor.red
......@@ -42,9 +42,23 @@ class YHMyViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableView);
tableView.snp.makeConstraints { make in
make.left.right.top.bottom.equalTo(view)
// view.addSubview(tableView);
// tableView.snp.makeConstraints { make in
// make.left.right.top.bottom.equalTo(view)
// }
let bgImgView = UIImageView(image: UIImage(named: "launch_screen_image"))
view.addSubview(bgImgView)
bgImgView.snp.makeConstraints { make in
make.edges.equalTo(self.view)
}
let inputView = YHValidateCodeInputView(count: 6, inputWith: 40, inputHeight: 60, gap: 10)
view.addSubview(inputView)
inputView.snp.makeConstraints { make in
make.left.right.equalTo(self.view)
make.top.equalTo(self.view.snp.top).offset(100)
make.height.equalTo(100)
}
}
}
......
//
// YHValidateCodeInputView.swift
// galaxy
//
// Created by edy on 2023/12/26.
//
import UIKit
// 单个输入框组件
class YHValidateCodeComponentView : UIView {
var bgView : UIView
var textField : UITextField
override init(frame: CGRect) {
bgView = UIView()
bgView.backgroundColor = UIColor(white: 1, alpha: 0.3)
bgView.layer.cornerRadius = 4
bgView.clipsToBounds = true
textField = UITextField()
textField.font = UIFont.systemFont(ofSize: 20)
textField.textColor = UIColor.white
textField.tintColor = UIColor.black
textField.tag = 999
textField.text = "*"
super.init(frame: frame)
bgView.addSubview(textField)
self.addSubview(bgView)
bgView.snp.makeConstraints { make in
make.edges.equalTo(self)
}
textField.snp.makeConstraints { make in
make.top.equalTo(self).offset(5)
make.bottom.equalTo(self).offset(-5)
make.width.equalTo(15)
make.center.equalTo(self)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class YHValidateCodeInputView: UIView {
let baseTag = 9527
// 小输入框个数
var count:Int = 0
// 小输入框宽度
var inputWidth = 40.0
// 小输入框长度
var inputHeight = 40.0
// 小输入框间距
var gap = 8.0
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
convenience init(count:Int, inputWith:Double, inputHeight:Double, gap:Double) {
self.init(frame: CGRectZero)
self.count = count
self.inputWidth = inputWith
self.inputHeight = inputHeight
self.gap = gap
self.setupUI()
}
// static func createInputView(count:Int) -> YHValidateCodeInputView {
// let view = YHValidateCodeInputView()
// view.count = count;
// view.setupUI()
// return view
// }
func setupUI() {
// 输入框个数是否为偶数
let isEven = (count % 2 == 0)
for index in 1...count {
let inputView = YHValidateCodeComponentView(frame: CGRectZero)
inputView.tag = baseTag + index
self.addSubview(inputView)
// 小组件右边距离父视图中轴线间距
var rightMargin = 0.0;
if (isEven) { // 输入框个数为偶数
let middle = count/2
if (index <= middle) {
rightMargin = -(Double(middle-index)*(gap+inputWidth) + gap/2.0)
} else {
rightMargin = Double(index-middle-1)*(gap+inputWidth) + gap/2.0+inputWidth
}
print(rightMargin)
inputView.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: inputWidth, height: inputHeight))
make.centerY.equalTo(self)
make.right.equalTo(self.snp.centerX).offset(rightMargin)
}
} else { // // 输入框个数为奇数
let middle:Int = count/2 + 1
if (index < middle) {
rightMargin = -(Double(middle-index-1)*(gap+inputWidth) + inputWidth/2.0+gap)
} else if (index > middle) {
rightMargin = (Double(index-middle-1)*(gap+inputWidth) + inputWidth*3/2.0+gap)
}
print(rightMargin)
inputView.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: inputWidth, height: inputHeight))
make.centerY.equalTo(self)
if (index == middle) {
make.centerX.equalTo(self)
} else {
make.right.equalTo(self.snp.centerX).offset(rightMargin)
}
}
}
}
}
func interactive() {
for index in 1...count {
let component = self.viewWithTag(baseTag+index) as! YHValidateCodeComponentView
let textField = component.viewWithTag(999) as! UITextField
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment