File tree Expand file tree Collapse file tree 10 files changed +68
-11
lines changed
TextFieldEffects/TextFieldEffects Expand file tree Collapse file tree 10 files changed +68
-11
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,12 @@ import UIKit
107107 }
108108
109109 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
110- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
110+ var smallerFont : UIFont
111+ if ( font. isSystemFont ( ) ) {
112+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
113+ } else {
114+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
115+ }
111116 return smallerFont
112117 }
113118
Original file line number Diff line number Diff line change @@ -149,7 +149,12 @@ import UIKit
149149 }
150150
151151 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
152- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
152+ var smallerFont : UIFont
153+ if ( font. isSystemFont ( ) ) {
154+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
155+ } else {
156+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
157+ }
153158 return smallerFont
154159 }
155160
Original file line number Diff line number Diff line change @@ -110,8 +110,13 @@ import UIKit
110110 }
111111 }
112112
113- private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
114- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
113+ private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
114+ var smallerFont : UIFont
115+ if ( font. isSystemFont ( ) ) {
116+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
117+ } else {
118+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
119+ }
115120 return smallerFont
116121 }
117122
Original file line number Diff line number Diff line change @@ -123,7 +123,12 @@ import UIKit
123123 }
124124
125125 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
126- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
126+ var smallerFont : UIFont
127+ if ( font. isSystemFont ( ) ) {
128+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
129+ } else {
130+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
131+ }
127132 return smallerFont
128133 }
129134
Original file line number Diff line number Diff line change @@ -133,7 +133,12 @@ import UIKit
133133 }
134134
135135 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
136- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
136+ var smallerFont : UIFont
137+ if ( font. isSystemFont ( ) ) {
138+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
139+ } else {
140+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
141+ }
137142 return smallerFont
138143 }
139144
Original file line number Diff line number Diff line change @@ -140,7 +140,12 @@ import UIKit
140140 }
141141
142142 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
143- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
143+ var smallerFont : UIFont
144+ if ( font. isSystemFont ( ) ) {
145+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
146+ } else {
147+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
148+ }
144149 return smallerFont
145150 }
146151
Original file line number Diff line number Diff line change @@ -129,7 +129,12 @@ import UIKit
129129 }
130130
131131 private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
132- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
132+ var smallerFont : UIFont
133+ if ( font. isSystemFont ( ) ) {
134+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
135+ } else {
136+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
137+ }
133138 return smallerFont
134139 }
135140
Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ extension String {
1717 }
1818}
1919
20+
21+
22+ extension UIFont {
23+ /**
24+ Compare any font to system font. then returns a bool
25+ */
26+ func isSystemFont( ) -> Bool {
27+ return self . familyName == UIFont . systemFont ( ofSize: 12.0 ) . familyName
28+ }
29+ }
30+
2031/**
2132A TextFieldEffects object is a control that displays editable text and contains the boilerplates to setup unique animations for text entry and display. You typically use this class the same way you use UITextField.
2233*/
Original file line number Diff line number Diff line change @@ -124,8 +124,13 @@ import UIKit
124124 }
125125 }
126126
127- private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
128- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * placeholderFontScale)
127+ private func placeholderFontFromFont( _ font: UIFont ) -> UIFont ! {
128+ var smallerFont : UIFont
129+ if ( font. isSystemFont ( ) ) {
130+ smallerFont = . systemFont( ofSize: font. pointSize * placeholderFontScale)
131+ } else {
132+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * placeholderFontScale)
133+ }
129134 return smallerFont
130135 }
131136
Original file line number Diff line number Diff line change @@ -122,9 +122,15 @@ import UIKit
122122 placeholderLabel. textColor = placeholderColor
123123 }
124124 }
125+
125126
126127 private func placeholderFontFromFontAndPercentageOfOriginalSize( font: UIFont , percentageOfOriginalSize: CGFloat ) -> UIFont ! {
127- let smallerFont = UIFont ( name: font. fontName, size: font. pointSize * percentageOfOriginalSize)
128+ var smallerFont : UIFont
129+ if ( font. isSystemFont ( ) ) {
130+ smallerFont = . systemFont( ofSize: font. pointSize * percentageOfOriginalSize)
131+ } else {
132+ smallerFont = UIFont ( descriptor: font. fontDescriptor, size: font. pointSize * percentageOfOriginalSize)
133+ }
128134 return smallerFont
129135 }
130136
You can’t perform that action at this time.
0 commit comments