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
7611c750
Unverified
Commit
7611c750
authored
Jun 27, 2018
by
Daniel Dahan
Committed by
GitHub
Jun 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1103 from OrkhanAlikhanov/visibility
Added ability to change password visibility icons
parents
2404c2ca
6fbbb6e1
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 @
7611c750
...
...
@@ -204,6 +204,12 @@ open class TextField: UITextField {
}
}
open
override
var
isSecureTextEntry
:
Bool
{
didSet
{
updateVisibilityIcon
()
}
}
/// The placeholder UILabel.
@IBInspectable
open
let
placeholderLabel
=
UILabel
()
...
...
@@ -333,6 +339,20 @@ open class TextField: UITextField {
/// A reference to the visibilityIconButton.
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.
@IBInspectable
open
var
isVisibilityIconButtonEnabled
:
Bool
{
...
...
@@ -350,10 +370,11 @@ open class TextField: UITextField {
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
!.
pulseAnimation
=
.
centerRadialBeyondBounds
isSecureTextEntry
=
true
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
=
visibilityIconButton
...
...
@@ -639,8 +660,6 @@ fileprivate extension TextField {
/// Handles the visibilityIconButton TouchUpInside event.
@objc
func
handleVisibilityIconButton
()
{
isSecureTextEntry
=
!
isSecureTextEntry
/// Workaround: Reassign text to reset cursor
/// This is a known issue with UITextField
/// Source: https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle
...
...
@@ -657,11 +676,7 @@ fileprivate extension TextField {
return
}
guard
let
v
=
self
.
visibilityIconButton
else
{
return
}
v
.
image
=
self
.
isSecureTextEntry
?
Icon
.
visibilityOff
?
.
tint
(
with
:
v
.
tintColor
.
withAlphaComponent
(
0.54
))
:
Icon
.
visibility
?
.
tint
(
with
:
v
.
tintColor
.
withAlphaComponent
(
0.54
))
self
.
isSecureTextEntry
=
!
self
.
isSecureTextEntry
})
}
}
...
...
@@ -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