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
c06092a1
Unverified
Commit
c06092a1
authored
Oct 17, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: progression with TextField
parent
1ace72ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
44 deletions
+33
-44
Examples/Programmatic/TextField/TextField/ViewController.swift
+2
-7
Sources/iOS/TextField.swift
+31
-37
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
c06092a1
...
...
@@ -46,11 +46,12 @@ class ViewController: UIViewController {
prepareNameField
()
prepareEmailField
()
preparePasswordField
()
prepareResignResponderButton
()
}
/// Programmatic update for the textField as it rotates.
override
func
willRotate
(
to
toInterfaceOrientation
:
UIInterfaceOrientation
,
duration
:
TimeInterval
)
{
emailField
.
width
=
(
Device
.
isLandscape
?
view
.
height
:
view
.
width
)
-
2
*
constant
emailField
.
width
=
view
.
height
-
2
*
constant
}
/// Prepares the resign responder button.
...
...
@@ -83,8 +84,6 @@ class ViewController: UIViewController {
nameField
.
leftView
=
leftView
nameField
.
leftViewMode
=
.
always
nameField
.
placeholderLabel
.
backgroundColor
=
Color
.
green
.
base
view
.
layout
(
nameField
)
.
top
(
4
*
constant
)
.
horizontally
(
left
:
constant
,
right
:
constant
)
}
...
...
@@ -103,8 +102,6 @@ class ViewController: UIViewController {
emailField
.
leftView
=
leftView
emailField
.
leftViewMode
=
.
always
emailField
.
placeholderLabel
.
backgroundColor
=
Color
.
green
.
base
// Set the colors for the emailField, different from the defaults.
// emailField.placeholderNormalColor = Color.amber.darken4
// emailField.placeholderActiveColor = Color.pink.base
...
...
@@ -124,8 +121,6 @@ class ViewController: UIViewController {
// Setting the visibilityIconButton color.
passwordField
.
visibilityIconButton
?
.
tintColor
=
Color
.
green
.
base
.
withAlphaComponent
(
passwordField
.
isSecureTextEntry
?
0.38
:
0.54
)
passwordField
.
placeholderLabel
.
backgroundColor
=
Color
.
green
.
base
view
.
layout
(
passwordField
)
.
top
(
10
*
constant
)
.
horizontally
(
left
:
constant
,
right
:
constant
)
}
}
...
...
Sources/iOS/TextField.swift
View file @
c06092a1
...
...
@@ -74,6 +74,7 @@ open class TextField: UITextField {
open
override
var
leftView
:
UIView
?
{
didSet
{
prepareLeftView
()
layoutSubviews
()
}
}
...
...
@@ -365,9 +366,6 @@ open class TextField: UITextField {
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
layoutDivider
()
layoutLeftView
()
reload
()
}
...
...
@@ -458,43 +456,33 @@ open class TextField: UITextField {
layoutDetailLabel
()
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutDivider
()
layoutLeftView
()
}
/// Layout the divider.
open
func
layoutDivider
()
{
divider
.
reload
()
}
/// Layout the placeholderLabel.
open
func
layoutPlaceholderLabel
()
{
let
w
=
leftViewWidth
let
h
=
0
==
height
?
intrinsicContentSize
.
height
:
height
if
!
isEditing
&&
true
==
text
?
.
isEmpty
&&
isPlaceholderAnimated
{
guard
isEditing
||
false
==
text
?
.
isEmpty
||
!
isPlaceholderAnimated
else
{
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
}
else
if
placeholderLabel
.
transform
.
isIdentity
{
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
switch
textAlignment
{
case
.
left
,
.
natural
:
placeholderLabel
.
x
=
w
case
.
right
:
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
default
:
break
}
placeholderLabel
.
y
=
-
placeholderLabel
.
height
+
placeholderVerticalOffset
}
else
{
switch
textAlignment
{
case
.
left
,
.
natural
:
placeholderLabel
.
x
=
w
case
.
right
:
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
case
.
center
:
placeholderLabel
.
center
.
x
=
(
width
+
w
)
/
2
default
:
break
}
placeholderLabel
.
width
=
(
width
-
w
)
*
0.75
}
return
}
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
switch
textAlignment
{
case
.
left
,
.
natural
:
placeholderLabel
.
x
=
w
case
.
right
:
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
default
:
break
}
placeholderLabel
.
y
=
-
placeholderLabel
.
height
+
placeholderVerticalOffset
}
/// Layout the detailLabel.
...
...
@@ -515,6 +503,11 @@ open class TextField: UITextField {
button
?
.
frame
=
CGRect
(
x
:
width
-
height
,
y
:
0
,
width
:
height
,
height
:
height
)
}
/// Layout the divider.
open
func
layoutDivider
()
{
divider
.
reload
()
}
/// Layout the leftView.
open
func
layoutLeftView
()
{
guard
let
v
=
leftView
else
{
...
...
@@ -522,11 +515,7 @@ open class TextField: UITextField {
}
let
w
=
leftViewWidth
v
.
width
=
w
v
.
height
=
height
v
.
contentMode
=
.
center
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
height
)
divider
.
contentEdgeInsets
.
left
=
w
}
...
...
@@ -622,6 +611,11 @@ open class TextField: UITextField {
addSubview
(
detailLabel
)
addObserver
(
self
,
forKeyPath
:
"detailLabel.text"
,
options
:
[],
context
:
&
TextFieldContext
)
}
/// Prepares the leftView.
private
func
prepareLeftView
()
{
leftView
?
.
contentMode
=
.
center
}
/// Prepares the target handlers.
private
func
prepareTargetHandlers
()
{
...
...
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