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
85cae46a
Commit
85cae46a
authored
Apr 26, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-338: fixed where programmatically setting text did not display placeholderLabel
parent
23dde70e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
Examples/Programmatic/TextField/TextField/ViewController.swift
+2
-2
Sources/iOS/MTextField.swift
+11
-6
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
85cae46a
...
@@ -106,9 +106,9 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -106,9 +106,9 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField.
/// Prepares the name TextField.
private
func
prepareNameField
()
{
private
func
prepareNameField
()
{
nameField
=
MTextField
()
nameField
=
MTextField
()
nameField
.
placeholder
=
"Name"
nameField
.
placeholder
=
"Name
yyy yyy
"
nameField
.
detail
=
"Error, incorrect password. yy ypp ggg"
nameField
.
detail
=
"Error, incorrect password. yy ypp ggg"
nameField
.
placeholderTextColor
=
MaterialColor
.
green
.
base
nameField
.
text
=
"Testing Text ppp ppp"
view
.
addSubview
(
nameField
)
view
.
addSubview
(
nameField
)
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
...
...
Sources/iOS/MTextField.swift
View file @
85cae46a
...
@@ -259,8 +259,10 @@ public class MTextField : UITextField {
...
@@ -259,8 +259,10 @@ public class MTextField : UITextField {
/// Handles the text editing did end state.
/// Handles the text editing did end state.
public
func
handleEditingDidEnd
()
{
public
func
handleEditingDidEnd
()
{
dividerEditingDidEndAnimation
()
dividerEditingDidEndAnimation
()
if
true
==
text
?
.
isEmpty
{
placeholderEditingDidEndAnimation
()
placeholderEditingDidEndAnimation
()
}
}
}
/**
/**
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
...
@@ -290,6 +292,10 @@ public class MTextField : UITextField {
...
@@ -290,6 +292,10 @@ public class MTextField : UITextField {
public
func
layoutPlaceholderLabel
()
{
public
func
layoutPlaceholderLabel
()
{
if
true
==
text
?
.
isEmpty
{
if
true
==
text
?
.
isEmpty
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
frame
=
bounds
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
transform
=
CGAffineTransformScale
(
placeholderLabel
.
transform
,
0.75
,
0.75
)
placeholderLabel
.
frame
.
origin
=
CGPointMake
(
0
,
-
16
)
}
}
}
}
...
@@ -314,11 +320,11 @@ public class MTextField : UITextField {
...
@@ -314,11 +320,11 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing begins.
/// The animation for the placeholder when editing begins.
public
func
placeholderEditingDidBeginAnimation
()
{
public
func
placeholderEditingDidBeginAnimation
()
{
placeholderLabel
.
textColor
=
placeholderTextColor
placeholderLabel
.
textColor
=
placeholderTextColor
if
true
==
text
?
.
isEmpty
{
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
:
MTextField
=
self
{
if
let
s
:
MTextField
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransformScale
(
s
.
placeholderLabel
.
transform
,
0.75
,
0.75
)
s
.
placeholderLabel
.
transform
=
CGAffineTransformScale
(
s
.
placeholderLabel
.
transform
,
0.75
,
0.75
)
s
.
placeholderLabel
.
frame
=
CGRectMake
(
0
,
-
16
,
s
.
bounds
.
width
,
12
)
s
.
placeholderLabel
.
frame
.
origin
=
CGPointMake
(
0
,
-
16
)
}
}
})
})
}
}
...
@@ -326,7 +332,6 @@ public class MTextField : UITextField {
...
@@ -326,7 +332,6 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing ends.
/// The animation for the placeholder when editing ends.
public
func
placeholderEditingDidEndAnimation
()
{
public
func
placeholderEditingDidEndAnimation
()
{
if
true
==
text
?
.
isEmpty
{
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
:
MTextField
=
self
{
if
let
s
:
MTextField
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
s
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
...
@@ -334,7 +339,6 @@ public class MTextField : UITextField {
...
@@ -334,7 +339,6 @@ public class MTextField : UITextField {
}
}
})
})
}
}
}
/// Prepares the divider.
/// Prepares the divider.
private
func
prepareDivider
()
{
private
func
prepareDivider
()
{
...
@@ -345,13 +349,14 @@ public class MTextField : UITextField {
...
@@ -345,13 +349,14 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel.
/// Prepares the placeholderLabel.
private
func
preparePlaceholderLabel
()
{
private
func
preparePlaceholderLabel
()
{
placeholderLabel
=
UILabel
()
placeholderLabel
=
UILabel
(
frame
:
CGRectZero
)
placeholderLabel
.
font
=
font
addSubview
(
placeholderLabel
)
addSubview
(
placeholderLabel
)
}
}
/// Prepares the detailLabel.
/// Prepares the detailLabel.
private
func
prepareDetailLabel
()
{
private
func
prepareDetailLabel
()
{
detailLabel
=
UILabel
()
detailLabel
=
UILabel
(
frame
:
CGRectZero
)
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
addSubview
(
detailLabel
)
addSubview
(
detailLabel
)
}
}
...
...
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