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
c46898e0
Commit
c46898e0
authored
Apr 30, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated animation when rotating to new orientation
parent
d1ad100c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
24 deletions
+46
-24
Examples/Programmatic/TextField/TextField/ViewController.swift
+8
-5
Sources/iOS/MTextField.swift
+38
-19
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
c46898e0
...
...
@@ -101,7 +101,7 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Programmatic update for the textField as it rotates.
override
func
willRotateToInterfaceOrientation
(
toInterfaceOrientation
:
UIInterfaceOrientation
,
duration
:
NSTimeInterval
)
{
emailField
.
width
=
view
.
bounds
.
height
emailField
.
width
=
view
.
bounds
.
height
-
80
}
/// General preparation statements.
...
...
@@ -133,7 +133,7 @@ class ViewController: UIViewController, TextFieldDelegate {
private
func
prepareNameField
()
{
nameField
=
MTextField
()
nameField
.
placeholder
=
"Email"
nameField
.
detail
=
"Enter your email address."
nameField
.
detail
=
"Enter your email address.
yyypppggg
"
nameField
.
clearButtonMode
=
.
WhileEditing
nameField
.
textAlignment
=
.
Center
nameField
.
text
=
"daniel@dahan"
...
...
@@ -146,15 +146,15 @@ class ViewController: UIViewController, TextFieldDelegate {
// Size the TextField to the maximum width, less 20 pixels on either side
// with a top margin of 100 pixels.
MaterialLayout
.
alignFromTop
(
view
,
child
:
nameField
,
top
:
10
0
)
MaterialLayout
.
alignFromTop
(
view
,
child
:
nameField
,
top
:
4
0
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
nameField
,
left
:
40
,
right
:
40
)
}
/// Prepares the email TextField.
private
func
prepareEmailField
()
{
emailField
=
MTextField
(
frame
:
CGRectMake
(
40
,
20
0
,
view
.
bounds
.
width
-
80
,
32
))
emailField
=
MTextField
(
frame
:
CGRectMake
(
40
,
12
0
,
view
.
bounds
.
width
-
80
,
32
))
emailField
.
placeholder
=
"Email"
emailField
.
detail
=
"Error, incorrect email."
emailField
.
detail
=
"Error, incorrect email.
yyppggg
"
emailField
.
delegate
=
self
emailField
.
clearButtonMode
=
.
WhileEditing
...
...
@@ -163,6 +163,9 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField
.
dividerColor
=
MaterialColor
.
cyan
.
base
emailField
.
detailColor
=
MaterialColor
.
indigo
.
accent1
emailField
.
backgroundColor
=
MaterialColor
.
green
.
accent1
emailField
.
placeholderLabel
.
backgroundColor
=
MaterialColor
.
green
.
accent3
view
.
addSubview
(
emailField
)
}
...
...
Sources/iOS/MTextField.swift
View file @
c46898e0
...
...
@@ -200,6 +200,7 @@ public class MTextField : UITextField {
if
let
v
:
String
=
value
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
layoutDetailLabel
()
}
}
...
...
@@ -215,11 +216,12 @@ public class MTextField : UITextField {
/// Handles the textAlignment of the placeholderLabel.
public
override
var
textAlignment
:
NSTextAlignment
{
get
{
return
placeholderLabel
.
textAlignment
return
super
.
textAlignment
}
set
(
value
)
{
super
.
textAlignment
=
value
placeholderLabel
.
textAlignment
=
value
detailLabel
.
textAlignment
=
value
}
}
...
...
@@ -250,18 +252,14 @@ public class MTextField : UITextField {
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
!
editing
&&
!
animating
{
layoutPlaceholderLabel
()
layoutDetailLabel
()
}
layoutPlaceholderLabel
()
layoutDetailLabel
()
}
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
if
!
editing
{
layoutDivider
()
}
layoutDivider
()
}
}
...
...
@@ -357,26 +355,41 @@ public class MTextField : UITextField {
/// Layout the divider.
public
func
layoutDivider
()
{
divider
.
frame
=
CGRectMake
(
0
,
height
,
width
,
dividerHeight
)
divider
.
frame
=
CGRectMake
(
0
,
height
,
width
,
editing
?
dividerActiveHeight
:
dividerHeight
)
}
/// Layout the placeholderLabel.
public
func
layoutPlaceholderLabel
()
{
if
true
==
text
?
.
isEmpty
{
placeholderLabel
.
frame
=
bounds
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
if
!
editing
&&
!
animating
{
if
true
==
text
?
.
isEmpty
{
placeholderLabel
.
frame
=
bounds
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
switch
textAlignment
{
case
.
Left
,
.
Natural
:
placeholderLabel
.
frame
.
origin
.
x
=
0
case
.
Right
:
placeholderLabel
.
frame
.
origin
.
x
=
width
-
placeholderLabel
.
frame
.
width
default
:
break
;
}
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
size
.
height
placeholderLabel
.
textColor
=
placeholderColor
}
}
else
if
!
animating
{
placeholderLabel
.
frame
.
origin
.
x
=
0
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
size
.
height
placeholderLabel
.
textColor
=
placeholderColor
placeholderLabel
.
frame
.
size
.
width
=
width
}
}
/// Layout the detailLabel.
public
func
layoutDetailLabel
()
{
detailLabel
.
frame
=
CGRectMake
(
0
,
height
+
8
,
width
,
12
)
detailLabel
.
sizeToFit
()
var
h
:
CGFloat
=
12
if
let
v
:
String
=
detail
{
let
size
:
CGSize
=
detailLabel
.
font
.
stringSize
(
v
,
constrainedToWidth
:
Double
(
width
))
h
=
size
.
height
}
detailLabel
.
frame
=
CGRectMake
(
0
,
height
+
8
,
width
,
h
)
}
/// The animation for the divider when editing begins.
...
...
@@ -398,7 +411,13 @@ public class MTextField : UITextField {
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
v
:
MTextField
=
self
{
v
.
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
switch
v
.
textAlignment
{
case
.
Left
,
.
Natural
:
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
case
.
Right
:
v
.
placeholderLabel
.
frame
.
origin
.
x
=
v
.
width
-
v
.
placeholderLabel
.
frame
.
width
default
:
break
;
}
v
.
placeholderLabel
.
frame
.
origin
.
y
=
-
v
.
placeholderLabel
.
frame
.
size
.
height
v
.
placeholderLabel
.
textColor
=
v
.
placeholderActiveColor
}
...
...
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