Skip to content

Commit

Permalink
Merge pull request #50 from recruit-lifestyle/develop
Browse files Browse the repository at this point in the history
impl. PasswordInputView modifiable font and fontSize
  • Loading branch information
liu044100 authored Jun 1, 2018
2 parents fffc390 + 70e051f commit d8a8812
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ class BlurPasswordLoginViewController: UIViewController {
passwordUIValidation.view.rearrangeForVisualEffectView(in: self)

passwordUIValidation.view.deleteButtonLocalizedTitle = "smilelock_delete"

// customize font
// for inputView in passwordUIValidation.view.passwordInputViews {
// inputView.labelFont = UIFont(name: "Chalkduster", size: 29)
// }
}
}
2 changes: 1 addition & 1 deletion SmileLock.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SmileLock"
s.version = "3.0.2"
s.version = "3.0.3"
s.summary = "A library for make a beautiful Passcode Lock View."
s.description = <<-DESC
1. Create a beautiful passcode lock view simply.
Expand Down
25 changes: 19 additions & 6 deletions SmileLock/Classes/PasswordInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ open class PasswordInputView: UIView {
let circleView = UIView()
let button = UIButton()
open let label = UILabel()
open var labelFont: UIFont?
fileprivate let fontSizeRatio: CGFloat = 46 / 40
fileprivate let borderWidthRatio: CGFloat = 1 / 26
fileprivate var touchUpFlag = false
fileprivate var touchUpFlag = true
fileprivate(set) open var isAnimating = false
var isVibrancyEffect = false

Expand Down Expand Up @@ -96,6 +97,18 @@ open class PasswordInputView: UIView {
updateUI()
}

fileprivate func getLabelFont() -> UIFont {
if labelFont != nil {
return labelFont!
}

let width = bounds.width
let height = bounds.height
let radius = min(width, height) / 2
return UIFont.systemFont(ofSize: radius * fontSizeRatio,
weight: touchUpFlag ? UIFont.Weight.thin : UIFont.Weight.regular)
}

fileprivate func updateUI() {
//prepare calculate
let width = bounds.width
Expand All @@ -107,7 +120,9 @@ open class PasswordInputView: UIView {

//update label
label.text = numberString
label.font = UIFont.systemFont(ofSize: radius * fontSizeRatio, weight: UIFont.Weight.thin)

label.font = getLabelFont()

label.textColor = textColor

//update circle view
Expand Down Expand Up @@ -147,8 +162,7 @@ private extension PasswordInputView {

//MARK: Animation
func touchDownAction() {
let originFont = label.font
label.font = UIFont.systemFont(ofSize: originFont!.pointSize, weight: UIFont.Weight.light)
label.font = getLabelFont()
label.textColor = highlightTextColor
if !self.isVibrancyEffect {
backgroundColor = highlightBackgroundColor
Expand All @@ -157,8 +171,7 @@ private extension PasswordInputView {
}

func touchUpAction() {
let originFont = label.font
label.font = UIFont.systemFont(ofSize: originFont!.pointSize, weight: UIFont.Weight.thin)
label.font = getLabelFont()
label.textColor = textColor
backgroundColor = borderColor
circleView.backgroundColor = circleBackgroundColor
Expand Down

0 comments on commit d8a8812

Please sign in to comment.