Commit 02cbef0a authored by lujunye's avatar lujunye

登录页面完成(待验证码背景图片)

parent 5cb119aa
......@@ -18,6 +18,7 @@
E01C26B12446989700ADCC70 /* Interface_Z.plist in Resources */ = {isa = PBXBuildFile; fileRef = E01C26B02446989700ADCC70 /* Interface_Z.plist */; };
E01C26B62446AF3100ADCC70 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E01C26B42446AF3100ADCC70 /* DemoViewController.swift */; };
E01C26B72446AF3100ADCC70 /* DemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E01C26B52446AF3100ADCC70 /* DemoViewController.xib */; };
E088CC8D24470BF0000DAA8A /* CodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E088CC8C24470BF0000DAA8A /* CodeView.swift */; };
E09B03A12445AF7100211A51 /* Define.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03A02445AF7100211A51 /* Define.swift */; };
E09B03A32445AF9500211A51 /* NetworkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03A22445AF9500211A51 /* NetworkRequest.swift */; };
E09B03A72445B04E00211A51 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09B03A52445B04D00211A51 /* BaseViewController.swift */; };
......@@ -70,6 +71,7 @@
E01C26B42446AF3100ADCC70 /* DemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = "<group>"; };
E01C26B52446AF3100ADCC70 /* DemoViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DemoViewController.xib; sourceTree = "<group>"; };
E01C26BA2446D68500ADCC70 /* Bridge_Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Bridge_Header.h; sourceTree = "<group>"; };
E088CC8C24470BF0000DAA8A /* CodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeView.swift; sourceTree = "<group>"; };
E09B03A02445AF7100211A51 /* Define.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Define.swift; sourceTree = "<group>"; };
E09B03A22445AF9500211A51 /* NetworkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkRequest.swift; sourceTree = "<group>"; };
E09B03A52445B04D00211A51 /* BaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
......@@ -152,6 +154,7 @@
E00D85DD244561FD00F5F816 /* GeliBusinessPlatform */ = {
isa = PBXGroup;
children = (
E088CC882446FFA1000DAA8A /* Other */,
E01C26B32446AEF800ADCC70 /* DEMO */,
E09B03B32445B19400211A51 /* Interface */,
E09B03AD2445B0BA00211A51 /* ViewController */,
......@@ -203,6 +206,22 @@
path = DEMO;
sourceTree = "<group>";
};
E088CC882446FFA1000DAA8A /* Other */ = {
isa = PBXGroup;
children = (
E088CC8B2446FFB5000DAA8A /* 验证码 */,
);
path = Other;
sourceTree = "<group>";
};
E088CC8B2446FFB5000DAA8A /* 验证码 */ = {
isa = PBXGroup;
children = (
E088CC8C24470BF0000DAA8A /* CodeView.swift */,
);
path = "验证码";
sourceTree = "<group>";
};
E09B039E2445AEF800211A51 /* Appdelegate */ = {
isa = PBXGroup;
children = (
......@@ -484,6 +503,7 @@
E01C26B62446AF3100ADCC70 /* DemoViewController.swift in Sources */,
E09B03A32445AF9500211A51 /* NetworkRequest.swift in Sources */,
E09B03A72445B04E00211A51 /* BaseViewController.swift in Sources */,
E088CC8D24470BF0000DAA8A /* CodeView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -9,10 +9,10 @@
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.517",
"red" : "0.180",
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000"
"blue" : "0.180",
"green" : "0.180"
}
}
}
......
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.651",
"alpha" : "1.000",
"blue" : "0.878",
"green" : "0.757"
}
}
}
]
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.388",
"alpha" : "1.000",
"blue" : "0.902",
"green" : "0.624"
}
}
}
]
}
\ No newline at end of file
{
"properties" : {
"localizable" : true
},
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.278",
"alpha" : "1.000",
"blue" : "0.890",
"green" : "0.561"
}
}
}
]
}
\ No newline at end of file
......@@ -10,4 +10,5 @@
#define Bridge_Header_h
#import "MJRefresh.h"
#import "WYHead.h"
#endif /* Bridge_Header_h */
//
// CodeView.swift
// GeliBusinessPlatform
//
// Created by 刘俊宏 on 2020/4/15.
// Copyright © 2020 junye lu. All rights reserved.
//例子
//let codeV = CaptchaView(frame: CGRect(x: 10, y: 200, width: 100, height: 50))
//self.view.addSubview(codeV);
//print("验证码\(codeV.changeString)")
//背景图-- codeBgImg
//当前边框颜色为灰色
import UIKit
import Hue
// MARK: 基本的样式
struct CaptchaViewStytel {
/// 随机颜色
var kRandomColor:UIColor{
return UIColor.init(red: CGFloat(Float(255)/255.0), green: CGFloat(Float(255)/255.0), blue: CGFloat(Float(255)/255.0), alpha: 1.0)
}
/// 线数量
var kLineCount = 6
/// 线宽
var kLineWidth = 1.0
/// 字符数量
var kCharCount = 4
/// 随机字体大小
var kFontSize:UIFont?{
return UIFont.boldSystemFont(ofSize: CGFloat(Float(arc4random()%5) + 18))
}
/// 随机字体颜色
var kFontColor:UIColor{
return UIColor.init(red: CGFloat(Float(arc4random()%255)/255.0), green: CGFloat(Float(arc4random()%255)/255.0), blue: CGFloat(Float(arc4random()%255)/255.0), alpha: 1.0)
}
}
class CaptchaView: UIView {
/// 字符素材数组
var changeArray: NSArray?
/// 验证码的字符串
var changeString: String?
/// 基本样式
var stytel:CaptchaViewStytel!
override init(frame: CGRect) {
super.init(frame: frame)
// 初始化
self.setUpUI()
// 显示一个随机验证码
self.changeCaptcha()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: 初始化
func setUpUI() -> Void {
let stytel = CaptchaViewStytel()
self.stytel = stytel
// let bgImg = UIImage.init(named: "codeBgImg")
// self.backgroundColor = UIColor.init(patternImage: bgImg!)
//设置layer圆角半径
self.layer.cornerRadius = 5.0
//隐藏边界
self.layer.masksToBounds = false
self.layer.borderWidth = 1
self.layer.borderColor = UIColor.gray.cgColor
}
// MARK: 布局约束
override func layoutSubviews() {
super.layoutSubviews()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// self.backgroundColor = stytel.kRandomColor
//点击界面,切换验证码
self.changeCaptcha()
//setNeedsDisplay调用drawRect方法来实现view的绘制
self.setNeedsDisplay()
}
// MARK: 显示一个随机验证码
func changeCaptcha(){
// 从字符数组中随机抽取相应数量的字符,组成验证码字符串
// 数组中存放的是全部可选的字符,可以是字母,也可以是中文
let changeArray = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
self.changeArray = changeArray as NSArray
self.changeString = String()
// 随机从数组中选取需要个数的字符,然后拼接为一个字符串
for _ in 0..<stytel.kCharCount {
let index = arc4random()%(UInt32(changeArray.count - 1))
let getStr = changeArray[Int(index)]
self.changeString = "\(self.changeString!)\(getStr)"
}
// 从网络获取字符串,然后把得到的字符串在本地绘制出来(网络获取步骤在这省略)
print("\(self.changeString!)")
}
// MARK:绘制界面(1.UIView初始化后自动调用; 2.调用setNeedsDisplay方法时会自动调用)
override func draw(_ rect: CGRect) {
// 重写父类方法,首先要调用父类的方法
super.draw(rect)
//设置随机背景颜色
// self.backgroundColor = stytel.kRandomColor
//获得要显示验证码字符串,根据长度,计算每个字符显示的大概位置
let text = self.changeString
let cSize = NSString(string: "S").size(withAttributes: [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 20)])
// 每个字符显示宽度的位置
let width = (rect.size.width / CGFloat(text!.count)) - CGFloat(cSize.width)
// 每个字符所显示高度位置
let height = rect.size.height - cSize.height
var point: CGPoint
//依次绘制每一个字符,可以设置显示的每个字符的字体大小、颜色、样式等
var pX,PY: CGFloat
for i in 0..<text!.count {
pX = CGFloat(Float(arc4random()%UInt32(width))) + rect.size.width / CGFloat(text!.count)*CGFloat(i)
PY = CGFloat(Float(arc4random()%UInt32(height)))
point = CGPoint(x: pX, y: PY)
let texta = text! as NSString
let c = texta.character(at: i)
let textC = NSString(format: "%C", c)
textC.draw(at: point, withAttributes: [NSAttributedString.Key.font : stytel.kFontSize!,NSAttributedString.Key.foregroundColor : stytel.kFontColor])
}
//调用drawRect:之前,系统会向栈中压入一个CGContextRef,调用UIGraphicsGetCurrentContext()会取栈顶的CGContextRef
let context = UIGraphicsGetCurrentContext()
// 设置画线宽度
context?.setLineWidth(CGFloat(stytel!.kLineWidth))
// 绘制干扰的彩色直线
for _ in 0..<stytel.kLineCount {
// 设置线的随机颜色
context?.setStrokeColor(stytel!.kRandomColor.cgColor)
// 设置线的起点
pX = CGFloat(Float(arc4random()%UInt32(rect.size.width)))
PY = CGFloat(Float(arc4random()%UInt32(rect.size.height)))
context?.move(to: CGPoint(x: pX, y: PY))
//设置线终点
pX = CGFloat(Float(arc4random()%UInt32(rect.size.width)))
PY = CGFloat(Float(arc4random()%UInt32(rect.size.height)))
context?.addLine(to: CGPoint(x: pX, y: PY))
// 画线
context?.strokePath()
}
}
}
......@@ -9,7 +9,7 @@
import UIKit
import Alamofire
import CryptoSwift
import LGButton
class LoginViewController: BaseViewController {
......@@ -20,22 +20,31 @@ let vc = DemoViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
//MARK: - 输入账号、密码
@IBAction func loginAction(_ sender: LGButton) {
print("loginAction")
}
//MARK: - 输入账号、密码、验证码
@IBOutlet weak var codeView: UIView!
@IBOutlet weak var phoneTF: UITextField!
@IBOutlet weak var passTF: UITextField!
@IBOutlet weak var codeTF: UITextField!
//MARK: - viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let codeV = CaptchaView(frame:codeView.bounds)
codeView.addSubview(codeV);
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
......
source 'http://git.oschina.net/akuandev/Specs.git'
platform :ios, '9.0'
inhibit_all_warnings!
......@@ -25,4 +23,5 @@ pod 'SkeletonView'
pod 'RealmSwift'
pod 'SnapKit'
pod 'LGButton'
pod 'WYAutoLayout'
end
\ No newline at end of file
......@@ -41,6 +41,7 @@ PODS:
- SwifterSwift/UIKit (5.1.0)
- SwiftyJSON (5.0.0)
- ViewAnimator (2.7.0)
- WYAutoLayout (1.0.1)
DEPENDENCIES:
- Alamofire
......@@ -61,6 +62,7 @@ DEPENDENCIES:
- SwifterSwift
- SwiftyJSON
- ViewAnimator
- WYAutoLayout
SPEC REPOS:
trunk:
......@@ -83,6 +85,7 @@ SPEC REPOS:
- SwifterSwift
- SwiftyJSON
- ViewAnimator
- WYAutoLayout
SPEC CHECKSUMS:
Alamofire: 85e8a02c69d6020a0d734f6054870d7ecb75cf18
......@@ -104,7 +107,8 @@ SPEC CHECKSUMS:
SwifterSwift: a9e8e144832638c2850b43da5feaf9598c6ad65b
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
ViewAnimator: 5af1c6f3b310f012bf081259c43717aa54fbae73
WYAutoLayout: 3cb136ddc2efa9faaecf15876e6a9b2a6fd7c6cb
PODFILE CHECKSUM: f44a6f82fbb68358d6512d34516d685184d1d6ad
PODFILE CHECKSUM: f7cea575720bdb85bdc196fb0c179b4966897e6e
COCOAPODS: 1.9.1
......@@ -41,6 +41,7 @@ PODS:
- SwifterSwift/UIKit (5.1.0)
- SwiftyJSON (5.0.0)
- ViewAnimator (2.7.0)
- WYAutoLayout (1.0.1)
DEPENDENCIES:
- Alamofire
......@@ -61,6 +62,7 @@ DEPENDENCIES:
- SwifterSwift
- SwiftyJSON
- ViewAnimator
- WYAutoLayout
SPEC REPOS:
trunk:
......@@ -83,6 +85,7 @@ SPEC REPOS:
- SwifterSwift
- SwiftyJSON
- ViewAnimator
- WYAutoLayout
SPEC CHECKSUMS:
Alamofire: 85e8a02c69d6020a0d734f6054870d7ecb75cf18
......@@ -104,7 +107,8 @@ SPEC CHECKSUMS:
SwifterSwift: a9e8e144832638c2850b43da5feaf9598c6ad65b
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
ViewAnimator: 5af1c6f3b310f012bf081259c43717aa54fbae73
WYAutoLayout: 3cb136ddc2efa9faaecf15876e6a9b2a6fd7c6cb
PODFILE CHECKSUM: f44a6f82fbb68358d6512d34516d685184d1d6ad
PODFILE CHECKSUM: f7cea575720bdb85bdc196fb0c179b4966897e6e
COCOAPODS: 1.9.1
This diff is collapsed.
......@@ -146,6 +146,8 @@
</dict>
<key>WYAutoLayout.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>20</integer>
</dict>
......
......@@ -899,4 +899,27 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
## WYAutoLayout
Copyright (c) 2019 wyxlh <wy_wangyu163@163.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Generated by CocoaPods - https://cocoapods.org
......@@ -1025,6 +1025,35 @@ THE SOFTWARE.
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>Copyright (c) 2019 wyxlh &lt;wy_wangyu163@163.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
</string>
<key>License</key>
<string>MIT</string>
<key>Title</key>
<string>WYAutoLayout</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>Generated by CocoaPods - https://cocoapods.org</string>
......
......@@ -17,4 +17,5 @@ ${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework
${BUILT_PRODUCTS_DIR}/SwiftDate/SwiftDate.framework
${BUILT_PRODUCTS_DIR}/SwifterSwift/SwifterSwift.framework
${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework
${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework
\ No newline at end of file
${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework
${BUILT_PRODUCTS_DIR}/WYAutoLayout/WYAutoLayout.framework
\ No newline at end of file
......@@ -16,4 +16,5 @@ ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftDate.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwifterSwift.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ViewAnimator.framework
\ No newline at end of file
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ViewAnimator.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WYAutoLayout.framework
\ No newline at end of file
......@@ -17,4 +17,5 @@ ${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework
${BUILT_PRODUCTS_DIR}/SwiftDate/SwiftDate.framework
${BUILT_PRODUCTS_DIR}/SwifterSwift/SwifterSwift.framework
${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework
${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework
\ No newline at end of file
${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework
${BUILT_PRODUCTS_DIR}/WYAutoLayout/WYAutoLayout.framework
\ No newline at end of file
......@@ -16,4 +16,5 @@ ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftDate.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwifterSwift.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ViewAnimator.framework
\ No newline at end of file
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ViewAnimator.framework
${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WYAutoLayout.framework
\ No newline at end of file
......@@ -216,6 +216,7 @@ if [[ "$CONFIGURATION" == "Debug" ]]; then
install_framework "${BUILT_PRODUCTS_DIR}/SwifterSwift/SwifterSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"
install_framework "${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework"
install_framework "${BUILT_PRODUCTS_DIR}/WYAutoLayout/WYAutoLayout.framework"
fi
if [[ "$CONFIGURATION" == "Release" ]]; then
install_framework "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework"
......@@ -237,6 +238,7 @@ if [[ "$CONFIGURATION" == "Release" ]]; then
install_framework "${BUILT_PRODUCTS_DIR}/SwifterSwift/SwifterSwift.framework"
install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"
install_framework "${BUILT_PRODUCTS_DIR}/ViewAnimator/ViewAnimator.framework"
install_framework "${BUILT_PRODUCTS_DIR}/WYAutoLayout/WYAutoLayout.framework"
fi
if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
wait
......
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