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
693ebed7
Commit
693ebed7
authored
Jun 29, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to show visibility and clear button at the same time
parent
8ac9ef6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
13 deletions
+35
-13
Sources/iOS/TextField.swift
+35
-13
No files found.
Sources/iOS/TextField.swift
View file @
693ebed7
...
@@ -302,6 +302,7 @@ open class TextField: UITextField {
...
@@ -302,6 +302,7 @@ open class TextField: UITextField {
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
)
removeFromRightView
(
view
:
clearIconButton
)
clearIconButton
=
nil
clearIconButton
=
nil
return
return
}
}
...
@@ -313,9 +314,8 @@ open class TextField: UITextField {
...
@@ -313,9 +314,8 @@ open class TextField: UITextField {
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
!.
contentEdgeInsetsPreset
=
.
none
clearIconButton
!.
contentEdgeInsetsPreset
=
.
none
clearIconButton
!.
pulseAnimation
=
.
none
clearIconButton
!.
pulseAnimation
=
.
none
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
?
.
grid
.
views
.
insert
(
clearIconButton
!
,
at
:
0
)
rightView
=
clearIconButton
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
...
@@ -362,6 +362,7 @@ open class TextField: UITextField {
...
@@ -362,6 +362,7 @@ open class TextField: UITextField {
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
)
removeFromRightView
(
view
:
visibilityIconButton
)
visibilityIconButton
=
nil
visibilityIconButton
=
nil
return
return
}
}
...
@@ -375,9 +376,8 @@ open class TextField: UITextField {
...
@@ -375,9 +376,8 @@ open class TextField: UITextField {
updateVisibilityIcon
()
updateVisibilityIcon
()
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
pulseAnimation
=
.
centerRadialBeyondBounds
visibilityIconButton
!.
pulseAnimation
=
.
centerRadialBeyondBounds
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
?
.
grid
.
views
.
append
(
visibilityIconButton
!
)
rightView
=
visibilityIconButton
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
...
@@ -429,10 +429,9 @@ open class TextField: UITextField {
...
@@ -429,10 +429,9 @@ open class TextField: UITextField {
layoutShape
()
layoutShape
()
layoutPlaceholderLabel
()
layoutPlaceholderLabel
()
layoutBottomLabel
(
label
:
detailLabel
,
verticalOffset
:
detailVerticalOffset
)
layoutBottomLabel
(
label
:
detailLabel
,
verticalOffset
:
detailVerticalOffset
)
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutDivider
()
layoutDivider
()
layoutLeftView
()
layoutLeftView
()
layoutRightView
()
}
}
open
override
func
becomeFirstResponder
()
->
Bool
{
open
override
func
becomeFirstResponder
()
->
Bool
{
...
@@ -475,6 +474,7 @@ open class TextField: UITextField {
...
@@ -475,6 +474,7 @@ open class TextField: UITextField {
prepareDetailLabel
()
prepareDetailLabel
()
prepareTargetHandlers
()
prepareTargetHandlers
()
prepareTextAlignment
()
prepareTextAlignment
()
prepareRightView
()
}
}
}
}
...
@@ -517,6 +517,14 @@ fileprivate extension TextField {
...
@@ -517,6 +517,14 @@ fileprivate extension TextField {
func
prepareTextAlignment
()
{
func
prepareTextAlignment
()
{
textAlignment
=
.
rightToLeft
==
Application
.
userInterfaceLayoutDirection
?
.
right
:
.
left
textAlignment
=
.
rightToLeft
==
Application
.
userInterfaceLayoutDirection
?
.
right
:
.
left
}
}
/// Prepares the rightView.
func
prepareRightView
()
{
rightView
=
UIView
()
rightView
?
.
grid
.
columns
=
2
rightViewMode
=
.
whileEditing
clearButtonMode
=
.
never
}
}
}
fileprivate
extension
TextField
{
fileprivate
extension
TextField
{
...
@@ -589,11 +597,6 @@ fileprivate extension TextField {
...
@@ -589,11 +597,6 @@ fileprivate extension TextField {
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
height
+
placeholderVerticalOffset
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
height
+
placeholderVerticalOffset
}
}
/// Layout the a button.
func
layoutButton
(
button
:
UIButton
?)
{
button
?
.
frame
=
CGRect
(
x
:
bounds
.
width
-
bounds
.
height
,
y
:
0
,
width
:
bounds
.
height
,
height
:
bounds
.
height
)
}
/// Layout the leftView.
/// Layout the leftView.
func
layoutLeftView
()
{
func
layoutLeftView
()
{
...
@@ -605,6 +608,16 @@ fileprivate extension TextField {
...
@@ -605,6 +608,16 @@ fileprivate extension TextField {
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
bounds
.
height
)
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
bounds
.
height
)
dividerContentEdgeInsets
.
left
=
w
dividerContentEdgeInsets
.
left
=
w
}
}
/// Layout the rightView.
func
layoutRightView
()
{
guard
let
rightView
=
rightView
else
{
return
}
let
w
=
CGFloat
(
rightView
.
grid
.
views
.
count
)
*
bounds
.
height
rightView
.
frame
=
CGRect
(
x
:
bounds
.
width
-
w
,
y
:
0
,
width
:
w
,
height
:
bounds
.
height
)
rightView
.
grid
.
reload
()
}
}
}
internal
extension
TextField
{
internal
extension
TextField
{
...
@@ -779,4 +792,13 @@ private extension TextField {
...
@@ -779,4 +792,13 @@ private extension TextField {
func
updateVisibilityIcon
()
{
func
updateVisibilityIcon
()
{
visibilityIconButton
?
.
image
=
isSecureTextEntry
?
visibilityIconOff
:
visibilityIconOn
visibilityIconButton
?
.
image
=
isSecureTextEntry
?
visibilityIconOff
:
visibilityIconOn
}
}
/// Remove view from rightView.
func
removeFromRightView
(
view
:
UIView
?)
{
guard
let
v
=
view
,
let
i
=
rightView
?
.
grid
.
views
.
index
(
of
:
v
)
else
{
return
}
rightView
?
.
grid
.
views
.
remove
(
at
:
i
)
}
}
}
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