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
1cce513d
Commit
1cce513d
authored
Apr 05, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated TextField to prepare titleLabel automatically
parent
a78719cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
52 deletions
+38
-52
Examples/Programmatic/TextField/TextField/ViewController.swift
+0
-10
README.md
+2
-2
Sources/iOS/TextField.swift
+36
-40
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
1cce513d
...
...
@@ -59,11 +59,6 @@ class ViewController: UIViewController, TextFieldDelegate {
textField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
textField
.
textColor
=
MaterialColor
.
black
textField
.
titleLabel
=
UILabel
()
textField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textField
.
titleLabelColor
=
MaterialColor
.
grey
.
base
textField
.
titleLabelActiveColor
=
MaterialColor
.
blue
.
accent3
view
.
addSubview
(
textField
)
}
...
...
@@ -76,11 +71,6 @@ class ViewController: UIViewController, TextFieldDelegate {
textField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
textField
.
textColor
=
MaterialColor
.
black
textField
.
titleLabel
=
UILabel
()
textField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textField
.
titleLabelColor
=
MaterialColor
.
grey
.
base
textField
.
titleLabelActiveColor
=
MaterialColor
.
blue
.
accent3
/*
Used to display the error message, which is displayed when
the user presses the 'return' key.
...
...
README.md
View file @
1cce513d
...
...
@@ -26,7 +26,7 @@ Express your creativity with Material, an animation and graphics framework for G
## Requirements
*
iOS 8.0+
*
iOS 8.0+
/ Mac OS X 10.9+
*
Xcode 7.3+
## Communication
...
...
@@ -39,7 +39,7 @@ Express your creativity with Material, an animation and graphics framework for G
## Installation
> **Embedded frameworks require a minimum deployment target of iOS 8.**
> **Embedded frameworks require a minimum deployment target of iOS 8
or OS X Mavericks (10.9)
.**
> - [Download Material](https://github.com/CosmicMind/Material/archive/master.zip)
Visit the
[
Installation
](
https://github.com/CosmicMind/Material/wiki/Installation
)
page to learn how to install Material using
[
CocoaPods
](
http://cocoapods.org
)
and
[
Carthage
](
https://github.com/Carthage/Carthage
)
.
...
...
Sources/iOS/TextField.swift
View file @
1cce513d
...
...
@@ -292,16 +292,12 @@ public class TextField : UITextField {
titleLabel text value is updated with the placeholder text
value before being displayed.
*/
public
var
titleLabel
:
UILabel
?
{
didSet
{
prepareTitleLabel
()
}
}
@IBInspectable
public
private(set)
var
titleLabel
:
UILabel
!
/// The color of the titleLabel text when the textField is not active.
@IBInspectable
public
var
titleLabelColor
:
UIColor
?
{
didSet
{
titleLabel
?
.
textColor
=
titleLabelColor
titleLabel
.
textColor
=
titleLabelColor
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
bottomBorderLayer
.
backgroundColor
=
self
.
titleLabelColor
?
.
CGColor
}
...
...
@@ -501,6 +497,7 @@ public class TextField : UITextField {
masksToBounds
=
false
prepareBottomBorderLayer
()
prepareClearButton
()
prepareTitleLabel
()
reloadView
()
}
...
...
@@ -530,7 +527,7 @@ public class TextField : UITextField {
/// Handler for text editing began.
internal
func
textFieldDidBegin
()
{
titleLabel
?
.
textColor
=
titleLabelActiveColor
titleLabel
.
textColor
=
titleLabelActiveColor
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
bottomBorderLayer
.
backgroundColor
=
self
.
detailLabelHidden
?
self
.
titleLabelActiveColor
?
.
CGColor
:
self
.
detailLabelActiveColor
?
.
CGColor
}
...
...
@@ -553,7 +550,7 @@ public class TextField : UITextField {
}
else
if
0
==
text
?
.
utf16
.
count
{
hideTitleLabel
()
}
titleLabel
?
.
textColor
=
titleLabelColor
titleLabel
.
textColor
=
titleLabelColor
MaterialAnimation
.
animationDisabled
{
[
unowned
self
]
in
self
.
bottomBorderLayer
.
backgroundColor
=
self
.
detailLabelHidden
?
self
.
titleLabelColor
?
.
CGColor
:
self
.
detailLabelActiveColor
?
.
CGColor
}
...
...
@@ -584,18 +581,21 @@ public class TextField : UITextField {
/// Prepares the titleLabel property.
private
func
prepareTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
v
.
hidden
=
true
addSubview
(
v
)
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
}
else
{
v
.
alpha
=
0
}
addTarget
(
self
,
action
:
#selector(
textFieldDidBegin
)
,
forControlEvents
:
.
EditingDidBegin
)
addTarget
(
self
,
action
:
#selector(
textFieldDidChange
)
,
forControlEvents
:
.
EditingChanged
)
addTarget
(
self
,
action
:
#selector(
textFieldDidEnd
)
,
forControlEvents
:
.
EditingDidEnd
)
titleLabel
=
UILabel
()
titleLabel
.
hidden
=
true
titleLabel
.
font
=
RobotoFont
.
mediumWithSize
(
12
)
titleLabelColor
=
MaterialColor
.
grey
.
base
titleLabelActiveColor
=
MaterialColor
.
blue
.
accent3
addSubview
(
titleLabel
)
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
(
)
}
else
{
titleLabel
.
alpha
=
0
}
addTarget
(
self
,
action
:
#selector(
textFieldDidBegin
)
,
forControlEvents
:
.
EditingDidBegin
)
addTarget
(
self
,
action
:
#selector(
textFieldDidChange
)
,
forControlEvents
:
.
EditingChanged
)
addTarget
(
self
,
action
:
#selector(
textFieldDidEnd
)
,
forControlEvents
:
.
EditingDidEnd
)
}
/// Prepares the detailLabel property.
...
...
@@ -640,33 +640,29 @@ public class TextField : UITextField {
/// Shows and animates the titleLabel property.
private
func
showTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
if
v
.
hidden
{
if
let
s
:
String
=
placeholder
{
if
0
==
v
.
text
?
.
utf16
.
count
||
nil
==
v
.
text
{
v
.
text
=
s
}
if
titleLabel
.
hidden
{
if
let
s
:
String
=
placeholder
{
if
0
==
titleLabel
.
text
?
.
utf16
.
count
||
nil
==
titleLabel
.
text
{
titleLabel
.
text
=
s
}
let
h
:
CGFloat
=
ceil
(
v
.
font
.
lineHeight
)
v
.
frame
=
CGRectMake
(
0
,
-
h
,
bounds
.
width
,
h
)
v
.
hidden
=
false
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
v
.
alpha
=
1
v
.
frame
.
origin
.
y
-=
self
.
titleLabelAnimationDistance
})
}
let
h
:
CGFloat
=
ceil
(
titleLabel
.
font
.
lineHeight
)
titleLabel
.
frame
=
CGRectMake
(
0
,
-
h
,
bounds
.
width
,
h
)
titleLabel
.
hidden
=
false
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
self
.
titleLabel
.
alpha
=
1
self
.
titleLabel
.
frame
.
origin
.
y
-=
self
.
titleLabelAnimationDistance
})
}
}
/// Hides and animates the titleLabel property.
private
func
hideTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
v
.
alpha
=
0
v
.
frame
.
origin
.
y
+=
self
.
titleLabelAnimationDistance
})
{
_
in
v
.
hidden
=
true
}
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
self
.
titleLabel
.
alpha
=
0
self
.
titleLabel
.
frame
.
origin
.
y
+=
self
.
titleLabelAnimationDistance
})
{
_
in
self
.
titleLabel
.
hidden
=
true
}
}
...
...
@@ -680,7 +676,7 @@ public class TextField : UITextField {
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
unowned
self
]
in
v
.
frame
.
origin
.
y
=
self
.
frame
.
height
+
self
.
bottomBorderLayerDistance
+
self
.
detailLabelAnimationDistance
v
.
alpha
=
1
})
})
}
}
}
...
...
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