Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcjw committed Jun 3, 2017
1 parent 8001afc commit 0508d09
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 4 deletions.
1 change: 1 addition & 0 deletions CJWUtilsS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ end
s.dependency "PodAsset"
s.dependency "JXBAdPageView"
s.dependency "iVersion"
s.dependency "MZTimerLabel"
s.dependency "iRate"
s.dependency "Qiniu", "~> 7.1"
#s.dependency "Bugly"
Expand Down
144 changes: 144 additions & 0 deletions CJWUtilsS/QPLib/UI/LGView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import MZTimerLabel

class LGView: UIView {

Expand Down Expand Up @@ -118,3 +119,146 @@ public class LGColumnsTitleCell3: LGColumnsTitleCell {
return 3
}
}


public class LGTimerLabel: UILabel {

public typealias LGTimerLabelBlock = () -> ()
public typealias LGTimerLabelCanBlock = () -> Bool

var block: LGTimerLabelBlock?

var startBlock: LGTimerLabelBlock?

var canStartBlock: LGTimerLabelCanBlock?

public func onTimesUp(block: LGTimerLabelBlock) {
self.block = block
}

public func canStart(block: LGTimerLabelCanBlock) {
self.canStartBlock = block
}

public func onStart(block: LGTimerLabelBlock) {
self.startBlock = block
}

var actoun: Selector?
var target: AnyObject?

public override func addTapGesture(target: AnyObject?, action: Selector) {
self.onStart {
target?.performSelector(action, withObject: nil)
// self.performSelector(action, withObject: target)
// action.
}
}

func startCounting(startDate: NSDate) {

userInteractionEnabled = false

self.timer = MZTimerLabel(label: self, andTimerType: MZTimerLabelTypeTimer)
self.timer.timeFormat = "重新获取(ss)"
let date = startDate.dateByAddingTimeInterval(60)
self.timer.setCountDownToDate(date)
self.timer.startWithEndingBlock { (time) in
self.text = "点击获取"
self.userInteractionEnabled = true
self.block?()
LGTimerUtils.sharedInstance.startDate = nil
}
}

func setupTimer() {
let date = NSDate()
if let startDate = LGTimerUtils.sharedInstance.startDate {
let min = startDate.minutesBeforeDate(date)
log.debug("min \(min) \(date) \(startDate)")
if min <= 1 {
let date = NSDate()
startCounting(startDate)
} else {
}
} else {
// startCounting()
}
}

var timer: MZTimerLabel!

func onTap() {
// if let block = canStartBlock {
//
// }else{
// }
var flag = true
if let block = canStartBlock {
flag = block()
}

if flag {
let startDate = NSDate()
LGTimerUtils.sharedInstance.startDate = startDate
startCounting(startDate)
startBlock?()
}
}

convenience init () {
self.init(frame: CGRect.zero)
setup(self)
}

override init(frame: CGRect) {
super.init(frame: frame)
setup(self)
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup(self)
}

override public func updateConstraints() {
super.updateConstraints()
cornorRadius(5)

}

func setup(view: UIView) {
// self.userInteractionEnabled = true
// let tap = UITapGestureRecognizer(target: self, action: #selector(LGTimerLabel.onTap))
// self.addGestureRecognizer(tap)
super.addTapGesture(self, action: #selector(LGTimerLabel.onTap))
// super.addTapGesture(self, action: <#T##Selector#>)
setupTimer()
self.backgroundColor = UIColor.mainColor()
self.textColor = UIColor.whiteColor()
self.fontNormal()
textAlignmentCenter()
self.text = "获取验证码"
}

public override func drawRect(rect: CGRect) {
super.drawRect(rect)
}

}

public class LGTimerUtils: NSObject {
var startDate: NSDate?

public class var sharedInstance: LGTimerUtils {
struct Static {
static var onceToken: dispatch_once_t = 0
static var instance: LGTimerUtils? = nil
}
dispatch_once(&Static.onceToken) {
Static.instance = LGTimerUtils()
}
return Static.instance!
}

}
34 changes: 33 additions & 1 deletion CJWUtilsS/QPLib/UI/QPFormModifyTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import UIKit

public class QPFormModifyTableViewController: QPTableViewController {

public var isTextView = false

var textInputFiled = UITextField()
var textInputView = UITextView()

private var text = ""
private var placeholder = ""
Expand Down Expand Up @@ -43,6 +46,12 @@ public class QPFormModifyTableViewController: QPTableViewController {
}

override public func cellForRow(atIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if isTextView {
let cell = QPInputTextViewCell()
cell.textField.text = self.text
self.textInputView = cell.textField
return cell
}
let cell = tableView.dequeueReusableCellWithIdentifier("QPInputTextFieldCell") as! QPInputTextFieldCell
cell.textField.text = self.text
cell.textField.placeholder = self.placeholder
Expand All @@ -52,7 +61,11 @@ public class QPFormModifyTableViewController: QPTableViewController {

override public func popViewController(animated: Bool) {
super.popViewController(animated)
block?(text: textInputFiled.text ?? "")
if isTextView {
block?(text: textInputView.text ?? "")
} else {
block?(text: textInputFiled.text ?? "")
}
}

public func setupBlock(text: String, placeholder: String, block: QPInputModifyBlock) {
Expand Down Expand Up @@ -87,3 +100,22 @@ class QPInputTextFieldCell: QPTableViewCell {
textField.heightConstrain("44")
}
}

class QPInputTextViewCell: QPTableViewCell {
let textField = UITextView()

override func setupViews(view: UIView) {
super.setupViews(view)
view.addSubview(textField)
}

override func setupConstrains(view: UIView) {
super.setupConstrains(view)
textField.leadingAlign(view, predicate: "16")
textField.trailingAlign(view, predicate: "-16")
textField.topAlign(view, predicate: "4")
textField.bottomAlign(view, predicate: "-4")
// textField.equalConstrain()
textField.heightConstrain("100")
}
}
6 changes: 4 additions & 2 deletions CJWUtilsS/QPLib/UI/QPInputTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class QPInputVerifyCodeTableViewCell: QPInputTableViewCell2 {
public class QPInputTableViewCell2: QPTableViewCell, UITextFieldDelegate {
public let tipsLabel = QPTipsLabel()
public let textField = UITextField()
public let infoLabel = UILabel()
public let infoLabel = LGTimerLabel()
var block: QPInputTableViewCellBlock?

public override func setupViews(view: UIView) {
Expand Down Expand Up @@ -162,12 +162,14 @@ public class QPLongLabelTableViewCell: QPTableViewCell {
tipsLabel.font = UIFont.fontNormal()
titleLabel.font = UIFont.fontNormal()
tipsLabel.textColor = UIColor.darkGrayColor()
titleLabel.numberOfLines = 0
// titleLabel.textAlignment = NSTextAlignme
}

public override func setupConstrains(view: UIView) {
super.setupConstrains(view)

titleLabel.trailingAlign(view, predicate: "-16@700")
titleLabel.trailingAlign(view, predicate: "-16")
titleLabel.leadingAlign(view, predicate: ">=100")
titleLabel.leadingConstrain(tipsLabel, predicate: "16")
titleLabel.topAlign(view)
Expand Down
2 changes: 1 addition & 1 deletion CJWUtilsS/QPLib/Utils/QPSecurityUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class QPSecurityUtils: NSObject {
let publicKeyPath = bundle.pathForResource("rsa_public_key2", ofType: "pem")!
let publicKey = try? String(contentsOfFile: publicKeyPath, encoding: NSUTF8StringEncoding)
let encryptedString = try! SwiftyRSA.encryptString(text, publicKeyPEM: publicKey!)
print("\(encryptedString)")
return encryptedString

}
Expand Down Expand Up @@ -161,6 +160,7 @@ extension String {
let pwd = CJWDesEncrypt.encrypt(self, key: session as String)
return pwd
}

}

public extension QPHttpUtils {
Expand Down

0 comments on commit 0508d09

Please # to comment.