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