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
a6297afa
Unverified
Commit
a6297afa
authored
Sep 29, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor cleanup to TextField, and a correction when removing KVO on the detailLabel.text keyPath
parent
233c49bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
61 deletions
+101
-61
Material.xcodeproj/project.pbxproj
+13
-5
Sources/iOS/TextField.swift
+88
-56
No files found.
Material.xcodeproj/project.pbxproj
View file @
a6297afa
...
@@ -358,6 +358,15 @@
...
@@ -358,6 +358,15 @@
/* End PBXFrameworksBuildPhase section */
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
/* Begin PBXGroup section */
96090B031D9D709E00709CA6
/* TextField */
=
{
isa
=
PBXGroup
;
children
=
(
96BCB79C1CB40DC500C806FE
/* TextField.swift */
,
961F18E71CD93E3E008927C5
/* ErrorTextField.swift */
,
);
name
=
TextField
;
sourceTree
=
"<group>"
;
};
96230AB61D6A51FD00AF47DC
/* Divider */
=
{
96230AB61D6A51FD00AF47DC
/* Divider */
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
...
@@ -581,7 +590,8 @@
...
@@ -581,7 +590,8 @@
968C99421D36EC9E000074FF
/* Switch */
,
968C99421D36EC9E000074FF
/* Switch */
,
963FBF011D6696AB008F8512
/* TabBar */
,
963FBF011D6696AB008F8512
/* TabBar */
,
966ECF2B1CF4C21B00BB0BDF
/* Table */
,
966ECF2B1CF4C21B00BB0BDF
/* Table */
,
96BCB80E1CB4110E00C806FE
/* Text */
,
96090B031D9D709E00709CA6
/* TextField */
,
96BCB80E1CB4110E00C806FE
/* TextView */
,
963FBF001D66964F008F8512
/* Toolbar */
,
963FBF001D66964F008F8512
/* Toolbar */
,
96BCB8061CB40FD000C806FE
/* Type */
,
96BCB8061CB40FD000C806FE
/* Type */
,
96BCB80C1CB410DD00C806FE
/* View */
,
96BCB80C1CB410DD00C806FE
/* View */
,
...
@@ -768,16 +778,14 @@
...
@@ -768,16 +778,14 @@
name
=
Layer
;
name
=
Layer
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
};
};
96BCB80E1CB4110E00C806FE
/* Text */
=
{
96BCB80E1CB4110E00C806FE
/* Text
View
*/
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
96BCB79B1CB40DC500C806FE
/* Text.swift */
,
96BCB79B1CB40DC500C806FE
/* Text.swift */
,
96BCB79C1CB40DC500C806FE
/* TextField.swift */
,
961F18E71CD93E3E008927C5
/* ErrorTextField.swift */
,
96BCB79D1CB40DC500C806FE
/* TextStorage.swift */
,
96BCB79D1CB40DC500C806FE
/* TextStorage.swift */
,
96BCB79E1CB40DC500C806FE
/* TextView.swift */
,
96BCB79E1CB40DC500C806FE
/* TextView.swift */
,
);
);
name
=
Text
;
name
=
Text
View
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
};
};
96D88BF41C1328D800B91418
/* Sources */
=
{
96D88BF41C1328D800B91418
/* Sources */
=
{
...
...
Sources/iOS/TextField.swift
View file @
a6297afa
...
@@ -59,6 +59,7 @@ open class TextField: UITextField {
...
@@ -59,6 +59,7 @@ open class TextField: UITextField {
guard
!
isEditing
else
{
guard
!
isEditing
else
{
return
return
}
}
dividerColor
=
dividerNormalColor
dividerColor
=
dividerNormalColor
}
}
}
}
...
@@ -87,9 +88,15 @@ open class TextField: UITextField {
...
@@ -87,9 +88,15 @@ open class TextField: UITextField {
@IBInspectable
@IBInspectable
open
override
var
text
:
String
?
{
open
override
var
text
:
String
?
{
didSet
{
didSet
{
if
true
==
text
?
.
isEmpty
&&
!
isFirstResponder
{
guard
true
==
text
?
.
isEmpty
else
{
placeholderEditingDidEndAnimation
()
return
}
}
guard
!
isFirstResponder
else
{
return
}
placeholderEditingDidEndAnimation
()
}
}
}
}
...
@@ -101,9 +108,12 @@ open class TextField: UITextField {
...
@@ -101,9 +108,12 @@ open class TextField: UITextField {
}
}
set
(
value
)
{
set
(
value
)
{
placeholderLabel
.
text
=
value
placeholderLabel
.
text
=
value
if
let
v
:
String
=
value
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderNormalColor
])
guard
let
v
=
value
else
{
}
return
}
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderNormalColor
])
}
}
}
}
...
@@ -115,11 +125,15 @@ open class TextField: UITextField {
...
@@ -115,11 +125,15 @@ open class TextField: UITextField {
@IBInspectable
@IBInspectable
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
didSet
{
didSet
{
if
!
isEditing
{
guard
!
isEditing
else
{
if
let
v
:
String
=
placeholder
{
return
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderNormalColor
])
}
}
}
guard
let
v
=
placeholder
else
{
return
}
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderNormalColor
])
}
}
}
}
...
@@ -127,12 +141,17 @@ open class TextField: UITextField {
...
@@ -127,12 +141,17 @@ open class TextField: UITextField {
@IBInspectable
@IBInspectable
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
didSet
{
didSet
{
if
isEditing
{
tintColor
=
placeholderActiveColor
if
let
v
:
String
=
placeholder
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderActiveColor
])
guard
isEditing
else
{
}
return
}
}
tintColor
=
placeholderActiveColor
guard
let
v
=
placeholder
else
{
return
}
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderActiveColor
])
}
}
}
}
...
@@ -159,9 +178,7 @@ open class TextField: UITextField {
...
@@ -159,9 +178,7 @@ open class TextField: UITextField {
@IBInspectable
@IBInspectable
open
var
detailColor
=
Color
.
darkText
.
others
{
open
var
detailColor
=
Color
.
darkText
.
others
{
didSet
{
didSet
{
if
let
v
=
detailLabel
.
text
{
updateDetailLabelAttributedText
()
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
}
}
}
}
...
@@ -192,20 +209,23 @@ open class TextField: UITextField {
...
@@ -192,20 +209,23 @@ open class TextField: UITextField {
return
nil
!=
clearIconButton
return
nil
!=
clearIconButton
}
}
set
(
value
)
{
set
(
value
)
{
if
value
{
guard
value
else
{
if
nil
==
clearIconButton
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
=
nil
clearIconButton
!.
contentEdgeInsets
=
.
zero
return
clearIconButton
!.
pulseAnimation
=
.
center
}
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
guard
nil
==
clearIconButton
else
{
rightView
=
clearIconButton
return
isClearIconButtonAutoHandled
=
isClearIconButtonAutoHandled
?
true
:
false
}
}
}
else
{
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
!.
contentEdgeInsets
=
.
zero
clearIconButton
=
nil
clearIconButton
!.
pulseAnimation
=
.
center
}
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
=
clearIconButton
isClearIconButtonAutoHandled
=
isClearIconButtonAutoHandled
?
true
:
false
}
}
}
}
...
@@ -214,9 +234,12 @@ open class TextField: UITextField {
...
@@ -214,9 +234,12 @@ open class TextField: UITextField {
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
)
if
isClearIconButtonAutoHandled
{
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
guard
isClearIconButtonAutoHandled
else
{
return
}
}
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
...
@@ -227,21 +250,24 @@ open class TextField: UITextField {
...
@@ -227,21 +250,24 @@ open class TextField: UITextField {
return
nil
!=
visibilityIconButton
return
nil
!=
visibilityIconButton
}
}
set
(
value
)
{
set
(
value
)
{
if
value
{
guard
value
else
{
if
nil
==
visibilityIconButton
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
visibilityIconButton
=
nil
visibilityIconButton
!.
contentEdgeInsets
=
.
zero
return
visibilityIconButton
!.
pulseAnimation
=
.
center
}
isSecureTextEntry
=
true
clearButtonMode
=
.
never
guard
nil
==
visibilityIconButton
else
{
rightViewMode
=
.
whileEditing
return
rightView
=
visibilityIconButton
}
isVisibilityIconButtonAutoHandled
=
isVisibilityIconButtonAutoHandled
?
true
:
false
}
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
}
else
{
visibilityIconButton
!.
contentEdgeInsets
=
.
zero
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
!.
pulseAnimation
=
.
center
visibilityIconButton
=
nil
isSecureTextEntry
=
true
}
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
=
visibilityIconButton
isVisibilityIconButtonAutoHandled
=
isVisibilityIconButtonAutoHandled
?
true
:
false
}
}
}
}
...
@@ -250,9 +276,12 @@ open class TextField: UITextField {
...
@@ -250,9 +276,12 @@ open class TextField: UITextField {
open
var
isVisibilityIconButtonAutoHandled
:
Bool
=
true
{
open
var
isVisibilityIconButtonAutoHandled
:
Bool
=
true
{
didSet
{
didSet
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
if
isVisibilityIconButtonAutoHandled
{
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
guard
isVisibilityIconButtonAutoHandled
else
{
return
}
}
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
...
@@ -278,12 +307,13 @@ open class TextField: UITextField {
...
@@ -278,12 +307,13 @@ open class TextField: UITextField {
super
.
observeValue
(
forKeyPath
:
keyPath
,
of
:
object
,
change
:
change
,
context
:
context
)
super
.
observeValue
(
forKeyPath
:
keyPath
,
of
:
object
,
change
:
change
,
context
:
context
)
return
return
}
}
updateDetailLabelAttributedText
()
updateDetailLabelAttributedText
()
layoutDetailLabel
()
layoutDetailLabel
()
}
}
deinit
{
deinit
{
removeObserver
(
self
,
forKeyPath
:
"
title
Label.text"
)
removeObserver
(
self
,
forKeyPath
:
"
detail
Label.text"
)
}
}
/**
/**
...
@@ -541,8 +571,10 @@ open class TextField: UITextField {
...
@@ -541,8 +571,10 @@ open class TextField: UITextField {
/// Updates the detailLabel attributedText.
/// Updates the detailLabel attributedText.
private
func
updateDetailLabelAttributedText
()
{
private
func
updateDetailLabelAttributedText
()
{
if
let
v
=
detail
{
guard
let
v
=
detail
else
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
return
}
}
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
}
}
}
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