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
541aaec7
Commit
541aaec7
authored
Apr 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added MTextField for testing
parent
2f724180
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
35 deletions
+73
-35
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+0
-6
Examples/Programmatic/TextField/TextField/ViewController.swift
+25
-8
Sources/iOS/MTextField.swift
+48
-21
No files found.
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
541aaec7
...
...
@@ -7,8 +7,6 @@
objects
=
{
/* Begin PBXBuildFile section */
961776711CCE75EB0091B4F3
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
961776701CCE75EB0091B4F3
/* Material.framework */
;
};
961776721CCE75EB0091B4F3
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
961776701CCE75EB0091B4F3
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
...
...
@@ -22,7 +20,6 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
961776721CCE75EB0091B4F3
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
961776701CCE75EB0091B4F3
/* 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
;
};
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>"
;
};
...
...
@@ -44,7 +40,6 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
961776711CCE75EB0091B4F3
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -54,7 +49,6 @@
966F57941C226BAA009185B7
=
{
isa
=
PBXGroup
;
children
=
(
961776701CCE75EB0091B4F3
/* Material.framework */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579E1C226BAA009185B7
/* Products */
,
);
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
541aaec7
...
...
@@ -94,6 +94,7 @@ class ViewController: UIViewController, TextFieldDelegate {
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
prepareResignResponderButton
()
prepareNameField
()
prepareEmailField
()
}
...
...
@@ -103,11 +104,32 @@ class ViewController: UIViewController, TextFieldDelegate {
view
.
backgroundColor
=
MaterialColor
.
white
}
/// Prepares the resign responder button.
private
func
prepareResignResponderButton
()
{
let
btn
:
RaisedButton
=
RaisedButton
()
btn
.
translatesAutoresizingMaskIntoConstraints
=
false
btn
.
addTarget
(
self
,
action
:
#selector(
handleResignResponderButton
)
,
forControlEvents
:
.
TouchUpInside
)
btn
.
setTitle
(
"Resign"
,
forState
:
.
Normal
)
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Normal
)
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Highlighted
)
view
.
addSubview
(
btn
)
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
btn
,
bottom
:
24
,
right
:
24
)
MaterialLayout
.
size
(
view
,
child
:
btn
,
width
:
100
,
height
:
50
)
}
/// Handle the resign responder button.
internal
func
handleResignResponderButton
()
{
nameField
?
.
resignFirstResponder
()
emailField
?
.
resignFirstResponder
()
}
/// Prepares the name TextField.
private
func
prepareNameField
()
{
nameField
=
MTextField
()
nameField
.
placeholder
=
"Email"
nameField
.
detail
=
"Enter your email address."
nameField
.
clearButtonMode
=
.
WhileEditing
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
nameField
.
translatesAutoresizingMaskIntoConstraints
=
false
...
...
@@ -116,15 +138,16 @@ 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
:
100
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
nameField
,
left
:
20
,
right
:
2
0
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
nameField
,
left
:
40
,
right
:
4
0
)
}
/// Prepares the email TextField.
private
func
prepareEmailField
()
{
emailField
=
MTextField
(
frame
:
CGRectMake
(
20
,
200
,
view
.
bounds
.
width
-
40
,
16
))
emailField
=
MTextField
(
frame
:
CGRectMake
(
40
,
200
,
view
.
bounds
.
width
-
80
,
21
))
emailField
.
placeholder
=
"Email"
emailField
.
detail
=
"Error, incorrect email."
emailField
.
delegate
=
self
emailField
.
clearButtonMode
=
.
WhileEditing
view
.
addSubview
(
emailField
)
}
...
...
@@ -135,30 +158,24 @@ class ViewController: UIViewController, TextFieldDelegate {
}
func
textFieldShouldBeginEditing
(
textField
:
UITextField
)
->
Bool
{
print
(
"Should Begin"
)
return
true
}
func
textFieldDidBeginEditing
(
textField
:
UITextField
)
{
print
(
"Did Begin"
)
}
func
textFieldShouldEndEditing
(
textField
:
UITextField
)
->
Bool
{
print
(
"Should End"
)
return
true
}
func
textFieldDidEndEditing
(
textField
:
UITextField
)
{
print
(
"Did End"
)
}
func
textFieldShouldClear
(
textField
:
UITextField
)
->
Bool
{
print
(
"Should Clear"
)
return
true
}
func
textField
(
textField
:
UITextField
,
shouldChangeCharactersInRange
range
:
NSRange
,
replacementString
string
:
String
)
->
Bool
{
print
(
"Should Change"
)
return
true
}
}
Sources/iOS/MTextField.swift
View file @
541aaec7
...
...
@@ -34,6 +34,8 @@ public protocol MTextFieldDelegate : UITextFieldDelegate {}
@IBDesignable
public
class
MTextField
:
UITextField
{
public
private(set)
var
animating
:
Bool
=
false
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame.
...
...
@@ -121,7 +123,22 @@ public class MTextField : UITextField {
@IBInspectable
public
var
dividerHeight
:
CGFloat
=
1
/// Divider active state height.
@IBInspectable
public
var
dividerActiveHeight
:
CGFloat
=
2
@IBInspectable
public
var
dividerActiveHeight
:
CGFloat
=
2
/// Sets the divider and tintColor.
@IBInspectable
public
var
dividerColor
:
UIColor
?
{
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.
@IBInspectable
public
override
var
font
:
UIFont
?
{
...
...
@@ -141,7 +158,7 @@ public class MTextField : UITextField {
set
(
value
)
{
placeholderLabel
.
text
=
value
if
let
v
:
String
=
value
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Text
Color
])
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
}
}
}
...
...
@@ -154,10 +171,10 @@ public class MTextField : UITextField {
@IBInspectable
public
private(set)
lazy
var
placeholderLabel
:
UILabel
=
UILabel
(
frame
:
CGRectZero
)
/// Placeholder textColor.
@IBInspectable
public
var
placeholder
Text
Color
:
UIColor
=
MaterialColor
.
darkText
.
others
{
@IBInspectable
public
var
placeholderColor
:
UIColor
=
MaterialColor
.
darkText
.
others
{
didSet
{
if
let
v
:
String
=
placeholder
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Text
Color
])
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
}
}
}
...
...
@@ -174,16 +191,16 @@ public class MTextField : UITextField {
set
(
value
)
{
detailLabel
.
text
=
value
if
let
v
:
String
=
value
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Text
Color
])
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
}
}
}
/// Detail textColor.
@IBInspectable
public
var
detail
Text
Color
:
UIColor
=
MaterialColor
.
darkText
.
others
{
@IBInspectable
public
var
detailColor
:
UIColor
=
MaterialColor
.
darkText
.
others
{
didSet
{
if
let
v
:
String
=
detail
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detail
Text
Color
])
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
}
}
...
...
@@ -215,7 +232,7 @@ public class MTextField : UITextField {
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
!
editing
{
if
!
editing
&&
!
animating
{
layoutPlaceholderLabel
()
layoutDetailLabel
()
}
...
...
@@ -329,7 +346,8 @@ public class MTextField : UITextField {
}
else
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
placeholderLabel
.
frame
=
bounds
placeholderLabel
.
transform
=
CGAffineTransformScale
(
placeholderLabel
.
transform
,
0.75
,
0.75
)
placeholderLabel
.
frame
.
origin
=
CGPointMake
(
0
,
-
24
)
placeholderLabel
.
frame
.
origin
.
x
=
0
placeholderLabel
.
frame
.
origin
.
y
=
-
21
}
}
...
...
@@ -353,25 +371,34 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing begins.
public
func
placeholderEditingDidBeginAnimation
()
{
placeholderLabel
.
textColor
=
placeholderTextColor
if
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
animating
=
true
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
:
MTextField
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransformScale
(
s
.
placeholderLabel
.
transform
,
0.75
,
0.75
)
s
.
placeholderLabel
.
frame
.
origin
=
CGPointMake
(
0
,
-
24
)
if
let
v
:
MTextField
=
self
{
v
.
placeholderLabel
.
transform
=
CGAffineTransformMakeScale
(
0.75
,
0.75
)
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
y
=
-
21
}
})
})
{
[
weak
self
]
_
in
self
?
.
animating
=
false
}
}
}
/// The animation for the placeholder when editing ends.
public
func
placeholderEditingDidEndAnimation
()
{
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
:
MTextField
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
s
.
placeholderLabel
.
frame
=
s
.
bounds
if
!
CGAffineTransformIsIdentity
(
placeholderLabel
.
transform
)
{
animating
=
true
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
weak
self
]
in
if
let
v
:
MTextField
=
self
{
v
.
placeholderLabel
.
transform
=
CGAffineTransformIdentity
v
.
placeholderLabel
.
frame
.
origin
.
x
=
0
v
.
placeholderLabel
.
frame
.
origin
.
y
=
0
}
})
{
[
weak
self
]
_
in
self
?
.
animating
=
false
}
}
)
}
}
/// Prepares the divider.
...
...
@@ -383,14 +410,14 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel.
private
func
preparePlaceholderLabel
()
{
placeholderLabel
.
font
=
font
placeholder
Text
Color
=
MaterialColor
.
darkText
.
others
placeholderColor
=
MaterialColor
.
darkText
.
others
addSubview
(
placeholderLabel
)
}
/// Prepares the detailLabel.
private
func
prepareDetailLabel
()
{
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
detail
Text
Color
=
MaterialColor
.
darkText
.
others
detailColor
=
MaterialColor
.
darkText
.
others
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