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
4451c147
Commit
4451c147
authored
Jan 02, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update README for release
parent
d5c7dfcf
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
208 additions
and
220 deletions
+208
-220
Examples/Programmatic/ImageCardView/ImageCardView.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+0
-6
Examples/Programmatic/TextField/TextField/ViewController.swift
+2
-2
Examples/Programmatic/TextView/TextView.xcodeproj/project.pbxproj
+0
-6
Examples/Programmatic/TextView/TextView/ViewController.swift
+1
-1
README.md
+121
-121
Sources/TextField.swift
+32
-42
Sources/TextView.swift
+46
-42
No files found.
Examples/Programmatic/ImageCardView/ImageCardView.xcodeproj/project.pbxproj
View file @
4451c147
...
...
@@ -7,6 +7,8 @@
objects
=
{
/* Begin PBXBuildFile section */
960590391C38C70D00691E88
/* MaterialKit.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590381C38C70D00691E88
/* MaterialKit.framework */
;
};
9605903A1C38C70D00691E88
/* MaterialKit.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590381C38C70D00691E88
/* MaterialKit.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
967513EE1C13EB69009F455A
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967513ED1C13EB69009F455A
/* AppDelegate.swift */
;
};
967513F01C13EB69009F455A
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967513EF1C13EB69009F455A
/* ViewController.swift */
;
};
967513F51C13EB69009F455A
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
967513F41C13EB69009F455A
/* Assets.xcassets */
;
};
...
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
9605903A1C38C70D00691E88
/* MaterialKit.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
960590381C38C70D00691E88
/* MaterialKit.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
MaterialKit.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"
;
sourceTree
=
"<absolute>"
;
};
967513EA1C13EB69009F455A
/* ImageCardView.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
ImageCardView.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
967513ED1C13EB69009F455A
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
967513EF1C13EB69009F455A
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
960590391C38C70D00691E88
/* MaterialKit.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -49,6 +54,7 @@
967513E11C13EB69009F455A
=
{
isa
=
PBXGroup
;
children
=
(
960590381C38C70D00691E88
/* MaterialKit.framework */
,
967513EC1C13EB69009F455A
/* ImageCardView */
,
967513EB1C13EB69009F455A
/* Products */
,
);
...
...
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
4451c147
...
...
@@ -7,8 +7,6 @@
objects
=
{
/* Begin PBXBuildFile section */
960590361C38B80400691E88
/* MaterialKit.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590351C38B80400691E88
/* MaterialKit.framework */
;
};
960590371C38B80400691E88
/* MaterialKit.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590351C38B80400691E88
/* MaterialKit.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
=
(
960590371C38B80400691E88
/* MaterialKit.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
960590351C38B80400691E88
/* MaterialKit.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
MaterialKit.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.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
=
(
960590361C38B80400691E88
/* MaterialKit.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -54,7 +49,6 @@
966F57941C226BAA009185B7
=
{
isa
=
PBXGroup
;
children
=
(
960590351C38B80400691E88
/* MaterialKit.framework */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579E1C226BAA009185B7
/* Products */
,
);
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
4451c147
...
...
@@ -50,7 +50,7 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabelTextColor
=
MaterialColor
.
grey
.
lighten
2
nameField
.
titleLabelTextColor
=
MaterialColor
.
grey
.
lighten
1
nameField
.
titleLabelActiveTextColor
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
view
.
addSubview
(
nameField
)
...
...
@@ -68,7 +68,7 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField
.
textColor
=
MaterialColor
.
black
emailField
.
titleLabel
=
UILabel
()
emailField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
emailField
.
titleLabelTextColor
=
MaterialColor
.
grey
.
lighten
2
emailField
.
titleLabelTextColor
=
MaterialColor
.
grey
.
lighten
1
emailField
.
titleLabelActiveTextColor
=
MaterialColor
.
blue
.
accent3
emailField
.
clearButtonMode
=
.
WhileEditing
emailField
.
detailLabel
=
UILabel
()
...
...
Examples/Programmatic/TextView/TextView.xcodeproj/project.pbxproj
View file @
4451c147
...
...
@@ -11,8 +11,6 @@
960590221C388FD800691E88
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590211C388FD800691E88
/* ViewController.swift */
;
};
960590271C388FD800691E88
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590261C388FD800691E88
/* Assets.xcassets */
;
};
9605902A1C388FD800691E88
/* LaunchScreen.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590281C388FD800691E88
/* LaunchScreen.storyboard */
;
};
960590321C38924200691E88
/* MaterialKit.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590311C38924200691E88
/* MaterialKit.framework */
;
};
960590331C38924200691E88
/* MaterialKit.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590311C38924200691E88
/* MaterialKit.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -22,7 +20,6 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
960590331C38924200691E88
/* MaterialKit.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -36,7 +33,6 @@
960590261C388FD800691E88
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
960590291C388FD800691E88
/* Base */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.storyboard
;
name
=
Base
;
path
=
Base.lproj/LaunchScreen.storyboard
;
sourceTree
=
"<group>"
;
};
9605902B1C388FD800691E88
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
960590311C38924200691E88
/* MaterialKit.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
MaterialKit.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"
;
sourceTree
=
"<absolute>"
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -44,7 +40,6 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
960590321C38924200691E88
/* MaterialKit.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -54,7 +49,6 @@
960590131C388FD800691E88
=
{
isa
=
PBXGroup
;
children
=
(
960590311C38924200691E88
/* MaterialKit.framework */
,
9605901E1C388FD800691E88
/* TextView */
,
9605901D1C388FD800691E88
/* Products */
,
);
...
...
Examples/Programmatic/TextView/TextView/ViewController.swift
View file @
4451c147
...
...
@@ -41,7 +41,7 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
text
.
delegate
=
self
text
.
textStorage
.
addLayoutManager
(
layoutManager
)
textView
=
TextView
(
frame
:
CGRectNull
,
textContainer
:
textContainer
)
textView
=
TextView
(
textContainer
:
textContainer
)
textView
.
delegate
=
self
textView
.
editable
=
true
textView
.
selectable
=
true
...
...
README.md
View file @
4451c147
...
...
@@ -29,6 +29,8 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
### Table of Contents
*
[
MaterialColor
](
#materialcolor
)
*
[
TextField
](
#textfield
)
*
[
TextView
](
#textview
)
*
[
MaterialLayer
](
#materiallayer
)
*
[
MaterialView
](
#materialview
)
*
[
MaterialPulseView
](
#materialpulseview
)
...
...
@@ -44,8 +46,6 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
*
[
Crop Image
](
#cropimage
)
*
[
Save Image To PhotoLibrary
](
#saveimagetophotolibrary
)
*
[
Asynchronous Image Loading
](
#asynchronousimageloading
)
*
[
TextField
](
#textfield
)
*
[
TextView
](
#textview
)
*
[
Lines of Text
](
#linesoftext
)
*
[
Trim Whitespace
](
#trimwhitespace
)
...
...
@@ -75,6 +75,116 @@ let button: FabButton = FabButton()
button
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
```
<a
name=
"textfield"
/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.

```
swift
let
nameField
:
TextField
=
TextField
(
frame
:
CGRectMake
(
57
,
100
,
300
,
24
))
nameField
.
placeholder
=
"First Name"
nameField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
// Add nameField to UIViewController.
view
.
addSubview
(
nameField
)
```
<a
name=
"textview"
/>
### TextView
Easily match any regular expression pattern in a body of text. Below is an example of the default hashtag pattern matching.

```
swift
class
ViewController
:
UIViewController
,
TextDelegate
,
TextViewDelegate
{
lazy
var
text
:
Text
=
Text
()
var
textView
:
TextView
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
prepareTextView
()
}
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
}
func
prepareTextView
()
{
let
layoutManager
:
NSLayoutManager
=
NSLayoutManager
()
let
textContainer
=
NSTextContainer
(
size
:
view
.
bounds
.
size
)
layoutManager
.
addTextContainer
(
textContainer
)
text
.
delegate
=
self
text
.
textStorage
.
addLayoutManager
(
layoutManager
)
textView
=
TextView
(
textContainer
:
textContainer
)
textView
.
delegate
=
self
textView
.
editable
=
true
textView
.
selectable
=
true
textView
.
font
=
RobotoFont
.
regular
textView
.
placeholderLabel
=
UILabel
()
textView
.
placeholderLabel
!.
textColor
=
MaterialColor
.
grey
.
base
textView
.
placeholderLabel
!.
text
=
"Description"
textView
.
titleLabel
=
UILabel
()
textView
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textView
.
titleLabelTextColor
=
MaterialColor
.
grey
.
lighten2
textView
.
titleLabelActiveTextColor
=
MaterialColor
.
blue
.
accent3
view
.
addSubview
(
textView
)
textView
!.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
textView
!
,
top
:
124
,
left
:
24
,
bottom
:
24
,
right
:
24
)
}
func
textWillProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
range
:
NSRange
)
{
textStorage
.
removeAttribute
(
NSFontAttributeName
,
range
:
range
)
textStorage
.
addAttribute
(
NSFontAttributeName
,
value
:
RobotoFont
.
regular
,
range
:
range
)
}
func
textDidProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
result
:
NSTextCheckingResult
?,
flags
:
NSMatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
{
textStorage
.
addAttribute
(
NSFontAttributeName
,
value
:
UIFont
.
boldSystemFontOfSize
(
16
),
range
:
result
!.
range
)
}
}
```
<a
name=
"linesoftext"
/>
### Lines of Text
Cycle through lines of text in any String. Below is an example of iterating through all lines of text in a String.
```
swift
let
text
:
String
=
"This is a
\n
block of text
\n
that has
\n
newlines."
for
line
in
text
.
lines
{
print
(
line
)
}
// Output:
// This is a
// block of text
// that has
// newlines.
```
<a
name=
"trimwhitespace"
/>
### Trim Whitespace
Remove the spaces and newlines from the beginning and end of a text block. Below is an example.
```
swift
let
text
:
String
=
"
\n
Hello World
\n
"
print
(
text
.
trim
())
// Output: Hello World
```
<a
name=
"materiallayer"
/>
### MaterialLayer
...
...
@@ -574,9 +684,9 @@ Add a new dimension of interactivity with CaptureView. CaptureView is a fully fu
Images come in all shapes and sizes. UIImage resize is a flexible way to resize images on the fly. The below example shows you how.
```
swift
let
p1
:
UIImage
?
=
UIImage
(
named
:
"img1
"
)
let
p2
:
UIImage
?
=
p
1
?
.
resize
(
toWidth
:
300
)
let
p3
:
UIImage
?
=
p
1
?
.
resize
(
toHeight
:
200
)
let
img1
:
UIImage
?
=
UIImage
(
named
:
"photo
"
)
let
img2
:
UIImage
?
=
img
1
?
.
resize
(
toWidth
:
300
)
let
img3
:
UIImage
?
=
img
1
?
.
resize
(
toHeight
:
200
)
```
<a
name=
"cropimage"
/>
...
...
@@ -585,8 +695,8 @@ let p3: UIImage? = p1?.resize(toHeight: 200)
Crop images easily with UIImage crop. Below is an example:
```
swift
let
p1
:
UIImage
?
=
UIImage
(
named
:
"img1
"
)
let
p2
:
UIImage
?
=
p
1
?
.
crop
(
toWidth
:
400
,
toHeight
:
200
)
let
img1
:
UIImage
?
=
UIImage
(
named
:
"photo
"
)
let
img2
:
UIImage
?
=
img
1
?
.
crop
(
toWidth
:
400
,
toHeight
:
200
)
```
<a
name=
"saveimagetophotolibrary"
/>
...
...
@@ -595,15 +705,15 @@ let p2: UIImage? = p1?.crop(toWidth: 400, toHeight: 200)
Keep the moment by saving your images to PhotoLibrary. Below is an example of cropping an image and saving it to the devices PhotoLibrary.
```
swift
let
p
:
UIImage
?
=
UIImage
(
named
:
"img1
"
)
p
?
.
crop
(
toWidth
:
400
,
toHeight
:
200
)?
.
writeToPhotoLibrary
()
let
img
:
UIImage
?
=
UIImage
(
named
:
"photo
"
)
img
?
.
crop
(
toWidth
:
400
,
toHeight
:
200
)?
.
writeToPhotoLibrary
()
```
It is also possible to specify a target handler when saving to the PhotoLibrary.
```
swift
let
p
:
UIImage
?
=
UIImage
(
named
:
"img1
"
)
p
?
.
writeToPhotoLibrary
(
target
:
self
)
let
img
:
UIImage
?
=
UIImage
(
named
:
"photo
"
)
img
?
.
writeToPhotoLibrary
(
target
:
self
)
```
Add the PhotoLibrary save handler to the target object.
...
...
@@ -632,116 +742,6 @@ UIImage.contentsOfURL(url) { (image: UIImage?, error: NSError?) in
}
```
<a
name=
"textfield"
/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.

```
swift
let
nameField
:
TextField
=
TextField
(
frame
:
CGRectMake
(
57
,
100
,
300
,
24
))
nameField
.
placeholder
=
"First Name"
nameField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
// Add nameField to UIViewController.
view
.
addSubview
(
nameField
)
```
<a
name=
"textview"
/>
### TextView
Easily match any regular expression pattern in a body of text. Below is an example of the default hashtag pattern matching.

```
swift
class
ViewController
:
UIViewController
,
TextDelegate
,
TextViewDelegate
{
lazy
var
text
:
Text
=
Text
()
var
textView
:
TextView
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
prepareTextView
()
}
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
}
func
prepareTextView
()
{
let
layoutManager
:
NSLayoutManager
=
NSLayoutManager
()
let
textContainer
=
NSTextContainer
(
size
:
view
.
bounds
.
size
)
layoutManager
.
addTextContainer
(
textContainer
)
text
.
delegate
=
self
text
.
textStorage
.
addLayoutManager
(
layoutManager
)
textView
=
TextView
(
frame
:
CGRectNull
,
textContainer
:
textContainer
)
textView
.
delegate
=
self
textView
.
editable
=
true
textView
.
selectable
=
true
textView
.
font
=
RobotoFont
.
regular
textView
.
placeholderLabel
=
UILabel
()
textView
.
placeholderLabel
!.
textColor
=
MaterialColor
.
grey
.
base
textView
.
placeholderLabel
!.
text
=
"Description"
textView
.
titleLabel
=
UILabel
()
textView
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textView
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
textView
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
view
.
addSubview
(
textView
)
textView
!.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
textView
!
,
top
:
124
,
left
:
24
,
bottom
:
24
,
right
:
24
)
}
func
textWillProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
range
:
NSRange
)
{
textStorage
.
removeAttribute
(
NSFontAttributeName
,
range
:
range
)
textStorage
.
addAttribute
(
NSFontAttributeName
,
value
:
RobotoFont
.
regular
,
range
:
range
)
}
func
textDidProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
result
:
NSTextCheckingResult
?,
flags
:
NSMatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
{
textStorage
.
addAttribute
(
NSFontAttributeName
,
value
:
UIFont
.
boldSystemFontOfSize
(
16
),
range
:
result
!.
range
)
}
}
```
<a
name=
"linesoftext"
/>
### Lines of Text
Cycle through lines of text in any String. Below is an example of iterating through all lines of text in a String.
```
swift
let
text
:
String
=
"This is a
\n
block of text
\n
that has
\n
newlines."
for
line
in
text
.
lines
{
print
(
line
)
}
// Output:
// This is a
// block of text
// that has
// newlines.
```
<a
name=
"trimwhitespace"
/>
### Trim Whitespace
Remove the spaces and newlines from the beginning and end of a text block. Below is an example.
```
swift
let
text
:
String
=
"
\n
Hello World
\n
"
print
(
text
.
trim
())
// Output: Hello World
```
### License
[
AGPL-3.0
](
http://choosealicense.com/licenses/agpl-3.0/
)
Sources/TextField.swift
View file @
4451c147
...
...
@@ -246,11 +246,6 @@ public class TextField : UITextField {
public
var
titleLabelActiveTextColor
:
UIColor
?
/**
:name: detailLabelActiveTextColor
*/
public
var
detailLabelActiveTextColor
:
UIColor
?
/**
The detail UILabel that is displayed when the detailLabelHidden property
is set to false.
*/
...
...
@@ -261,6 +256,12 @@ public class TextField : UITextField {
}
/**
The color of the detailLabel text when the detailLabelHidden property
is set to false.
*/
public
var
detailLabelActiveTextColor
:
UIColor
?
/**
:name: detailLabelHidden
*/
public
var
detailLabelHidden
:
Bool
=
false
{
...
...
@@ -276,8 +277,10 @@ public class TextField : UITextField {
}
}
/**
:name: init
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
depth
=
.
None
...
...
@@ -289,7 +292,10 @@ public class TextField : UITextField {
}
/**
:name: init
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public
override
init
(
frame
:
CGRect
)
{
depth
=
.
None
...
...
@@ -300,9 +306,7 @@ public class TextField : UITextField {
prepareView
()
}
/**
:name: init
*/
/// A convenience initializer that is mostly used with AutoLayout.
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
...
...
@@ -383,11 +387,16 @@ public class TextField : UITextField {
prepareBottomBorderLayer
()
}
/**
:name: textFieldDidBegin
*/
/// Handler for text editing began.
internal
func
textFieldDidBegin
(
textField
:
TextField
)
{
titleLabel
?
.
text
=
placeholder
if
let
v
:
UILabel
=
titleLabel
{
if
v
.
hidden
{
let
h
:
CGFloat
=
v
.
font
.
pointSize
v
.
frame
=
CGRectMake
(
0
,
-
h
,
bounds
.
width
,
h
)
titleLabel
?
.
text
=
placeholder
}
}
if
0
==
text
?
.
utf16
.
count
{
titleLabel
?
.
textColor
=
titleLabelTextColor
bottomBorderLayer
.
backgroundColor
=
titleLabelTextColor
?
.
CGColor
...
...
@@ -398,9 +407,7 @@ public class TextField : UITextField {
}
}
/**
:name: textFieldDidChange
*/
/// Handler for text changed.
internal
func
textFieldDidChange
(
textField
:
TextField
)
{
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
...
...
@@ -412,9 +419,7 @@ public class TextField : UITextField {
}
}
/**
:name: textFieldDidEnd
*/
/// Handler for text editing ended.
internal
func
textFieldDidEnd
(
textField
:
TextField
)
{
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
...
...
@@ -432,9 +437,7 @@ public class TextField : UITextField {
}
}
/**
:name: prepareTitleLabel
*/
/// Prepares the titleLabel property.
private
func
prepareTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
MaterialAnimation
.
animationDisabled
{
...
...
@@ -451,9 +454,7 @@ public class TextField : UITextField {
}
}
/**
:name: prepareDetailLabel
*/
/// Prepares the detailLabel property.
private
func
prepareDetailLabel
()
{
if
let
v
:
UILabel
=
detailLabel
{
MaterialAnimation
.
animationDisabled
{
...
...
@@ -469,16 +470,12 @@ public class TextField : UITextField {
}
}
/**
:name: prepareBottomBorderLayer
*/
/// Prepares the bottomBorderLayer property.
private
func
prepareBottomBorderLayer
()
{
layer
.
addSublayer
(
bottomBorderLayer
)
}
/**
:name: showTitleLabel
*/
/// Shows and animates the titleLabel property.
private
func
showTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
v
.
frame
.
size
.
height
=
v
.
font
.
pointSize
...
...
@@ -490,9 +487,7 @@ public class TextField : UITextField {
}
}
/**
:name: hideTitleLabel
*/
/// Hides and animates the titleLabel property.
private
func
hideTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
...
...
@@ -504,12 +499,9 @@ public class TextField : UITextField {
}
}
/**
:name: showDetailLabel
*/
/// Shows and animates the detailLabel property.
private
func
showDetailLabel
()
{
if
let
v
:
UILabel
=
detailLabel
{
v
.
frame
.
size
.
height
=
v
.
font
.
pointSize
v
.
hidden
=
false
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
v
.
alpha
=
1
...
...
@@ -518,9 +510,7 @@ public class TextField : UITextField {
}
}
/**
:name: hideDetailLabel
*/
/// Hides and animates the detailLabel property.
private
func
hideDetailLabel
()
{
if
let
v
:
UILabel
=
detailLabel
{
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
...
...
Sources/TextView.swift
View file @
4451c147
...
...
@@ -241,28 +241,21 @@ public class TextView: UITextView {
/// The color of the titleLabel text when the textView is active.
public
var
titleLabelActiveTextColor
:
UIColor
?
/**
:name: placeholderLabel
*/
/// Placeholder UILabel view.
public
var
placeholderLabel
:
UILabel
?
{
didSet
{
preparePlaceholderLabel
()
}
}
/**
:name: text
*/
/// An override to the text property.
public
override
var
text
:
String
!
{
didSet
{
handleTextViewTextDidChange
()
}
}
/**
:name: attributedText
*/
/// An override to the attributedText property.
public
override
var
attributedText
:
NSAttributedString
!
{
didSet
{
handleTextViewTextDidChange
()
...
...
@@ -270,7 +263,8 @@ public class TextView: UITextView {
}
/**
:name: textContainerInset
Text container UIEdgeInset preset property. This updates the
textContainerInset property with a preset value.
*/
public
var
textContainerInsetPreset
:
MaterialEdgeInsetPreset
=
.
None
{
didSet
{
...
...
@@ -278,9 +272,7 @@ public class TextView: UITextView {
}
}
/**
:name: textContainerInset
*/
/// Text container UIEdgeInset property.
public
override
var
textContainerInset
:
UIEdgeInsets
{
didSet
{
reloadView
()
...
...
@@ -288,7 +280,8 @@ public class TextView: UITextView {
}
/**
:name: init
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
depth
=
.
None
...
...
@@ -300,7 +293,10 @@ public class TextView: UITextView {
}
/**
:name: init
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public
override
init
(
frame
:
CGRect
,
textContainer
:
NSTextContainer
?)
{
depth
=
.
None
...
...
@@ -311,9 +307,17 @@ public class TextView: UITextView {
prepareView
()
}
//
// :name: deinit
//
/**
A convenience initializer that is mostly used with AutoLayout.
- Parameter textContainer: A NSTextContainer instance.
*/
public
convenience
init
(
textContainer
:
NSTextContainer
?)
{
self
.
init
(
frame
:
CGRectNull
,
textContainer
:
textContainer
)
}
/** Denitializer. This should never be called unless you know
what you are doing.
*/
deinit
{
removeNotificationHandlers
()
}
...
...
@@ -385,9 +389,7 @@ public class TextView: UITextView {
}
}
/**
:name: reloadView
*/
/// Reloads necessary components when the view has changed.
internal
func
reloadView
()
{
if
let
p
=
placeholderLabel
{
removeConstraints
(
constraints
)
...
...
@@ -400,21 +402,23 @@ public class TextView: UITextView {
}
}
/**
:name: textFieldDidBegin
*/
/// Notification handler for when text editing began.
internal
func
handleTextViewTextDidBegin
()
{
titleLabel
?
.
text
=
placeholderLabel
?
.
text
if
0
==
text
?
.
utf16
.
count
{
titleLabel
?
.
textColor
=
titleLabelTextColor
}
else
{
titleLabel
?
.
textColor
=
titleLabelActiveTextColor
if
let
v
:
UILabel
=
titleLabel
{
if
v
.
hidden
{
let
h
:
CGFloat
=
v
.
font
.
pointSize
v
.
frame
=
CGRectMake
(
0
,
-
h
,
bounds
.
width
,
h
)
v
.
text
=
placeholderLabel
?
.
text
if
0
==
text
?
.
utf16
.
count
{
v
.
textColor
=
titleLabelTextColor
}
else
{
v
.
textColor
=
titleLabelActiveTextColor
}
}
}
}
/**
:name: textFieldDidChange
*/
/// Notification handler for when text changed.
internal
func
handleTextViewTextDidChange
()
{
if
let
p
=
placeholderLabel
{
p
.
hidden
=
!
text
.
isEmpty
...
...
@@ -428,9 +432,7 @@ public class TextView: UITextView {
}
}
/**
:name: textFieldDidEnd
*/
/// Notification handler for when text editing ended.
internal
func
handleTextViewTextDidEnd
()
{
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
...
...
@@ -447,9 +449,13 @@ public class TextView: UITextView {
}
}
//
// :name: prepareView
//
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
private
func
prepareView
()
{
textContainerInset
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
backgroundColor
=
MaterialColor
.
white
...
...
@@ -459,6 +465,7 @@ public class TextView: UITextView {
reloadView
()
}
/// prepares the placeholderLabel property.
private
func
preparePlaceholderLabel
()
{
if
let
v
:
UILabel
=
placeholderLabel
{
v
.
translatesAutoresizingMaskIntoConstraints
=
false
...
...
@@ -481,8 +488,6 @@ public class TextView: UITextView {
v
.
alpha
=
0
}
titleLabel
?
.
text
=
placeholderLabel
?
.
text
let
h
:
CGFloat
=
v
.
font
.
pointSize
v
.
frame
=
CGRectMake
(
0
,
-
h
,
bounds
.
width
,
h
)
addSubview
(
v
)
}
}
...
...
@@ -490,7 +495,6 @@ public class TextView: UITextView {
/// Shows and animates the titleLabel property.
private
func
showTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
v
.
frame
.
size
.
height
=
v
.
font
.
pointSize
v
.
hidden
=
false
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
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