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
82a26399
Commit
82a26399
authored
Apr 30, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added password TextField example
parent
c46898e0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
60 deletions
+31
-60
Examples/Programmatic/TextField/TextField/ViewController.swift
+29
-55
Sources/iOS/MTextField.swift
+2
-5
No files found.
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
82a26399
...
@@ -38,65 +38,18 @@ under the TextField.
...
@@ -38,65 +38,18 @@ under the TextField.
import
UIKit
import
UIKit
import
Material
import
Material
//extension TextField {
//
// func setDefaultLabelSpecs(titleColor titleColor: UIColor, detailColor: UIColor) {
// // ref: https://www.google.com/design/spec/components/text-fields.html#text-fields-labels
// // ref: https://www.google.com/design/spec/patterns/errors.html#errors-user-input-errors
// // ref: https://www.google.com/design/spec/layout/metrics-keylines.html#metrics-keylines-touch-target-size
// assert(height == 80, "Height must be 80, based on Material design spec.")
//
// backgroundColor = nil
//
// let derivedDetailLabelHeight: CGFloat = 15
// let paddingAboveAndBelowErrorText: CGFloat = 4
//
// detailLabel.font = RobotoFont.regularWithSize(12)
// detailLabelActiveColor = detailColor
// detailLabelAnimationDistance = lineLayerThickness + paddingAboveAndBelowErrorText
//
// lineLayerActiveColor = titleColor
// lineLayerColor = MaterialColor.darkText.dividers
// lineLayerDistance = 0 - (derivedDetailLabelHeight + (paddingAboveAndBelowErrorText * 2) + lineLayerThickness)
//
// let derivedTitleLabelHeight: CGFloat = 20
// let paddingAboveLabelText: CGFloat = 8
//
// titleLabelActiveColor = lineLayerActiveColor
// titleLabelAnimationDistance = 0 - (derivedTitleLabelHeight + paddingAboveLabelText)
//
// if let clearButton = clearButton {
// let touchTargetHeight: CGFloat = 48
// let spacing = (height - touchTargetHeight) / 2
// let origin = CGPoint(x: width - touchTargetHeight - spacing, y: spacing)
// let size = CGSize(width: touchTargetHeight, height: touchTargetHeight)
//
// clearButton.frame = CGRect(origin: origin, size: size)
//
// clearButton.contentHorizontalAlignment = .Right
//
// // Use PDF for better rendering
// let clearImage = UIImage(named: "Material/Navigation/Close")
// clearButton.setImage(clearImage, forState: .Normal)
// clearButton.setImage(clearImage, forState: .Highlighted)
//
// // Hide it since it bleeds over the lineLayer, and doesn't look good
// // with the horizontal alignment.
// clearButton.pulseOpacity = 0
// }
// }
//}
class
ViewController
:
UIViewController
,
TextFieldDelegate
{
class
ViewController
:
UIViewController
,
TextFieldDelegate
{
private
var
nameField
:
MTextField
!
private
var
nameField
:
MTextField
!
private
var
emailField
:
MTextField
!
private
var
emailField
:
MTextField
!
private
var
passwordField
:
MTextField
!
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareView
()
prepareResignResponderButton
()
prepareNameField
()
prepareNameField
()
prepareEmailField
()
prepareEmailField
()
preparePasswordField
()
prepareResignResponderButton
()
}
}
/// Programmatic update for the textField as it rotates.
/// Programmatic update for the textField as it rotates.
...
@@ -132,11 +85,11 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -132,11 +85,11 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField.
/// Prepares the name TextField.
private
func
prepareNameField
()
{
private
func
prepareNameField
()
{
nameField
=
MTextField
()
nameField
=
MTextField
()
nameField
.
placeholder
=
"
Email
"
nameField
.
placeholder
=
"
Name
"
nameField
.
detail
=
"
Enter your email address.yyypppggg
"
nameField
.
detail
=
"
Your given name
"
nameField
.
clearButtonMode
=
.
WhileEditing
nameField
.
clearButtonMode
=
.
WhileEditing
nameField
.
textAlignment
=
.
Center
nameField
.
textAlignment
=
.
Center
nameField
.
text
=
"
daniel@d
ahan"
nameField
.
text
=
"
Daniel D
ahan"
nameField
.
backgroundColor
=
MaterialColor
.
green
.
accent1
nameField
.
backgroundColor
=
MaterialColor
.
green
.
accent1
nameField
.
placeholderLabel
.
backgroundColor
=
MaterialColor
.
green
.
accent3
nameField
.
placeholderLabel
.
backgroundColor
=
MaterialColor
.
green
.
accent3
...
@@ -144,8 +97,8 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -144,8 +97,8 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
view
.
addSubview
(
nameField
)
view
.
addSubview
(
nameField
)
// Size the TextField to the maximum width, less
2
0 pixels on either side
// Size the TextField to the maximum width, less
4
0 pixels on either side
// with a top margin of
10
0 pixels.
// with a top margin of
4
0 pixels.
MaterialLayout
.
alignFromTop
(
view
,
child
:
nameField
,
top
:
40
)
MaterialLayout
.
alignFromTop
(
view
,
child
:
nameField
,
top
:
40
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
nameField
,
left
:
40
,
right
:
40
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
nameField
,
left
:
40
,
right
:
40
)
}
}
...
@@ -169,6 +122,27 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -169,6 +122,27 @@ class ViewController: UIViewController, TextFieldDelegate {
view
.
addSubview
(
emailField
)
view
.
addSubview
(
emailField
)
}
}
/// Prepares the password TextField.
private
func
preparePasswordField
()
{
passwordField
=
MTextField
()
passwordField
.
placeholder
=
"Password"
passwordField
.
detail
=
"At least 8 characters"
passwordField
.
clearButtonMode
=
.
WhileEditing
passwordField
.
textAlignment
=
.
Right
passwordField
.
secureTextEntry
=
true
passwordField
.
backgroundColor
=
MaterialColor
.
green
.
accent1
passwordField
.
placeholderLabel
.
backgroundColor
=
MaterialColor
.
green
.
accent3
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
passwordField
.
translatesAutoresizingMaskIntoConstraints
=
false
view
.
addSubview
(
passwordField
)
// Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 200 pixels.
MaterialLayout
.
alignFromTop
(
view
,
child
:
passwordField
,
top
:
200
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
passwordField
,
left
:
40
,
right
:
40
)
}
/// Executed when the 'return' key is pressed when using the emailField.
/// Executed when the 'return' key is pressed when using the emailField.
func
textFieldShouldReturn
(
textField
:
UITextField
)
->
Bool
{
func
textFieldShouldReturn
(
textField
:
UITextField
)
->
Bool
{
return
true
return
true
...
...
Sources/iOS/MTextField.swift
View file @
82a26399
...
@@ -252,9 +252,11 @@ public class MTextField : UITextField {
...
@@ -252,9 +252,11 @@ public class MTextField : UITextField {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
if
!
editing
&&
!
animating
{
layoutPlaceholderLabel
()
layoutPlaceholderLabel
()
layoutDetailLabel
()
layoutDetailLabel
()
}
}
}
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
super
.
layoutSublayersOfLayer
(
layer
)
...
@@ -360,7 +362,6 @@ public class MTextField : UITextField {
...
@@ -360,7 +362,6 @@ public class MTextField : UITextField {
/// Layout the placeholderLabel.
/// Layout the placeholderLabel.
public
func
layoutPlaceholderLabel
()
{
public
func
layoutPlaceholderLabel
()
{
if
!
editing
&&
!
animating
{
if
true
==
text
?
.
isEmpty
{
if
true
==
text
?
.
isEmpty
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
frame
=
bounds
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
...
@@ -376,10 +377,6 @@ public class MTextField : UITextField {
...
@@ -376,10 +377,6 @@ public class MTextField : UITextField {
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
size
.
height
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
size
.
height
placeholderLabel
.
textColor
=
placeholderColor
placeholderLabel
.
textColor
=
placeholderColor
}
}
}
else
if
!
animating
{
placeholderLabel
.
frame
.
origin
.
x
=
0
placeholderLabel
.
frame
.
size
.
width
=
width
}
}
}
/// Layout the detailLabel.
/// Layout the 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