Commit 4451c147 by Daniel Dahan

update README for release

parent d5c7dfcf
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* 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 */; }; 967513EE1C13EB69009F455A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513ED1C13EB69009F455A /* AppDelegate.swift */; };
967513F01C13EB69009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513EF1C13EB69009F455A /* ViewController.swift */; }; 967513F01C13EB69009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513EF1C13EB69009F455A /* ViewController.swift */; };
967513F51C13EB69009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513F41C13EB69009F455A /* Assets.xcassets */; }; 967513F51C13EB69009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513F41C13EB69009F455A /* Assets.xcassets */; };
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
9605903A1C38C70D00691E88 /* MaterialKit.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 */
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; }; 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>"; }; 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>"; }; 967513EF1C13EB69009F455A /* 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 = (
960590391C38C70D00691E88 /* MaterialKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
967513E11C13EB69009F455A = { 967513E11C13EB69009F455A = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
960590381C38C70D00691E88 /* MaterialKit.framework */,
967513EC1C13EB69009F455A /* ImageCardView */, 967513EC1C13EB69009F455A /* ImageCardView */,
967513EB1C13EB69009F455A /* Products */, 967513EB1C13EB69009F455A /* Products */,
); );
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* 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 */; }; 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 */; };
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
960590371C38B80400691E88 /* MaterialKit.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -30,7 +27,6 @@ ...@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference 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; }; 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>"; };
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
960590361C38B80400691E88 /* MaterialKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
966F57941C226BAA009185B7 = { 966F57941C226BAA009185B7 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
960590351C38B80400691E88 /* MaterialKit.framework */,
966F579F1C226BAA009185B7 /* TextField */, 966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */, 966F579E1C226BAA009185B7 /* Products */,
); );
......
...@@ -50,7 +50,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -50,7 +50,7 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.textColor = MaterialColor.black nameField.textColor = MaterialColor.black
nameField.titleLabel = UILabel() nameField.titleLabel = UILabel()
nameField.titleLabel!.font = RobotoFont.mediumWithSize(12) nameField.titleLabel!.font = RobotoFont.mediumWithSize(12)
nameField.titleLabelTextColor = MaterialColor.grey.lighten2 nameField.titleLabelTextColor = MaterialColor.grey.lighten1
nameField.titleLabelActiveTextColor = MaterialColor.blue.accent3 nameField.titleLabelActiveTextColor = MaterialColor.blue.accent3
nameField.clearButtonMode = .WhileEditing nameField.clearButtonMode = .WhileEditing
view.addSubview(nameField) view.addSubview(nameField)
...@@ -68,7 +68,7 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -68,7 +68,7 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField.textColor = MaterialColor.black emailField.textColor = MaterialColor.black
emailField.titleLabel = UILabel() emailField.titleLabel = UILabel()
emailField.titleLabel!.font = RobotoFont.mediumWithSize(12) emailField.titleLabel!.font = RobotoFont.mediumWithSize(12)
emailField.titleLabelTextColor = MaterialColor.grey.lighten2 emailField.titleLabelTextColor = MaterialColor.grey.lighten1
emailField.titleLabelActiveTextColor = MaterialColor.blue.accent3 emailField.titleLabelActiveTextColor = MaterialColor.blue.accent3
emailField.clearButtonMode = .WhileEditing emailField.clearButtonMode = .WhileEditing
emailField.detailLabel = UILabel() emailField.detailLabel = UILabel()
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
960590221C388FD800691E88 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 960590211C388FD800691E88 /* ViewController.swift */; }; 960590221C388FD800691E88 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 960590211C388FD800691E88 /* ViewController.swift */; };
960590271C388FD800691E88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 960590261C388FD800691E88 /* Assets.xcassets */; }; 960590271C388FD800691E88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 960590261C388FD800691E88 /* Assets.xcassets */; };
9605902A1C388FD800691E88 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 960590281C388FD800691E88 /* LaunchScreen.storyboard */; }; 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 */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
960590331C38924200691E88 /* MaterialKit.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -36,7 +33,6 @@ ...@@ -36,7 +33,6 @@
960590261C388FD800691E88 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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 */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
960590321C38924200691E88 /* MaterialKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
960590131C388FD800691E88 = { 960590131C388FD800691E88 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
960590311C38924200691E88 /* MaterialKit.framework */,
9605901E1C388FD800691E88 /* TextView */, 9605901E1C388FD800691E88 /* TextView */,
9605901D1C388FD800691E88 /* Products */, 9605901D1C388FD800691E88 /* Products */,
); );
......
...@@ -41,7 +41,7 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate { ...@@ -41,7 +41,7 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
text.delegate = self text.delegate = self
text.textStorage.addLayoutManager(layoutManager) text.textStorage.addLayoutManager(layoutManager)
textView = TextView(frame: CGRectNull, textContainer: textContainer) textView = TextView(textContainer: textContainer)
textView.delegate = self textView.delegate = self
textView.editable = true textView.editable = true
textView.selectable = true textView.selectable = true
......
...@@ -29,6 +29,8 @@ Run carthage to build the framework and drag the built MaterialKit.framework int ...@@ -29,6 +29,8 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
### Table of Contents ### Table of Contents
* [MaterialColor](#materialcolor) * [MaterialColor](#materialcolor)
* [TextField](#textfield)
* [TextView](#textview)
* [MaterialLayer](#materiallayer) * [MaterialLayer](#materiallayer)
* [MaterialView](#materialview) * [MaterialView](#materialview)
* [MaterialPulseView](#materialpulseview) * [MaterialPulseView](#materialpulseview)
...@@ -44,8 +46,6 @@ Run carthage to build the framework and drag the built MaterialKit.framework int ...@@ -44,8 +46,6 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
* [Crop Image](#cropimage) * [Crop Image](#cropimage)
* [Save Image To PhotoLibrary](#saveimagetophotolibrary) * [Save Image To PhotoLibrary](#saveimagetophotolibrary)
* [Asynchronous Image Loading](#asynchronousimageloading) * [Asynchronous Image Loading](#asynchronousimageloading)
* [TextField](#textfield)
* [TextView](#textview)
* [Lines of Text](#linesoftext) * [Lines of Text](#linesoftext)
* [Trim Whitespace](#trimwhitespace) * [Trim Whitespace](#trimwhitespace)
...@@ -75,6 +75,116 @@ let button: FabButton = FabButton() ...@@ -75,6 +75,116 @@ let button: FabButton = FabButton()
button.backgroundColor = MaterialColor.blue.darken1 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.
![MaterialKitTextField](http://www.materialkit.io/MK/MaterialKitTextField.gif)
```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.
![MaterialKitTextView](http://www.materialkit.io/MK/MaterialKitTextView.gif)
```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\nblock of text\nthat has\nnewlines."
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"/> <a name="materiallayer"/>
### MaterialLayer ### MaterialLayer
...@@ -574,9 +684,9 @@ Add a new dimension of interactivity with CaptureView. CaptureView is a fully fu ...@@ -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. 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 ```swift
let p1: UIImage? = UIImage(named: "img1") let img1: UIImage? = UIImage(named: "photo")
let p2: UIImage? = p1?.resize(toWidth: 300) let img2: UIImage? = img1?.resize(toWidth: 300)
let p3: UIImage? = p1?.resize(toHeight: 200) let img3: UIImage? = img1?.resize(toHeight: 200)
``` ```
<a name="cropimage"/> <a name="cropimage"/>
...@@ -585,8 +695,8 @@ let p3: UIImage? = p1?.resize(toHeight: 200) ...@@ -585,8 +695,8 @@ let p3: UIImage? = p1?.resize(toHeight: 200)
Crop images easily with UIImage crop. Below is an example: Crop images easily with UIImage crop. Below is an example:
```swift ```swift
let p1: UIImage? = UIImage(named: "img1") let img1: UIImage? = UIImage(named: "photo")
let p2: UIImage? = p1?.crop(toWidth: 400, toHeight: 200) let img2: UIImage? = img1?.crop(toWidth: 400, toHeight: 200)
``` ```
<a name="saveimagetophotolibrary"/> <a name="saveimagetophotolibrary"/>
...@@ -595,15 +705,15 @@ let p2: UIImage? = p1?.crop(toWidth: 400, toHeight: 200) ...@@ -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. 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 ```swift
let p: UIImage? = UIImage(named: "img1") let img: UIImage? = UIImage(named: "photo")
p?.crop(toWidth: 400, toHeight: 200)?.writeToPhotoLibrary() img?.crop(toWidth: 400, toHeight: 200)?.writeToPhotoLibrary()
``` ```
It is also possible to specify a target handler when saving to the PhotoLibrary. It is also possible to specify a target handler when saving to the PhotoLibrary.
```swift ```swift
let p: UIImage? = UIImage(named: "img1") let img: UIImage? = UIImage(named: "photo")
p?.writeToPhotoLibrary(target: self) img?.writeToPhotoLibrary(target: self)
``` ```
Add the PhotoLibrary save handler to the target object. Add the PhotoLibrary save handler to the target object.
...@@ -632,116 +742,6 @@ UIImage.contentsOfURL(url) { (image: UIImage?, error: NSError?) in ...@@ -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.
![MaterialKitTextField](http://www.materialkit.io/MK/MaterialKitTextField.gif)
```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.
![MaterialKitTextView](http://www.materialkit.io/MK/MaterialKitTextView.gif)
```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\nblock of text\nthat has\nnewlines."
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 ### License
[AGPL-3.0](http://choosealicense.com/licenses/agpl-3.0/) [AGPL-3.0](http://choosealicense.com/licenses/agpl-3.0/)
...@@ -246,11 +246,6 @@ public class TextField : UITextField { ...@@ -246,11 +246,6 @@ public class TextField : UITextField {
public var titleLabelActiveTextColor: UIColor? public var titleLabelActiveTextColor: UIColor?
/** /**
:name: detailLabelActiveTextColor
*/
public var detailLabelActiveTextColor: UIColor?
/**
The detail UILabel that is displayed when the detailLabelHidden property The detail UILabel that is displayed when the detailLabelHidden property
is set to false. is set to false.
*/ */
...@@ -261,6 +256,12 @@ public class TextField : UITextField { ...@@ -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 :name: detailLabelHidden
*/ */
public var detailLabelHidden: Bool = false { public var detailLabelHidden: Bool = false {
...@@ -276,8 +277,10 @@ public class TextField : UITextField { ...@@ -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) { public required init?(coder aDecoder: NSCoder) {
depth = .None depth = .None
...@@ -289,7 +292,10 @@ public class TextField : UITextField { ...@@ -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) { public override init(frame: CGRect) {
depth = .None depth = .None
...@@ -300,9 +306,7 @@ public class TextField : UITextField { ...@@ -300,9 +306,7 @@ public class TextField : UITextField {
prepareView() prepareView()
} }
/** /// A convenience initializer that is mostly used with AutoLayout.
:name: init
*/
public convenience init() { public convenience init() {
self.init(frame: CGRectNull) self.init(frame: CGRectNull)
} }
...@@ -383,11 +387,16 @@ public class TextField : UITextField { ...@@ -383,11 +387,16 @@ public class TextField : UITextField {
prepareBottomBorderLayer() prepareBottomBorderLayer()
} }
/** /// Handler for text editing began.
:name: textFieldDidBegin
*/
internal func textFieldDidBegin(textField: TextField) { 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 { if 0 == text?.utf16.count {
titleLabel?.textColor = titleLabelTextColor titleLabel?.textColor = titleLabelTextColor
bottomBorderLayer.backgroundColor = titleLabelTextColor?.CGColor bottomBorderLayer.backgroundColor = titleLabelTextColor?.CGColor
...@@ -398,9 +407,7 @@ public class TextField : UITextField { ...@@ -398,9 +407,7 @@ public class TextField : UITextField {
} }
} }
/** /// Handler for text changed.
:name: textFieldDidChange
*/
internal func textFieldDidChange(textField: TextField) { internal func textFieldDidChange(textField: TextField) {
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
showTitleLabel() showTitleLabel()
...@@ -412,9 +419,7 @@ public class TextField : UITextField { ...@@ -412,9 +419,7 @@ public class TextField : UITextField {
} }
} }
/** /// Handler for text editing ended.
:name: textFieldDidEnd
*/
internal func textFieldDidEnd(textField: TextField) { internal func textFieldDidEnd(textField: TextField) {
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
showTitleLabel() showTitleLabel()
...@@ -432,9 +437,7 @@ public class TextField : UITextField { ...@@ -432,9 +437,7 @@ public class TextField : UITextField {
} }
} }
/** /// Prepares the titleLabel property.
:name: prepareTitleLabel
*/
private func prepareTitleLabel() { private func prepareTitleLabel() {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
MaterialAnimation.animationDisabled { MaterialAnimation.animationDisabled {
...@@ -451,9 +454,7 @@ public class TextField : UITextField { ...@@ -451,9 +454,7 @@ public class TextField : UITextField {
} }
} }
/** /// Prepares the detailLabel property.
:name: prepareDetailLabel
*/
private func prepareDetailLabel() { private func prepareDetailLabel() {
if let v: UILabel = detailLabel { if let v: UILabel = detailLabel {
MaterialAnimation.animationDisabled { MaterialAnimation.animationDisabled {
...@@ -469,16 +470,12 @@ public class TextField : UITextField { ...@@ -469,16 +470,12 @@ public class TextField : UITextField {
} }
} }
/** /// Prepares the bottomBorderLayer property.
:name: prepareBottomBorderLayer
*/
private func prepareBottomBorderLayer() { private func prepareBottomBorderLayer() {
layer.addSublayer(bottomBorderLayer) layer.addSublayer(bottomBorderLayer)
} }
/** /// Shows and animates the titleLabel property.
:name: showTitleLabel
*/
private func showTitleLabel() { private func showTitleLabel() {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
v.frame.size.height = v.font.pointSize v.frame.size.height = v.font.pointSize
...@@ -490,9 +487,7 @@ public class TextField : UITextField { ...@@ -490,9 +487,7 @@ public class TextField : UITextField {
} }
} }
/** /// Hides and animates the titleLabel property.
:name: hideTitleLabel
*/
private func hideTitleLabel() { private func hideTitleLabel() {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
UIView.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
...@@ -504,12 +499,9 @@ public class TextField : UITextField { ...@@ -504,12 +499,9 @@ public class TextField : UITextField {
} }
} }
/** /// Shows and animates the detailLabel property.
:name: showDetailLabel
*/
private func showDetailLabel() { private func showDetailLabel() {
if let v: UILabel = detailLabel { if let v: UILabel = detailLabel {
v.frame.size.height = v.font.pointSize
v.hidden = false v.hidden = false
UIView.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
v.alpha = 1 v.alpha = 1
...@@ -518,9 +510,7 @@ public class TextField : UITextField { ...@@ -518,9 +510,7 @@ public class TextField : UITextField {
} }
} }
/** /// Hides and animates the detailLabel property.
:name: hideDetailLabel
*/
private func hideDetailLabel() { private func hideDetailLabel() {
if let v: UILabel = detailLabel { if let v: UILabel = detailLabel {
UIView.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
......
...@@ -241,28 +241,21 @@ public class TextView: UITextView { ...@@ -241,28 +241,21 @@ public class TextView: UITextView {
/// The color of the titleLabel text when the textView is active. /// The color of the titleLabel text when the textView is active.
public var titleLabelActiveTextColor: UIColor? public var titleLabelActiveTextColor: UIColor?
/** /// Placeholder UILabel view.
:name: placeholderLabel
*/
public var placeholderLabel: UILabel? { public var placeholderLabel: UILabel? {
didSet { didSet {
preparePlaceholderLabel() preparePlaceholderLabel()
} }
} }
/// An override to the text property.
/**
:name: text
*/
public override var text: String! { public override var text: String! {
didSet { didSet {
handleTextViewTextDidChange() handleTextViewTextDidChange()
} }
} }
/** /// An override to the attributedText property.
:name: attributedText
*/
public override var attributedText: NSAttributedString! { public override var attributedText: NSAttributedString! {
didSet { didSet {
handleTextViewTextDidChange() handleTextViewTextDidChange()
...@@ -270,7 +263,8 @@ public class TextView: UITextView { ...@@ -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 { public var textContainerInsetPreset: MaterialEdgeInsetPreset = .None {
didSet { didSet {
...@@ -278,9 +272,7 @@ public class TextView: UITextView { ...@@ -278,9 +272,7 @@ public class TextView: UITextView {
} }
} }
/** /// Text container UIEdgeInset property.
:name: textContainerInset
*/
public override var textContainerInset: UIEdgeInsets { public override var textContainerInset: UIEdgeInsets {
didSet { didSet {
reloadView() reloadView()
...@@ -288,7 +280,8 @@ public class TextView: UITextView { ...@@ -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) { public required init?(coder aDecoder: NSCoder) {
depth = .None depth = .None
...@@ -300,7 +293,10 @@ public class TextView: UITextView { ...@@ -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?) { public override init(frame: CGRect, textContainer: NSTextContainer?) {
depth = .None depth = .None
...@@ -311,9 +307,17 @@ public class TextView: UITextView { ...@@ -311,9 +307,17 @@ public class TextView: UITextView {
prepareView() 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 { deinit {
removeNotificationHandlers() removeNotificationHandlers()
} }
...@@ -385,9 +389,7 @@ public class TextView: UITextView { ...@@ -385,9 +389,7 @@ public class TextView: UITextView {
} }
} }
/** /// Reloads necessary components when the view has changed.
:name: reloadView
*/
internal func reloadView() { internal func reloadView() {
if let p = placeholderLabel { if let p = placeholderLabel {
removeConstraints(constraints) removeConstraints(constraints)
...@@ -400,21 +402,23 @@ public class TextView: UITextView { ...@@ -400,21 +402,23 @@ public class TextView: UITextView {
} }
} }
/** /// Notification handler for when text editing began.
:name: textFieldDidBegin
*/
internal func handleTextViewTextDidBegin() { internal func handleTextViewTextDidBegin() {
titleLabel?.text = placeholderLabel?.text if let v: UILabel = titleLabel {
if 0 == text?.utf16.count { if v.hidden {
titleLabel?.textColor = titleLabelTextColor let h: CGFloat = v.font.pointSize
} else { v.frame = CGRectMake(0, -h, bounds.width, h)
titleLabel?.textColor = titleLabelActiveTextColor v.text = placeholderLabel?.text
if 0 == text?.utf16.count {
v.textColor = titleLabelTextColor
} else {
v.textColor = titleLabelActiveTextColor
}
}
} }
} }
/** /// Notification handler for when text changed.
:name: textFieldDidChange
*/
internal func handleTextViewTextDidChange() { internal func handleTextViewTextDidChange() {
if let p = placeholderLabel { if let p = placeholderLabel {
p.hidden = !text.isEmpty p.hidden = !text.isEmpty
...@@ -428,9 +432,7 @@ public class TextView: UITextView { ...@@ -428,9 +432,7 @@ public class TextView: UITextView {
} }
} }
/** /// Notification handler for when text editing ended.
:name: textFieldDidEnd
*/
internal func handleTextViewTextDidEnd() { internal func handleTextViewTextDidEnd() {
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
showTitleLabel() showTitleLabel()
...@@ -447,9 +449,13 @@ public class TextView: UITextView { ...@@ -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() { private func prepareView() {
textContainerInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0) textContainerInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
...@@ -459,6 +465,7 @@ public class TextView: UITextView { ...@@ -459,6 +465,7 @@ public class TextView: UITextView {
reloadView() reloadView()
} }
/// prepares the placeholderLabel property.
private func preparePlaceholderLabel() { private func preparePlaceholderLabel() {
if let v: UILabel = placeholderLabel { if let v: UILabel = placeholderLabel {
v.translatesAutoresizingMaskIntoConstraints = false v.translatesAutoresizingMaskIntoConstraints = false
...@@ -481,8 +488,6 @@ public class TextView: UITextView { ...@@ -481,8 +488,6 @@ public class TextView: UITextView {
v.alpha = 0 v.alpha = 0
} }
titleLabel?.text = placeholderLabel?.text titleLabel?.text = placeholderLabel?.text
let h: CGFloat = v.font.pointSize
v.frame = CGRectMake(0, -h, bounds.width, h)
addSubview(v) addSubview(v)
} }
} }
...@@ -490,7 +495,6 @@ public class TextView: UITextView { ...@@ -490,7 +495,6 @@ public class TextView: UITextView {
/// Shows and animates the titleLabel property. /// Shows and animates the titleLabel property.
private func showTitleLabel() { private func showTitleLabel() {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
v.frame.size.height = v.font.pointSize
v.hidden = false v.hidden = false
UIView.animateWithDuration(0.25, animations: { UIView.animateWithDuration(0.25, animations: {
v.alpha = 1 v.alpha = 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment