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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
34 deletions
+23
-34
Examples/Programmatic/TextField/TextField/ViewController.swift
+2
-7
Sources/iOS/TextField.swift
+21
-27
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
c06092a1
...
@@ -46,11 +46,12 @@ class ViewController: UIViewController {
...
@@ -46,11 +46,12 @@ class ViewController: UIViewController {
prepareNameField
()
prepareNameField
()
prepareEmailField
()
prepareEmailField
()
preparePasswordField
()
preparePasswordField
()
prepareResignResponderButton
()
}
}
/// Programmatic update for the textField as it rotates.
/// Programmatic update for the textField as it rotates.
override
func
willRotate
(
to
toInterfaceOrientation
:
UIInterfaceOrientation
,
duration
:
TimeInterval
)
{
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.
/// Prepares the resign responder button.
...
@@ -83,8 +84,6 @@ class ViewController: UIViewController {
...
@@ -83,8 +84,6 @@ class ViewController: UIViewController {
nameField
.
leftView
=
leftView
nameField
.
leftView
=
leftView
nameField
.
leftViewMode
=
.
always
nameField
.
leftViewMode
=
.
always
nameField
.
placeholderLabel
.
backgroundColor
=
Color
.
green
.
base
view
.
layout
(
nameField
)
.
top
(
4
*
constant
)
.
horizontally
(
left
:
constant
,
right
:
constant
)
view
.
layout
(
nameField
)
.
top
(
4
*
constant
)
.
horizontally
(
left
:
constant
,
right
:
constant
)
}
}
...
@@ -103,8 +102,6 @@ class ViewController: UIViewController {
...
@@ -103,8 +102,6 @@ class ViewController: UIViewController {
emailField
.
leftView
=
leftView
emailField
.
leftView
=
leftView
emailField
.
leftViewMode
=
.
always
emailField
.
leftViewMode
=
.
always
emailField
.
placeholderLabel
.
backgroundColor
=
Color
.
green
.
base
// Set the colors for the emailField, different from the defaults.
// Set the colors for the emailField, different from the defaults.
// emailField.placeholderNormalColor = Color.amber.darken4
// emailField.placeholderNormalColor = Color.amber.darken4
// emailField.placeholderActiveColor = Color.pink.base
// emailField.placeholderActiveColor = Color.pink.base
...
@@ -124,8 +121,6 @@ class ViewController: UIViewController {
...
@@ -124,8 +121,6 @@ class ViewController: UIViewController {
// Setting the visibilityIconButton color.
// Setting the visibilityIconButton color.
passwordField
.
visibilityIconButton
?
.
tintColor
=
Color
.
green
.
base
.
withAlphaComponent
(
passwordField
.
isSecureTextEntry
?
0.38
:
0.54
)
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
)
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 {
...
@@ -74,6 +74,7 @@ open class TextField: UITextField {
open
override
var
leftView
:
UIView
?
{
open
override
var
leftView
:
UIView
?
{
didSet
{
didSet
{
prepareLeftView
()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
...
@@ -365,9 +366,6 @@ open class TextField: UITextField {
...
@@ -365,9 +366,6 @@ open class TextField: UITextField {
open
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
layoutDivider
()
layoutLeftView
()
reload
()
reload
()
}
}
...
@@ -458,11 +456,8 @@ open class TextField: UITextField {
...
@@ -458,11 +456,8 @@ open class TextField: UITextField {
layoutDetailLabel
()
layoutDetailLabel
()
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
}
layoutDivider
()
layoutLeftView
()
/// Layout the divider.
open
func
layoutDivider
()
{
divider
.
reload
()
}
}
/// Layout the placeholderLabel.
/// Layout the placeholderLabel.
...
@@ -470,11 +465,15 @@ open class TextField: UITextField {
...
@@ -470,11 +465,15 @@ open class TextField: UITextField {
let
w
=
leftViewWidth
let
w
=
leftViewWidth
let
h
=
0
==
height
?
intrinsicContentSize
.
height
:
height
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
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
}
else
if
placeholderLabel
.
transform
.
isIdentity
{
return
}
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
switch
textAlignment
{
switch
textAlignment
{
case
.
left
,
.
natural
:
case
.
left
,
.
natural
:
placeholderLabel
.
x
=
w
placeholderLabel
.
x
=
w
...
@@ -482,19 +481,8 @@ open class TextField: UITextField {
...
@@ -482,19 +481,8 @@ open class TextField: UITextField {
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
default
:
break
default
:
break
}
}
placeholderLabel
.
y
=
-
placeholderLabel
.
height
+
placeholderVerticalOffset
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
}
}
}
/// Layout the detailLabel.
/// Layout the detailLabel.
...
@@ -515,6 +503,11 @@ open class TextField: UITextField {
...
@@ -515,6 +503,11 @@ open class TextField: UITextField {
button
?
.
frame
=
CGRect
(
x
:
width
-
height
,
y
:
0
,
width
:
height
,
height
:
height
)
button
?
.
frame
=
CGRect
(
x
:
width
-
height
,
y
:
0
,
width
:
height
,
height
:
height
)
}
}
/// Layout the divider.
open
func
layoutDivider
()
{
divider
.
reload
()
}
/// Layout the leftView.
/// Layout the leftView.
open
func
layoutLeftView
()
{
open
func
layoutLeftView
()
{
guard
let
v
=
leftView
else
{
guard
let
v
=
leftView
else
{
...
@@ -522,11 +515,7 @@ open class TextField: UITextField {
...
@@ -522,11 +515,7 @@ open class TextField: UITextField {
}
}
let
w
=
leftViewWidth
let
w
=
leftViewWidth
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
height
)
v
.
width
=
w
v
.
height
=
height
v
.
contentMode
=
.
center
divider
.
contentEdgeInsets
.
left
=
w
divider
.
contentEdgeInsets
.
left
=
w
}
}
...
@@ -623,6 +612,11 @@ open class TextField: UITextField {
...
@@ -623,6 +612,11 @@ open class TextField: UITextField {
addObserver
(
self
,
forKeyPath
:
"detailLabel.text"
,
options
:
[],
context
:
&
TextFieldContext
)
addObserver
(
self
,
forKeyPath
:
"detailLabel.text"
,
options
:
[],
context
:
&
TextFieldContext
)
}
}
/// Prepares the leftView.
private
func
prepareLeftView
()
{
leftView
?
.
contentMode
=
.
center
}
/// Prepares the target handlers.
/// Prepares the target handlers.
private
func
prepareTargetHandlers
()
{
private
func
prepareTargetHandlers
()
{
addTarget
(
self
,
action
:
#selector(
handleEditingDidBegin
)
,
for
:
.
editingDidBegin
)
addTarget
(
self
,
action
:
#selector(
handleEditingDidBegin
)
,
for
:
.
editingDidBegin
)
...
...
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