Skip to content

Commit da2048a

Browse files
committed
Added support for setting the scale factor of the placeholder
1 parent 8060412 commit da2048a

File tree

8 files changed

+98
-10
lines changed

8 files changed

+98
-10
lines changed

TextFieldEffects/TextFieldEffects/AkiraTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ import UIKit
4040
}
4141
}
4242

43+
/**
44+
The scale of the placeholder font.
45+
46+
This property determines the size of the placeholder label relative to the font size of the text field.
47+
*/
48+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.7 {
49+
didSet {
50+
updatePlaceholder()
51+
}
52+
}
53+
4354
override public var placeholder: String? {
4455
didSet {
4556
updatePlaceholder()
@@ -93,7 +104,7 @@ import UIKit
93104
}
94105

95106
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
96-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.7)
107+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
97108
return smallerFont
98109
}
99110

TextFieldEffects/TextFieldEffects/IsaoTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import UIKit
3535
}
3636
}
3737

38+
/**
39+
The scale of the placeholder font.
40+
41+
This property determines the size of the placeholder label relative to the font size of the text field.
42+
*/
43+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.7 {
44+
didSet {
45+
updatePlaceholder()
46+
}
47+
}
48+
3849
override public var placeholder: String? {
3950
didSet {
4051
updatePlaceholder()
@@ -101,7 +112,7 @@ import UIKit
101112
}
102113

103114
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
104-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.7)
115+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
105116
return smallerFont
106117
}
107118

TextFieldEffects/TextFieldEffects/JiroTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import UIKit
3535
}
3636
}
3737

38+
/**
39+
The scale of the placeholder font.
40+
41+
This property determines the size of the placeholder label relative to the font size of the text field.
42+
*/
43+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.65 {
44+
didSet {
45+
updatePlaceholder()
46+
}
47+
}
48+
3849
override public var placeholder: String? {
3950
didSet {
4051
updatePlaceholder()
@@ -109,7 +120,7 @@ import UIKit
109120
}
110121

111122
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
112-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.65)
123+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
113124
return smallerFont
114125
}
115126

TextFieldEffects/TextFieldEffects/KaedeTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ import UIKit
2424
}
2525
}
2626

27+
/**
28+
The scale of the placeholder font.
29+
30+
This property determines the size of the placeholder label relative to the font size of the text field.
31+
*/
32+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.8 {
33+
didSet {
34+
updatePlaceholder()
35+
}
36+
}
37+
2738
/**
2839
The view’s foreground color.
2940

@@ -106,7 +117,7 @@ import UIKit
106117
}
107118

108119
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
109-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.8)
120+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
110121
return smallerFont
111122
}
112123

TextFieldEffects/TextFieldEffects/MadokaTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import UIKit
3535
}
3636
}
3737

38+
/**
39+
The scale of the placeholder font.
40+
41+
This property determines the size of the placeholder label relative to the font size of the text field.
42+
*/
43+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.65 {
44+
didSet {
45+
updatePlaceholder()
46+
}
47+
}
48+
3849
override public var placeholder: String? {
3950
didSet {
4051
updatePlaceholder()
@@ -126,7 +137,7 @@ import UIKit
126137
}
127138

128139
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
129-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.65)
140+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
130141
return smallerFont
131142
}
132143

TextFieldEffects/TextFieldEffects/MinoruTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ import UIKit
3333
}
3434
}
3535

36+
/**
37+
The scale of the placeholder font.
38+
39+
This property determines the size of the placeholder label relative to the font size of the text field.
40+
*/
41+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.65 {
42+
didSet {
43+
updatePlaceholder()
44+
}
45+
}
46+
3647
override public var placeholder: String? {
3748
didSet {
3849
updatePlaceholder()
@@ -104,7 +115,7 @@ import UIKit
104115
}
105116

106117
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
107-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.65)
118+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
108119
return smallerFont
109120
}
110121

TextFieldEffects/TextFieldEffects/YokoTextField.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ import UIKit
2424
}
2525
}
2626

27+
/**
28+
The scale of the placeholder font.
29+
30+
This property determines the size of the placeholder label relative to the font size of the text field.
31+
*/
32+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.7 {
33+
didSet {
34+
updatePlaceholder()
35+
}
36+
}
37+
2738
/**
2839
The view’s foreground color.
2940

@@ -111,7 +122,7 @@ import UIKit
111122
}
112123

113124
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
114-
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * 0.7)
125+
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
115126
return smallerFont
116127
}
117128

TextFieldEffects/TextFieldEffects/YoshikoTextField.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ import UIKit
7575
updatePlaceholder()
7676
}
7777
}
78+
79+
/**
80+
The scale of the placeholder font.
81+
82+
This property determines the size of the placeholder label relative to the font size of the text field.
83+
*/
84+
@IBInspectable dynamic public var placeholderFontScale: CGFloat = 0.7 {
85+
didSet {
86+
updatePlaceholder()
87+
}
88+
}
7889

7990
override public var placeholder: String? {
8091
didSet {
@@ -104,11 +115,11 @@ import UIKit
104115
placeholderLabel.textAlignment = textAlignment
105116

106117
if isFirstResponder() || text!.isNotEmpty {
107-
placeholderLabel.font = placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: 0.5)
118+
placeholderLabel.font = placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: placeholderFontScale * 0.8)
108119
placeholderLabel.text = placeholder?.uppercaseString
109120
placeholderLabel.textColor = activeBorderColor
110121
} else {
111-
placeholderLabel.font = placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: 0.7)
122+
placeholderLabel.font = placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: placeholderFontScale)
112123
placeholderLabel.textColor = placeholderColor
113124
}
114125
}
@@ -123,7 +134,7 @@ import UIKit
123134
}
124135

125136
private var placeholderHeight : CGFloat {
126-
return placeHolderInsets.y + placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: 0.7).lineHeight
137+
return placeHolderInsets.y + placeholderFontFromFontAndPercentageOfOriginalSize(font: font!, percentageOfOriginalSize: placeholderFontScale).lineHeight
127138
}
128139

129140
private func animateViews() {

0 commit comments

Comments
 (0)