Commit ee64ef6d by Daniel Dahan

issue-301, updated TextField and examples with fix.

parent f22d7bdb
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
......
...@@ -32,29 +32,21 @@ import UIKit ...@@ -32,29 +32,21 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
@IBOutlet weak var cardView: CardView! @IBOutlet weak var cardView: CardView!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
// Examples of using CardView prepareCardView()
prepareCardViewExample()
} }
/** /// Prepares the view.
:name: prepareView
:description: General preparation statements.
*/
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/** /// Prepares the cardView.
:name: prepareCardViewExample func prepareCardView() {
:description: General usage example.
*/
func prepareCardViewExample() {
// Title label. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.text = "Welcome Back!" titleLabel.text = "Welcome Back!"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "MaterialKitImageCardViewBackgroundImage.png", "filename" : "MaterialDesign.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_favorite_grey_darken_2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_grey_darken_2@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_grey_darken_2@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_share_grey_darken_2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_share_grey_darken_2@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_share_grey_darken_2@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_star_grey_darken_2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_star_grey_darken_2@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_star_grey_darken_2@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--View Controller--> <!--View Controller-->
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
</constraints> </constraints>
</view> </view>
<connections> <connections>
<outlet property="imageCardView" destination="XJ3-7l-unK" id="nrC-Eb-oNY"/> <outlet property="topCardView" destination="XJ3-7l-unK" id="4Rb-ki-8YN"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
......
...@@ -32,61 +32,62 @@ import UIKit ...@@ -32,61 +32,62 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
@IBOutlet weak var topCardView: ImageCardView!
@IBOutlet weak var imageCardView: ImageCardView!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
// Example of image card view prepareTopCardView()
prepareImageCardViewExample()
} }
/** /// Prepares the view.
:name: prepareImageCardViewExample private func prepareView() {
:description: General preparation statements. view.backgroundColor = MaterialColor.white
*/ }
func prepareImageCardViewExample() {
imageCardView.divider = false /// Prepares the topCardView.
imageCardView.maxImageHeight = 130 func prepareTopCardView() {
topCardView.divider = false
// Image. topCardView.maxImageHeight = 130
imageCardView.image = UIImage(named: "MaterialImageCardViewBackgroundImage") topCardView.image = UIImage(named: "MaterialDesign")
// Title label. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.text = "Material Design" titleLabel.text = "Material Design"
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(24) titleLabel.font = RobotoFont.regularWithSize(24)
imageCardView.titleLabel = titleLabel topCardView.titleLabel = titleLabel
imageCardView.titleLabelInset.top = 80 topCardView.titleLabelInset.top = 80
// Star button. // Star button.
let img1: UIImage? = UIImage(named: "ic_star_grey_darken_2") let img1: UIImage? = MaterialIcon.cm.star
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
btn1.pulseColor = MaterialColor.blueGrey.lighten1 btn1.pulseColor = MaterialColor.blueGrey.lighten1
btn1.tintColor = MaterialColor.blueGrey.lighten1
btn1.pulseScale = false btn1.pulseScale = false
btn1.setImage(img1, forState: .Normal) btn1.setImage(img1, forState: .Normal)
btn1.setImage(img1, forState: .Highlighted) btn1.setImage(img1, forState: .Highlighted)
// Favorite button. // Bell button.
let img2: UIImage? = UIImage(named: "ic_favorite_grey_darken_2") let img2: UIImage? = MaterialIcon.cm.bell
let btn2: FlatButton = FlatButton() let btn2: FlatButton = FlatButton()
btn2.pulseColor = MaterialColor.blueGrey.lighten1 btn2.pulseColor = MaterialColor.blueGrey.lighten1
btn2.tintColor = MaterialColor.blueGrey.lighten1
btn2.pulseScale = false btn2.pulseScale = false
btn2.setImage(img2, forState: .Normal) btn2.setImage(img2, forState: .Normal)
btn2.setImage(img2, forState: .Highlighted) btn2.setImage(img2, forState: .Highlighted)
// Share button. // Share button.
let img3: UIImage? = UIImage(named: "ic_share_grey_darken_2") let img3: UIImage? = MaterialIcon.cm.share
let btn3: FlatButton = FlatButton() let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.blueGrey.lighten1 btn3.pulseColor = MaterialColor.blueGrey.lighten1
btn3.tintColor = MaterialColor.blueGrey.lighten1
btn3.pulseScale = false btn3.pulseScale = false
btn3.setImage(img3, forState: .Normal) btn3.setImage(img3, forState: .Normal)
btn3.setImage(img3, forState: .Highlighted) btn3.setImage(img3, forState: .Highlighted)
// Add buttons to right side. // Add buttons to right side.
imageCardView.rightButtons = [btn1, btn2, btn3] topCardView.rightButtons = [btn1, btn2, btn3]
} }
} }
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
96D528071C8198AD00D3BDD1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D528051C8198AD00D3BDD1 /* Main.storyboard */; }; 96D528071C8198AD00D3BDD1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D528051C8198AD00D3BDD1 /* Main.storyboard */; };
96D528091C8198AD00D3BDD1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96D528081C8198AD00D3BDD1 /* Assets.xcassets */; }; 96D528091C8198AD00D3BDD1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96D528081C8198AD00D3BDD1 /* Assets.xcassets */; };
96D5280C1C8198AD00D3BDD1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */; }; 96D5280C1C8198AD00D3BDD1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */; };
F602C1681CBDEEB8003DFE27 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F602C1671CBDEEB8003DFE27 /* Material.framework */; };
F602C1691CBDEEB8003DFE27 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F602C1671CBDEEB8003DFE27 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F602C16B1CBDEEE4003DFE27 /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -24,7 +21,6 @@ ...@@ -24,7 +21,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
F602C1691CBDEEB8003DFE27 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -39,9 +35,6 @@ ...@@ -39,9 +35,6 @@
96D528081C8198AD00D3BDD1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96D528081C8198AD00D3BDD1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96D5280B1C8198AD00D3BDD1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 96D5280B1C8198AD00D3BDD1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
96D5280D1C8198AD00D3BDD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 96D5280D1C8198AD00D3BDD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F602C1651CBDEE85003DFE27 /* Material.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Material.framework; path = "../../../build/Debug-iphoneos/Material.framework"; sourceTree = "<group>"; };
F602C1671CBDEEB8003DFE27 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/ramon/Library/Developer/Xcode/DerivedData/Material-himrdtrjxqulxbgtyvxqqgkjdthx/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -49,7 +42,6 @@ ...@@ -49,7 +42,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
F602C1681CBDEEB8003DFE27 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -59,8 +51,6 @@ ...@@ -59,8 +51,6 @@
96D527F51C8198AD00D3BDD1 = { 96D527F51C8198AD00D3BDD1 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
F602C1671CBDEEB8003DFE27 /* Material.framework */,
F602C1651CBDEE85003DFE27 /* Material.framework */,
96D528001C8198AD00D3BDD1 /* TextField */, 96D528001C8198AD00D3BDD1 /* TextField */,
96D527FF1C8198AD00D3BDD1 /* Products */, 96D527FF1C8198AD00D3BDD1 /* Products */,
); );
...@@ -83,7 +73,6 @@ ...@@ -83,7 +73,6 @@
96D528081C8198AD00D3BDD1 /* Assets.xcassets */, 96D528081C8198AD00D3BDD1 /* Assets.xcassets */,
96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */, 96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */,
96D5280D1C8198AD00D3BDD1 /* Info.plist */, 96D5280D1C8198AD00D3BDD1 /* Info.plist */,
F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */,
); );
path = TextField; path = TextField;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -162,7 +151,6 @@ ...@@ -162,7 +151,6 @@
files = ( files = (
96D528041C8198AD00D3BDD1 /* ViewController.swift in Sources */, 96D528041C8198AD00D3BDD1 /* ViewController.swift in Sources */,
96D528021C8198AD00D3BDD1 /* AppDelegate.swift in Sources */, 96D528021C8198AD00D3BDD1 /* AppDelegate.swift in Sources */,
F602C16B1CBDEEE4003DFE27 /* ViewController2.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--View Controller--> <!--View Controller-->
...@@ -34,25 +33,12 @@ ...@@ -34,25 +33,12 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
</textField> </textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ROk-Om-Aix">
<rect key="frame" x="277" y="285" width="46" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="g5u-eh-klu"/>
<constraint firstAttribute="width" constant="46" id="pEY-9N-KAi"/>
</constraints>
<state key="normal" title="Open"/>
<connections>
<segue destination="bnT-id-zXl" kind="show" id="SQ4-R4-FyL"/>
</connections>
</button>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints> <constraints>
<constraint firstItem="3zW-lR-Siu" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="21" id="4lG-n9-phz"/> <constraint firstItem="3zW-lR-Siu" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="21" id="4lG-n9-phz"/>
<constraint firstItem="fUS-ww-GD9" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="NRT-ra-UCs"/> <constraint firstItem="fUS-ww-GD9" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="NRT-ra-UCs"/>
<constraint firstItem="3zW-lR-Siu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Xbp-rO-2qd"/> <constraint firstItem="3zW-lR-Siu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Xbp-rO-2qd"/>
<constraint firstItem="ROk-Om-Aix" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="iMc-Rh-hn6"/>
<constraint firstItem="ROk-Om-Aix" firstAttribute="top" secondItem="fUS-ww-GD9" secondAttribute="bottom" constant="98" id="qM7-sR-btl"/>
<constraint firstItem="fUS-ww-GD9" firstAttribute="top" secondItem="3zW-lR-Siu" secondAttribute="bottom" constant="86" id="ueA-T8-0vM"/> <constraint firstItem="fUS-ww-GD9" firstAttribute="top" secondItem="3zW-lR-Siu" secondAttribute="bottom" constant="86" id="ueA-T8-0vM"/>
</constraints> </constraints>
</view> </view>
...@@ -63,65 +49,7 @@ ...@@ -63,65 +49,7 @@
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects> </objects>
</scene> <point key="canvasLocation" x="427" y="466"/>
<!--View Controller2-->
<scene sceneID="crp-rI-egd">
<objects>
<viewController id="bnT-id-zXl" customClass="ViewController2" customModule="TextField" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="xWq-9m-5dl"/>
<viewControllerLayoutGuide type="bottom" id="JCe-cw-Htq"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="s6w-a0-kH1">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Eeh-Ol-bZG" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="63" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="27N-Rl-xug"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="YjB-bn-zu7" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="179" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="dtc-xl-jHa"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fqE-3b-mxt">
<rect key="frame" x="534" y="28" width="46" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="46" id="ukl-j3-utm"/>
<constraint firstAttribute="height" constant="30" id="zSF-no-ylx"/>
</constraints>
<state key="normal" title="Close"/>
<connections>
<action selector="close:" destination="bnT-id-zXl" eventType="touchUpInside" id="lYs-c9-ZoD"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="YjB-bn-zu7" firstAttribute="centerX" secondItem="s6w-a0-kH1" secondAttribute="centerX" id="0qi-DP-6HZ"/>
<constraint firstItem="fqE-3b-mxt" firstAttribute="top" secondItem="xWq-9m-5dl" secondAttribute="bottom" constant="8" id="7T2-D0-0n4"/>
<constraint firstAttribute="trailingMargin" secondItem="fqE-3b-mxt" secondAttribute="trailing" id="K75-oB-FHc"/>
<constraint firstItem="YjB-bn-zu7" firstAttribute="top" secondItem="Eeh-Ol-bZG" secondAttribute="bottom" constant="86" id="VJX-9a-FzT"/>
<constraint firstItem="Eeh-Ol-bZG" firstAttribute="centerX" secondItem="s6w-a0-kH1" secondAttribute="centerX" id="aHo-N6-p4D"/>
<constraint firstItem="Eeh-Ol-bZG" firstAttribute="top" secondItem="xWq-9m-5dl" secondAttribute="bottom" constant="43" id="h39-tb-Paq"/>
</constraints>
</view>
<connections>
<outlet property="emailField" destination="YjB-bn-zu7" id="0Aj-Dj-nEi"/>
<outlet property="nameField" destination="Eeh-Ol-bZG" id="PQN-kr-OvB"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="1Ho-Zx-Ti5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1011" y="353"/>
</scene> </scene>
</scenes> </scenes>
</document> </document>
//
// ViewController2.swift
// TextField
//
// Created by Ramon Vicente on 4/13/16.
// Copyright © 2016 CosmicMind, Inc. All rights reserved.
//
import UIKit
import Material
class ViewController2: UIViewController, TextFieldDelegate {
@IBOutlet weak var nameField: TextField!
@IBOutlet weak var emailField: TextField!
@IBAction func close(sender: UIButton) {
dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareNameField()
prepareEmailField()
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.white
}
/// Prepares the name TextField.
private func prepareNameField() {
nameField.placeholder = "First Name"
}
/// Prepares the email TextField.
private func prepareEmailField() {
emailField.delegate = self
emailField.placeholder = "Email"
/*
Used to display the error message, which is displayed when
the user presses the 'return' key.
*/
emailField.detailLabel = UILabel()
emailField.detailLabel!.text = "Email is incorrect."
emailField.detailLabel!.font = RobotoFont.regularWithSize(12)
emailField.detailLabelActiveColor = MaterialColor.red.accent3
// emailField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
}
/// Executed when the 'return' key is pressed when using the emailField.
func textFieldShouldReturn(textField: UITextField) -> Bool {
(textField as! TextField).detailLabelHidden = 0 == textField.text?.utf16.count
return false
}
}
\ No newline at end of file
...@@ -501,7 +501,7 @@ public class TextField : UITextField { ...@@ -501,7 +501,7 @@ public class TextField : UITextField {
/// Reloads the view. /// Reloads the view.
public func reloadView() { public func reloadView() {
/// Align the clearButton. /// Align the clearButton.
clearButton.frame = CGRectMake(width - height, 0, height, height) clearButton.frame = CGRectMake(width - height, 2, height - 4, height - 4)
} }
...@@ -622,9 +622,9 @@ public class TextField : UITextField { ...@@ -622,9 +622,9 @@ public class TextField : UITextField {
/// Shows and animates the titleLabel property. /// Shows and animates the titleLabel property.
private func showTitleLabel() { private func showTitleLabel() {
if titleLabel.hidden { if titleLabel.hidden {
if let s: String = placeholder { if let v: String = placeholder {
titleLabel.text = s titleLabel.text = v
placeholderText = s placeholderText = v
placeholder = nil placeholder = nil
} }
let h: CGFloat = ceil(titleLabel.font.lineHeight) let h: CGFloat = ceil(titleLabel.font.lineHeight)
...@@ -632,10 +632,10 @@ public class TextField : UITextField { ...@@ -632,10 +632,10 @@ public class TextField : UITextField {
titleLabel.font = font titleLabel.font = font
titleLabel.hidden = false titleLabel.hidden = false
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self { if let v: TextField = self {
self!.titleLabel.alpha = 1 v.titleLabel.alpha = 1
self!.titleLabel.transform = CGAffineTransformScale(self!.titleLabel.transform, 0.75, 0.75) v.titleLabel.transform = CGAffineTransformScale(v.titleLabel.transform, 0.75, 0.75)
self!.titleLabel.frame = CGRectMake(0, -(self!.titleLabelAnimationDistance + h), self!.bounds.width, h) v.titleLabel.frame = CGRectMake(0, -(v.titleLabelAnimationDistance + h), v.bounds.width, h)
} }
}) })
} }
...@@ -644,14 +644,14 @@ public class TextField : UITextField { ...@@ -644,14 +644,14 @@ public class TextField : UITextField {
/// Hides and animates the titleLabel property. /// Hides and animates the titleLabel property.
private func hideTitleLabel() { private func hideTitleLabel() {
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self { if let v: TextField = self {
self!.titleLabel.transform = CGAffineTransformIdentity v.titleLabel.transform = CGAffineTransformIdentity
self!.titleLabel.frame = self!.bounds v.titleLabel.frame = v.bounds
} }
}) { [weak self] _ in }) { [weak self] _ in
if nil != self { if let v: TextField = self {
self!.placeholder = self!.placeholderText v.placeholder = v.placeholderText
self!.titleLabel.hidden = true v.titleLabel.hidden = true
} }
} }
} }
...@@ -664,8 +664,8 @@ public class TextField : UITextField { ...@@ -664,8 +664,8 @@ public class TextField : UITextField {
v.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h) v.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
v.hidden = false v.hidden = false
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self { if let s: TextField = self {
v.frame.origin.y = self!.frame.height + self!.lineLayerDistance + self!.detailLabelAnimationDistance v.frame.origin.y = s.frame.height + s.lineLayerDistance + s.detailLabelAnimationDistance
v.alpha = 1 v.alpha = 1
} }
}) })
...@@ -677,9 +677,9 @@ public class TextField : UITextField { ...@@ -677,9 +677,9 @@ public class TextField : UITextField {
private func hideDetailLabel() { private func hideDetailLabel() {
if let v: UILabel = detailLabel { if let v: UILabel = detailLabel {
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self { if let s: TextField = self {
v.alpha = 0 v.alpha = 0
v.frame.origin.y -= self!.detailLabelAnimationDistance v.frame.origin.y -= s.detailLabelAnimationDistance
} }
}) { _ in }) { _ in
v.hidden = true v.hidden = true
......
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