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
867fc755
Commit
867fc755
authored
Apr 29, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated default colors and sizes, and added help properties to set the values when active
parent
541aaec7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
39 deletions
+53
-39
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/TextField/TextField/ViewController.swift
+10
-1
Sources/iOS/MTextField.swift
+37
-38
No files found.
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
867fc755
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
objects
=
{
objects
=
{
/* Begin PBXBuildFile section */
/* Begin PBXBuildFile section */
9658F1F01CD3C0EA00B902C1
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
;
};
9658F1F11CD3C0EA00B902C1
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
...
@@ -20,6 +22,7 @@
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstPath
=
""
;
dstSubfolderSpec
=
10
;
dstSubfolderSpec
=
10
;
files
=
(
files
=
(
9658F1F11CD3C0EA00B902C1
/* Material.framework in Embed Frameworks */
,
);
);
name
=
"Embed Frameworks"
;
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
...
@@ -27,6 +30,7 @@
...
@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
966F579D1C226BAA009185B7
/* TextField.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
TextField.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
966F579D1C226BAA009185B7
/* TextField.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
TextField.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
966F57A01C226BAA009185B7
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
966F57A01C226BAA009185B7
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
966F57A21C226BAA009185B7
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
966F57A21C226BAA009185B7
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -40,6 +44,7 @@
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
9658F1F01CD3C0EA00B902C1
/* Material.framework in Frameworks */
,
);
);
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
};
};
...
@@ -49,6 +54,7 @@
...
@@ -49,6 +54,7 @@
966F57941C226BAA009185B7
=
{
966F57941C226BAA009185B7
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579E1C226BAA009185B7
/* Products */
,
966F579E1C226BAA009185B7
/* Products */
,
);
);
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
867fc755
...
@@ -99,6 +99,11 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -99,6 +99,11 @@ class ViewController: UIViewController, TextFieldDelegate {
prepareEmailField
()
prepareEmailField
()
}
}
/// Programmatic update for the textField as it rotates.
override
func
willRotateToInterfaceOrientation
(
toInterfaceOrientation
:
UIInterfaceOrientation
,
duration
:
NSTimeInterval
)
{
emailField
.
width
=
view
.
bounds
.
height
}
/// General preparation statements.
/// General preparation statements.
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
view
.
backgroundColor
=
MaterialColor
.
white
...
@@ -130,6 +135,10 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -130,6 +135,10 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField
.
placeholder
=
"Email"
nameField
.
placeholder
=
"Email"
nameField
.
detail
=
"Enter your email address."
nameField
.
detail
=
"Enter your email address."
nameField
.
clearButtonMode
=
.
WhileEditing
nameField
.
clearButtonMode
=
.
WhileEditing
nameField
.
textAlignment
=
.
Center
nameField
.
text
=
"daniel@dahan"
nameField
.
backgroundColor
=
MaterialColor
.
green
.
accent1
nameField
.
placeholderLabel
.
backgroundColor
=
MaterialColor
.
green
.
accent3
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
...
@@ -143,7 +152,7 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -143,7 +152,7 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the email TextField.
/// Prepares the email TextField.
private
func
prepareEmailField
()
{
private
func
prepareEmailField
()
{
emailField
=
MTextField
(
frame
:
CGRectMake
(
40
,
200
,
view
.
bounds
.
width
-
80
,
21
))
emailField
=
MTextField
(
frame
:
CGRectMake
(
40
,
200
,
view
.
bounds
.
width
-
80
,
32
))
emailField
.
placeholder
=
"Email"
emailField
.
placeholder
=
"Email"
emailField
.
detail
=
"Error, incorrect email."
emailField
.
detail
=
"Error, incorrect email."
emailField
.
delegate
=
self
emailField
.
delegate
=
self
...
...
Sources/iOS/MTextField.swift
View file @
867fc755
...
@@ -126,19 +126,7 @@ public class MTextField : UITextField {
...
@@ -126,19 +126,7 @@ public class MTextField : UITextField {
@IBInspectable
public
var
dividerActiveHeight
:
CGFloat
=
2
@IBInspectable
public
var
dividerActiveHeight
:
CGFloat
=
2
/// Sets the divider and tintColor.
/// Sets the divider and tintColor.
@IBInspectable
public
var
dividerColor
:
UIColor
?
{
@IBInspectable
public
var
dividerColor
:
UIColor
=
MaterialColor
.
darkText
.
dividers
get
{
return
nil
==
divider
.
backgroundColor
?
nil
:
UIColor
(
CGColor
:
divider
.
backgroundColor
!
)
}
set
(
value
)
{
divider
.
backgroundColor
=
dividerColor
?
.
CGColor
if
let
v
:
UIColor
=
dividerColor
{
tintColor
=
v
}
else
{
tintColor
=
MaterialColor
.
darkText
.
dividers
}
}
}
/// The placeholderLabel font value.
/// The placeholderLabel font value.
@IBInspectable
public
override
var
font
:
UIFont
?
{
@IBInspectable
public
override
var
font
:
UIFont
?
{
...
@@ -171,13 +159,10 @@ public class MTextField : UITextField {
...
@@ -171,13 +159,10 @@ public class MTextField : UITextField {
@IBInspectable
public
private(set)
lazy
var
placeholderLabel
:
UILabel
=
UILabel
(
frame
:
CGRectZero
)
@IBInspectable
public
private(set)
lazy
var
placeholderLabel
:
UILabel
=
UILabel
(
frame
:
CGRectZero
)
/// Placeholder textColor.
/// Placeholder textColor.
@IBInspectable
public
var
placeholderColor
:
UIColor
=
MaterialColor
.
darkText
.
others
{
@IBInspectable
public
var
placeholderColor
:
UIColor
=
MaterialColor
.
darkText
.
others
didSet
{
if
let
v
:
String
=
placeholder
{
/// Placeholder active textColor.
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
@IBInspectable
public
var
placeholderActiveColor
:
UIColor
=
MaterialColor
.
blue
.
base
}
}
}
/// The detailLabel UILabel that is displayed.
/// The detailLabel UILabel that is displayed.
@IBInspectable
public
private(set)
lazy
var
detailLabel
:
UILabel
=
UILabel
(
frame
:
CGRectZero
)
@IBInspectable
public
private(set)
lazy
var
detailLabel
:
UILabel
=
UILabel
(
frame
:
CGRectZero
)
...
@@ -191,17 +176,22 @@ public class MTextField : UITextField {
...
@@ -191,17 +176,22 @@ public class MTextField : UITextField {
set
(
value
)
{
set
(
value
)
{
detailLabel
.
text
=
value
detailLabel
.
text
=
value
if
let
v
:
String
=
value
{
if
let
v
:
String
=
value
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Color
])
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detail
Color
])
}
}
}
}
}
}
/// Detail textColor.
/// Detail textColor.
@IBInspectable
public
var
detailColor
:
UIColor
=
MaterialColor
.
darkText
.
others
{
@IBInspectable
public
var
detailColor
:
UIColor
=
MaterialColor
.
darkText
.
others
didSet
{
if
let
v
:
String
=
detail
{
/// Handles the textAlignment of the placeholderLabel.
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
public
override
var
textAlignment
:
NSTextAlignment
{
}
get
{
return
placeholderLabel
.
textAlignment
}
set
(
value
)
{
super
.
textAlignment
=
value
placeholderLabel
.
textAlignment
=
value
}
}
}
}
...
@@ -247,6 +237,11 @@ public class MTextField : UITextField {
...
@@ -247,6 +237,11 @@ public class MTextField : UITextField {
}
}
}
}
/// Default size when using AutoLayout.
public
override
func
intrinsicContentSize
()
->
CGSize
{
return
CGSizeMake
(
width
,
32
)
}
/**
/**
A method that accepts CAAnimation objects and executes them on the
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
view's backing layer.
...
@@ -310,9 +305,7 @@ public class MTextField : UITextField {
...
@@ -310,9 +305,7 @@ 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
()
}
}
}
/**
/**
...
@@ -336,7 +329,7 @@ public class MTextField : UITextField {
...
@@ -336,7 +329,7 @@ public class MTextField : UITextField {
/// Layout the divider.
/// Layout the divider.
public
func
layoutDivider
()
{
public
func
layoutDivider
()
{
divider
.
frame
=
CGRectMake
(
0
,
height
+
8
,
width
,
dividerHeight
)
divider
.
frame
=
CGRectMake
(
0
,
height
,
width
,
dividerHeight
)
}
}
/// Layout the placeholderLabel.
/// Layout the placeholderLabel.
...
@@ -345,28 +338,29 @@ public class MTextField : UITextField {
...
@@ -345,28 +338,29 @@ public class MTextField : UITextField {
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
frame
=
bounds
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
transform
=
CGAffineTransform
Scale
(
placeholderLabel
.
transform
,
0.75
,
0.75
)
placeholderLabel
.
transform
=
CGAffineTransform
MakeScale
(
0.75
,
0.75
)
placeholderLabel
.
frame
.
origin
.
x
=
0
placeholderLabel
.
frame
.
origin
.
x
=
0
placeholderLabel
.
frame
.
origin
.
y
=
-
21
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
size
.
height
placeholderLabel
.
textColor
=
placeholderColor
}
}
}
}
/// Layout the detailLabel.
/// Layout the detailLabel.
public
func
layoutDetailLabel
()
{
public
func
layoutDetailLabel
()
{
detailLabel
.
frame
=
CGRectMake
(
0
,
height
+
16
,
width
,
12
)
detailLabel
.
frame
=
CGRectMake
(
0
,
height
+
8
,
width
,
12
)
detailLabel
.
sizeToFit
()
detailLabel
.
sizeToFit
()
}
}
/// The animation for the divider when editing begins.
/// The animation for the divider when editing begins.
public
func
dividerEditingDidBeginAnimation
()
{
public
func
dividerEditingDidBeginAnimation
()
{
divider
.
frame
.
size
.
height
=
dividerActiveHeight
divider
.
frame
.
size
.
height
=
dividerActiveHeight
divider
.
backgroundColor
=
MaterialColor
.
blue
.
base
.
CGColor
divider
.
backgroundColor
=
placeholderActiveColor
.
CGColor
}
}
/// The animation for the divider when editing ends.
/// The animation for the divider when editing ends.
public
func
dividerEditingDidEndAnimation
()
{
public
func
dividerEditingDidEndAnimation
()
{
divider
.
frame
.
size
.
height
=
dividerHeight
divider
.
frame
.
size
.
height
=
dividerHeight
divider
.
backgroundColor
=
MaterialColor
.
darkText
.
dividers
.
CGColor
divider
.
backgroundColor
=
dividerColor
.
CGColor
}
}
/// The animation for the placeholder when editing begins.
/// The animation for the placeholder when editing begins.
...
@@ -377,27 +371,33 @@ public class MTextField : UITextField {
...
@@ -377,27 +371,33 @@ public class MTextField : UITextField {
if
let
v
:
MTextField
=
self
{
if
let
v
:
MTextField
=
self
{
v
.
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
v
.
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
y
=
-
21
v
.
placeholderLabel
.
frame
.
origin
.
y
=
-
v
.
placeholderLabel
.
frame
.
size
.
height
v
.
placeholderLabel
.
textColor
=
v
.
placeholderActiveColor
}
}
})
{
[
weak
self
]
_
in
})
{
[
weak
self
]
_
in
self
?
.
animating
=
false
self
?
.
animating
=
false
}
}
}
else
if
editing
{
placeholderLabel
.
textColor
=
placeholderActiveColor
}
}
}
}
/// The animation for the placeholder when editing ends.
/// The animation for the placeholder when editing ends.
public
func
placeholderEditingDidEndAnimation
()
{
public
func
placeholderEditingDidEndAnimation
()
{
if
!
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
if
!
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
&&
true
==
text
?
.
isEmpty
{
animating
=
true
animating
=
true
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
v
:
MTextField
=
self
{
if
let
v
:
MTextField
=
self
{
v
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
v
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
y
=
0
v
.
placeholderLabel
.
frame
.
origin
.
y
=
0
v
.
placeholderLabel
.
textColor
=
v
.
placeholderColor
}
}
})
{
[
weak
self
]
_
in
})
{
[
weak
self
]
_
in
self
?
.
animating
=
false
self
?
.
animating
=
false
}
}
}
else
if
!
editing
{
placeholderLabel
.
textColor
=
placeholderColor
}
}
}
}
...
@@ -409,7 +409,6 @@ public class MTextField : UITextField {
...
@@ -409,7 +409,6 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel.
/// Prepares the placeholderLabel.
private
func
preparePlaceholderLabel
()
{
private
func
preparePlaceholderLabel
()
{
placeholderLabel
.
font
=
font
placeholderColor
=
MaterialColor
.
darkText
.
others
placeholderColor
=
MaterialColor
.
darkText
.
others
addSubview
(
placeholderLabel
)
addSubview
(
placeholderLabel
)
}
}
...
...
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