Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
87baa186
Commit
87baa186
authored
Sep 05, 2017
by
Daniel Dahan
Committed by
GitHub
Sep 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #715 from mjgaylord/development
Uppercase placeholder in TextField when active
parents
9dc1261d
eb9f06fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
159 additions
and
139 deletions
+159
-139
Sources/iOS/TextField.swift
+159
-139
No files found.
Sources/iOS/TextField.swift
View file @
87baa186
...
@@ -133,8 +133,8 @@ open class TextField: UITextField {
...
@@ -133,8 +133,8 @@ open class TextField: UITextField {
}
}
/// Divider active height.
/// Divider active height.
@IBInspectable
@IBInspectable
open
var
dividerActiveHeight
:
CGFloat
=
2
{
open
var
dividerActiveHeight
:
CGFloat
=
2
{
didSet
{
didSet
{
guard
isEditing
else
{
guard
isEditing
else
{
...
@@ -144,9 +144,9 @@ open class TextField: UITextField {
...
@@ -144,9 +144,9 @@ open class TextField: UITextField {
dividerThickness
=
dividerActiveHeight
dividerThickness
=
dividerActiveHeight
}
}
}
}
/// Divider normal color.
/// Divider normal color.
@IBInspectable
@IBInspectable
open
var
dividerNormalColor
=
Color
.
darkText
.
dividers
{
open
var
dividerNormalColor
=
Color
.
darkText
.
dividers
{
didSet
{
didSet
{
guard
!
isEditing
else
{
guard
!
isEditing
else
{
...
@@ -156,58 +156,62 @@ open class TextField: UITextField {
...
@@ -156,58 +156,62 @@ open class TextField: UITextField {
dividerColor
=
dividerNormalColor
dividerColor
=
dividerNormalColor
}
}
}
}
/// Divider active color.
/// Divider active color.
@IBInspectable
@IBInspectable
open
var
dividerActiveColor
=
Color
.
blue
.
base
{
open
var
dividerActiveColor
=
Color
.
blue
.
base
{
didSet
{
didSet
{
guard
isEditing
else
{
guard
isEditing
else
{
return
return
}
}
dividerColor
=
dividerActiveColor
dividerColor
=
dividerActiveColor
}
}
}
}
/// The placeholderLabel font value.
/// The placeholderLabel font value.
@IBInspectable
@IBInspectable
open
override
var
font
:
UIFont
?
{
open
override
var
font
:
UIFont
?
{
didSet
{
didSet
{
placeholderLabel
.
font
=
font
placeholderLabel
.
font
=
font
}
}
}
}
/// The placeholderLabel text value.
/// The placeholderLabel text value.
@IBInspectable
@IBInspectable
open
override
var
placeholder
:
String
?
{
open
override
var
placeholder
:
String
?
{
get
{
get
{
return
placeholderLabel
.
text
return
placeholderLabel
.
text
}
}
set
(
value
)
{
set
(
value
)
{
placeholderLabel
.
text
=
value
if
isEditing
&&
isPlaceholderUppercasedWhenEditing
{
placeholderLabel
.
text
=
value
?
.
uppercased
()
}
else
{
placeholderLabel
.
text
=
value
}
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// The placeholder UILabel.
/// The placeholder UILabel.
@IBInspectable
@IBInspectable
open
let
placeholderLabel
=
UILabel
()
open
let
placeholderLabel
=
UILabel
()
/// Placeholder normal text
/// Placeholder normal text
@IBInspectable
@IBInspectable
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
didSet
{
didSet
{
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
}
}
}
}
/// Placeholder active text
/// Placeholder active text
@IBInspectable
@IBInspectable
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
didSet
{
didSet
{
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
}
}
}
}
/// This property adds a padding to placeholder y position animation
/// This property adds a padding to placeholder y position animation
@IBInspectable
@IBInspectable
...
@@ -232,53 +236,53 @@ open class TextField: UITextField {
...
@@ -232,53 +236,53 @@ open class TextField: UITextField {
/// The detailLabel text value.
/// The detailLabel text value.
@IBInspectable
@IBInspectable
open
var
detail
:
String
?
{
open
var
detail
:
String
?
{
get
{
get
{
return
detailLabel
.
text
return
detailLabel
.
text
}
}
set
(
value
)
{
set
(
value
)
{
detailLabel
.
text
=
value
detailLabel
.
text
=
value
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Detail text
/// Detail text
@IBInspectable
@IBInspectable
open
var
detailColor
=
Color
.
darkText
.
others
{
open
var
detailColor
=
Color
.
darkText
.
others
{
didSet
{
didSet
{
updateDetailLabelColor
()
updateDetailLabelColor
()
}
}
}
}
/// Vertical distance for the detailLabel from the divider.
/// Vertical distance for the detailLabel from the divider.
@IBInspectable
@IBInspectable
open
var
detailVerticalOffset
:
CGFloat
=
8
{
open
var
detailVerticalOffset
:
CGFloat
=
8
{
didSet
{
didSet
{
layoutDetailLabel
()
layoutDetailLabel
()
}
}
}
}
/// Handles the textAlignment of the placeholderLabel.
/// Handles the textAlignment of the placeholderLabel.
open
override
var
textAlignment
:
NSTextAlignment
{
open
override
var
textAlignment
:
NSTextAlignment
{
get
{
get
{
return
super
.
textAlignment
return
super
.
textAlignment
}
}
set
(
value
)
{
set
(
value
)
{
super
.
textAlignment
=
value
super
.
textAlignment
=
value
placeholderLabel
.
textAlignment
=
value
placeholderLabel
.
textAlignment
=
value
detailLabel
.
textAlignment
=
value
detailLabel
.
textAlignment
=
value
}
}
}
}
/// A reference to the clearIconButton.
/// A reference to the clearIconButton.
open
fileprivate
(
set
)
var
clearIconButton
:
IconButton
?
open
fileprivate
(
set
)
var
clearIconButton
:
IconButton
?
/// Enables the clearIconButton.
/// Enables the clearIconButton.
@IBInspectable
@IBInspectable
open
var
isClearIconButtonEnabled
:
Bool
{
open
var
isClearIconButtonEnabled
:
Bool
{
get
{
get
{
return
nil
!=
clearIconButton
return
nil
!=
clearIconButton
}
}
set
(
value
)
{
set
(
value
)
{
guard
value
else
{
guard
value
else
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
=
nil
clearIconButton
=
nil
...
@@ -298,33 +302,33 @@ open class TextField: UITextField {
...
@@ -298,33 +302,33 @@ open class TextField: UITextField {
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Enables the automatic handling of the clearIconButton.
/// Enables the automatic handling of the clearIconButton.
@IBInspectable
@IBInspectable
open
var
isClearIconButtonAutoHandled
=
true
{
open
var
isClearIconButtonAutoHandled
=
true
{
didSet
{
didSet
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
guard
isClearIconButtonAutoHandled
else
{
guard
isClearIconButtonAutoHandled
else
{
return
return
}
}
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
/// A reference to the visibilityIconButton.
/// A reference to the visibilityIconButton.
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
/// Enables the visibilityIconButton.
/// Enables the visibilityIconButton.
@IBInspectable
@IBInspectable
open
var
isVisibilityIconButtonEnabled
:
Bool
{
open
var
isVisibilityIconButtonEnabled
:
Bool
{
get
{
get
{
return
nil
!=
visibilityIconButton
return
nil
!=
visibilityIconButton
}
}
set
(
value
)
{
set
(
value
)
{
guard
value
else
{
guard
value
else
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
=
nil
visibilityIconButton
=
nil
...
@@ -345,50 +349,56 @@ open class TextField: UITextField {
...
@@ -345,50 +349,56 @@ open class TextField: UITextField {
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Enables the automatic handling of the visibilityIconButton.
/// Enables the automatic handling of the visibilityIconButton.
@IBInspectable
@IBInspectable
open
var
isVisibilityIconButtonAutoHandled
=
true
{
open
var
isVisibilityIconButtonAutoHandled
=
true
{
didSet
{
didSet
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
guard
isVisibilityIconButtonAutoHandled
else
{
guard
isVisibilityIconButtonAutoHandled
else
{
return
return
}
}
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
@IBInspectable
open
var
isPlaceholderUppercasedWhenEditing
:
Bool
=
false
{
didSet
{
placeholder
=
placeholder
?
.
uppercased
()
}
}
/**
/**
An initializer that initializes the object with a NSCoder object.
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
*/
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
super
.
init
(
coder
:
aDecoder
)
prepare
()
prepare
()
}
}
/**
/**
An initializer that initializes the object with a CGRect object.
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
using the init() initializer.
- Parameter frame: A CGRect instance.
- Parameter frame: A CGRect instance.
*/
*/
public
override
init
(
frame
:
CGRect
)
{
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
super
.
init
(
frame
:
frame
)
prepare
()
prepare
()
}
}
/// A convenience initializer.
/// A convenience initializer.
public
convenience
init
()
{
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
self
.
init
(
frame
:
.
zero
)
}
}
open
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
layoutShape
()
layoutShape
()
layoutPlaceholderLabel
()
layoutPlaceholderLabel
()
layoutDetailLabel
()
layoutDetailLabel
()
...
@@ -396,8 +406,8 @@ open class TextField: UITextField {
...
@@ -396,8 +406,8 @@ open class TextField: UITextField {
layoutButton
(
button
:
visibilityIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutDivider
()
layoutDivider
()
layoutLeftView
()
layoutLeftView
()
}
}
open
override
func
becomeFirstResponder
()
->
Bool
{
open
override
func
becomeFirstResponder
()
->
Bool
{
layoutSubviews
()
layoutSubviews
()
return
super
.
becomeFirstResponder
()
return
super
.
becomeFirstResponder
()
...
@@ -417,27 +427,27 @@ open class TextField: UITextField {
...
@@ -417,27 +427,27 @@ open class TextField: UITextField {
return
textRect
(
forBounds
:
bounds
)
return
textRect
(
forBounds
:
bounds
)
}
}
/**
/**
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
it is recommended to override the prepare method
to initialize property values and other setup operations.
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
The super.prepare method should always be called immediately
when subclassing.
when subclassing.
*/
*/
open
func
prepare
()
{
open
func
prepare
()
{
clipsToBounds
=
false
clipsToBounds
=
false
borderStyle
=
.
none
borderStyle
=
.
none
backgroundColor
=
nil
backgroundColor
=
nil
contentScaleFactor
=
Screen
.
scale
contentScaleFactor
=
Screen
.
scale
font
=
RobotoFont
.
regular
(
with
:
16
)
font
=
RobotoFont
.
regular
(
with
:
16
)
textColor
=
Color
.
darkText
.
primary
textColor
=
Color
.
darkText
.
primary
prepareDivider
()
prepareDivider
()
preparePlaceholderLabel
()
preparePlaceholderLabel
()
prepareDetailLabel
()
prepareDetailLabel
()
prepareTargetHandlers
()
prepareTargetHandlers
()
prepareTextAlignment
()
prepareTextAlignment
()
}
}
}
}
fileprivate
extension
TextField
{
fileprivate
extension
TextField
{
...
@@ -638,10 +648,16 @@ extension TextField {
...
@@ -638,10 +648,16 @@ extension TextField {
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
guard
isPlaceholderAnimated
else
{
guard
isPlaceholderAnimated
else
{
if
isPlaceholderUppercasedWhenEditing
{
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
uppercased
()
}
return
return
}
}
guard
isEmpty
else
{
guard
isEmpty
else
{
if
isPlaceholderUppercasedWhenEditing
{
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
uppercased
()
}
return
return
}
}
...
@@ -651,7 +667,10 @@ extension TextField {
...
@@ -651,7 +667,10 @@ extension TextField {
}
}
s
.
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
s
.
placeholderActiveScale
,
y
:
s
.
placeholderActiveScale
)
s
.
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
s
.
placeholderActiveScale
,
y
:
s
.
placeholderActiveScale
)
if
self
?
.
isPlaceholderUppercasedWhenEditing
??
false
{
s
.
placeholderLabel
.
text
=
s
.
placeholderLabel
.
text
?
.
uppercased
()
}
switch
s
.
textAlignment
{
switch
s
.
textAlignment
{
case
.
left
,
.
natural
:
case
.
left
,
.
natural
:
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
+
s
.
textInset
+
s
.
placeholderHorizinalOffset
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
+
s
.
textInset
+
s
.
placeholderHorizinalOffset
...
@@ -672,11 +691,12 @@ extension TextField {
...
@@ -672,11 +691,12 @@ extension TextField {
}
}
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
if
self
.
isPlaceholderUppercasedWhenEditing
{
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
capitalized
}
guard
isPlaceholderAnimated
else
{
guard
isPlaceholderAnimated
else
{
return
return
}
}
guard
isEmpty
else
{
guard
isEmpty
else
{
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment