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
5a4985e1
Commit
5a4985e1
authored
Jun 27, 2018
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' of github.com:CosmicMind/Material into development
parents
a741f921
7611c750
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
Sources/iOS/TextField.swift
+31
-9
No files found.
Sources/iOS/TextField.swift
View file @
5a4985e1
...
@@ -204,6 +204,12 @@ open class TextField: UITextField {
...
@@ -204,6 +204,12 @@ open class TextField: UITextField {
}
}
}
}
open
override
var
isSecureTextEntry
:
Bool
{
didSet
{
updateVisibilityIcon
()
}
}
/// The placeholder UILabel.
/// The placeholder UILabel.
@IBInspectable
@IBInspectable
open
let
placeholderLabel
=
UILabel
()
open
let
placeholderLabel
=
UILabel
()
...
@@ -333,6 +339,20 @@ open class TextField: UITextField {
...
@@ -333,6 +339,20 @@ open class TextField: UITextField {
/// A reference to the visibilityIconButton.
/// A reference to the visibilityIconButton.
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
/// Icon for visibilityIconButton when in the on state.
open
var
visibilityIconOn
=
Icon
.
visibility
{
didSet
{
updateVisibilityIcon
()
}
}
/// Icon for visibilityIconButton when in the off state.
open
var
visibilityIconOff
=
Icon
.
visibilityOff
{
didSet
{
updateVisibilityIcon
()
}
}
/// Enables the visibilityIconButton.
/// Enables the visibilityIconButton.
@IBInspectable
@IBInspectable
open
var
isVisibilityIconButtonEnabled
:
Bool
{
open
var
isVisibilityIconButtonEnabled
:
Bool
{
...
@@ -350,10 +370,11 @@ open class TextField: UITextField {
...
@@ -350,10 +370,11 @@ open class TextField: UITextField {
return
return
}
}
visibilityIconButton
=
IconButton
(
image
:
isSecureTextEntry
?
Icon
.
visibility
:
Icon
.
visibilityOff
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
0.54
))
isSecureTextEntry
=
true
visibilityIconButton
=
IconButton
(
image
:
nil
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
0.54
))
updateVisibilityIcon
()
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
pulseAnimation
=
.
centerRadialBeyondBounds
visibilityIconButton
!.
pulseAnimation
=
.
centerRadialBeyondBounds
isSecureTextEntry
=
true
clearButtonMode
=
.
never
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightViewMode
=
.
whileEditing
rightView
=
visibilityIconButton
rightView
=
visibilityIconButton
...
@@ -639,8 +660,6 @@ fileprivate extension TextField {
...
@@ -639,8 +660,6 @@ fileprivate extension TextField {
/// Handles the visibilityIconButton TouchUpInside event.
/// Handles the visibilityIconButton TouchUpInside event.
@objc
@objc
func
handleVisibilityIconButton
()
{
func
handleVisibilityIconButton
()
{
isSecureTextEntry
=
!
isSecureTextEntry
/// Workaround: Reassign text to reset cursor
/// Workaround: Reassign text to reset cursor
/// This is a known issue with UITextField
/// This is a known issue with UITextField
/// Source: https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle
/// Source: https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle
...
@@ -657,11 +676,7 @@ fileprivate extension TextField {
...
@@ -657,11 +676,7 @@ fileprivate extension TextField {
return
return
}
}
guard
let
v
=
self
.
visibilityIconButton
else
{
self
.
isSecureTextEntry
=
!
self
.
isSecureTextEntry
return
}
v
.
image
=
self
.
isSecureTextEntry
?
Icon
.
visibilityOff
?
.
tint
(
with
:
v
.
tintColor
.
withAlphaComponent
(
0.54
))
:
Icon
.
visibility
?
.
tint
(
with
:
v
.
tintColor
.
withAlphaComponent
(
0.54
))
})
})
}
}
}
}
...
@@ -758,3 +773,10 @@ extension TextField {
...
@@ -758,3 +773,10 @@ extension TextField {
})
})
}
}
}
}
private
extension
TextField
{
/// Updates visibilityIconButton image based on isSecureTextEntry value.
func
updateVisibilityIcon
()
{
visibilityIconButton
?
.
image
=
isSecureTextEntry
?
visibilityIconOff
:
visibilityIconOn
}
}
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