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
eb94bb7e
Unverified
Commit
eb94bb7e
authored
Sep 29, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added initial TextField sample project and moved Divider to a UIView extension
parent
f00e3eee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
437 additions
and
217 deletions
+437
-217
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+0
-0
Examples/Programmatic/TextField/TextField.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+7
-0
Examples/Programmatic/TextField/TextField/AppDelegate.swift
+44
-0
Examples/Programmatic/TextField/TextField/Assets.xcassets/AppIcon.appiconset/Contents.json
+69
-0
Examples/Programmatic/TextField/TextField/Base.lproj/LaunchScreen.storyboard
+27
-0
Examples/Programmatic/TextField/TextField/Info.plist
+44
-0
Examples/Programmatic/TextField/TextField/ViewController.swift
+148
-0
Material.xcworkspace/contents.xcworkspacedata
+3
-0
Sources/iOS/Bar.swift
+0
-41
Sources/iOS/BottomTabBar.swift
+0
-50
Sources/iOS/CollectionViewCell.swift
+0
-41
Sources/iOS/Divider.swift
+50
-0
Sources/iOS/ErrorTextField.swift
+5
-5
Sources/iOS/NavigationBar.swift
+0
-42
Sources/iOS/TextField.swift
+40
-38
No files found.
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
0 → 100644
View file @
eb94bb7e
This diff is collapsed.
Click to expand it.
Examples/Programmatic/TextField/TextField.xcodeproj/project.xcworkspace/contents.xcworkspacedata
0 → 100644
View file @
eb94bb7e
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version =
"1.0"
>
<FileRef
location =
"self:TextField.xcodeproj"
>
</FileRef>
</Workspace>
Examples/Programmatic/TextField/TextField/AppDelegate.swift
0 → 100644
View file @
eb94bb7e
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
import
Material
@UIApplicationMain
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
{
var
window
:
UIWindow
?
func
applicationDidFinishLaunching
(
_
application
:
UIApplication
)
{
window
=
UIWindow
(
frame
:
Device
.
bounds
)
window
!.
rootViewController
=
ViewController
()
window
!.
makeKeyAndVisible
()
}
}
Examples/Programmatic/TextField/TextField/Assets.xcassets/AppIcon.appiconset/Contents.json
0 → 100644
View file @
eb94bb7e
{
"images"
:
[
{
"idiom"
:
"iphone"
,
"size"
:
"29x29"
,
"scale"
:
"2x"
},
{
"idiom"
:
"iphone"
,
"size"
:
"29x29"
,
"scale"
:
"3x"
},
{
"idiom"
:
"iphone"
,
"size"
:
"40x40"
,
"scale"
:
"2x"
},
{
"idiom"
:
"iphone"
,
"size"
:
"40x40"
,
"scale"
:
"3x"
},
{
"idiom"
:
"iphone"
,
"size"
:
"60x60"
,
"scale"
:
"2x"
},
{
"idiom"
:
"iphone"
,
"size"
:
"60x60"
,
"scale"
:
"3x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"29x29"
,
"scale"
:
"1x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"29x29"
,
"scale"
:
"2x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"40x40"
,
"scale"
:
"1x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"40x40"
,
"scale"
:
"2x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"76x76"
,
"scale"
:
"1x"
},
{
"idiom"
:
"ipad"
,
"size"
:
"76x76"
,
"scale"
:
"2x"
}
],
"info"
:
{
"version"
:
1
,
"author"
:
"xcode"
}
}
\ No newline at end of file
Examples/Programmatic/TextField/TextField/Base.lproj/LaunchScreen.storyboard
0 → 100644
View file @
eb94bb7e
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"11134"
systemVersion=
"15F34"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
launchScreen=
"YES"
useTraitCollections=
"YES"
colorMatched=
"YES"
initialViewController=
"01J-lp-oVM"
>
<dependencies>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"11106"
/>
<capability
name=
"documents saved in the Xcode 8 format"
minToolsVersion=
"8.0"
/>
</dependencies>
<scenes>
<!--View Controller-->
<scene
sceneID=
"EHf-IW-A2E"
>
<objects>
<viewController
id=
"01J-lp-oVM"
sceneMemberID=
"viewController"
>
<layoutGuides>
<viewControllerLayoutGuide
type=
"top"
id=
"Llm-lL-Icb"
/>
<viewControllerLayoutGuide
type=
"bottom"
id=
"xb3-aO-Qok"
/>
</layoutGuides>
<view
key=
"view"
contentMode=
"scaleToFill"
id=
"Ze5-6b-2t3"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"375"
height=
"667"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<color
key=
"backgroundColor"
red=
"1"
green=
"1"
blue=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</view>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"iYj-Kq-Ea1"
userLabel=
"First Responder"
sceneMemberID=
"firstResponder"
/>
</objects>
<point
key=
"canvasLocation"
x=
"53"
y=
"375"
/>
</scene>
</scenes>
</document>
Examples/Programmatic/TextField/TextField/Info.plist
0 → 100644
View file @
eb94bb7e
<
?xml
v
e
rsion="
1
.
0
"
e
n
c
o
d
ing="UT
F
-
8
"?
>
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
en
<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
<
string
>
$
(
EXECUTABLE_NAME
)<
/string
>
<
k
e
y
>
CFBundleIdentifier
<
/k
e
y
>
<
string
>
$
(
PRODUCT_BUNDLE_IDENTIFIER
)<
/string
>
<
k
e
y
>
CFBundleInfoDictionaryVersion
<
/k
e
y
>
<
string
>
6.0
<
/string
>
<
k
e
y
>
CFBundleName
<
/k
e
y
>
<
string
>
$
(
PRODUCT_NAME
)<
/string
>
<
k
e
y
>
CFBundlePackageType
<
/k
e
y
>
<
string
>
APPL
<
/string
>
<
k
e
y
>
CFBundleShortVersionString
<
/k
e
y
>
<
string
>
1.0
<
/string
>
<
k
e
y
>
CFBundleVersion
<
/k
e
y
>
<
string
>
1
<
/string
>
<
k
e
y
>
LSRequiresIPhoneOS
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UILaunchStoryboardName
<
/k
e
y
>
<
string
>
LaunchScreen
<
/string
>
<
k
e
y
>
UIRequiredDeviceCapabilities
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
armv7
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
/
d
i
c
t
>
<
/plist
>
Examples/Programmatic/TextField/TextField/ViewController.swift
0 → 100644
View file @
eb94bb7e
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
import
Material
class
ViewController
:
UIViewController
{
private
var
nameField
:
TextField
!
private
var
emailField
:
ErrorTextField
!
private
var
passwordField
:
TextField
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
view
.
backgroundColor
=
Color
.
white
prepareNameField
()
prepareEmailField
()
preparePasswordField
()
prepareResignResponderButton
()
}
/// Programmatic update for the textField as it rotates.
override
func
willRotate
(
to
toInterfaceOrientation
:
UIInterfaceOrientation
,
duration
:
TimeInterval
)
{
emailField
.
width
=
view
.
bounds
.
height
-
80
}
/// Prepares the resign responder button.
private
func
prepareResignResponderButton
()
{
let
btn
=
RaisedButton
(
title
:
"Resign"
,
titleColor
:
Color
.
blue
.
base
)
btn
.
addTarget
(
self
,
action
:
#selector(
handleResignResponderButton
)
,
for
:
.
touchUpInside
)
view
.
layout
(
btn
)
.
width
(
100
)
.
height
(
50
)
.
bottom
(
24
)
.
right
(
24
)
}
/// Handle the resign responder button.
internal
func
handleResignResponderButton
()
{
nameField
?
.
resignFirstResponder
()
emailField
?
.
resignFirstResponder
()
passwordField
?
.
resignFirstResponder
()
}
/// Prepares the name TextField.
private
func
prepareNameField
()
{
nameField
=
TextField
()
nameField
.
text
=
"Daniel Dahan"
nameField
.
placeholder
=
"Name"
nameField
.
detail
=
"Your given name"
nameField
.
textAlignment
=
.
center
nameField
.
clearButtonMode
=
.
whileEditing
// Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 40 pixels.
view
.
layout
(
nameField
)
.
top
(
40
)
.
horizontally
(
left
:
40
,
right
:
40
)
}
/// Prepares the email TextField.
private
func
prepareEmailField
()
{
emailField
=
ErrorTextField
(
frame
:
CGRect
(
x
:
40
,
y
:
120
,
width
:
view
.
width
-
80
,
height
:
32
))
emailField
.
placeholder
=
"Email"
emailField
.
detail
=
"Error, incorrect email"
emailField
.
isClearIconButtonEnabled
=
true
emailField
.
delegate
=
self
emailField
.
placeholderColor
=
Color
.
amber
.
darken4
emailField
.
placeholderActiveColor
=
Color
.
pink
.
base
emailField
.
dividerColor
=
Color
.
cyan
.
base
view
.
addSubview
(
emailField
)
}
/// Prepares the password TextField.
private
func
preparePasswordField
()
{
passwordField
=
TextField
()
passwordField
.
placeholder
=
"Password"
passwordField
.
detail
=
"At least 8 characters"
passwordField
.
clearButtonMode
=
.
whileEditing
passwordField
.
isVisibilityIconButtonEnabled
=
true
// Setting the visibilityFlatButton color.
passwordField
.
visibilityIconButton
?
.
tintColor
=
Color
.
green
.
base
.
withAlphaComponent
(
passwordField
.
isSecureTextEntry
?
0.38
:
0.54
)
// Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 200 pixels.
view
.
layout
(
passwordField
)
.
top
(
200
)
.
horizontally
(
left
:
40
,
right
:
40
)
}
}
extension
UIViewController
:
TextFieldDelegate
{
/// Executed when the 'return' key is pressed when using the emailField.
public
func
textFieldShouldReturn
(
_
textField
:
UITextField
)
->
Bool
{
(
textField
as?
ErrorTextField
)?
.
isErrorRevealed
=
true
return
true
}
public
func
textFieldShouldBeginEditing
(
_
textField
:
UITextField
)
->
Bool
{
return
true
}
public
func
textFieldDidBeginEditing
(
_
textField
:
UITextField
)
{
}
public
func
textFieldShouldEndEditing
(
_
textField
:
UITextField
)
->
Bool
{
return
true
}
public
func
textFieldDidEndEditing
(
_
textField
:
UITextField
)
{
(
textField
as?
ErrorTextField
)?
.
isErrorRevealed
=
false
}
public
func
textFieldShouldClear
(
_
textField
:
UITextField
)
->
Bool
{
(
textField
as?
ErrorTextField
)?
.
isErrorRevealed
=
false
return
true
}
public
func
textField
(
_
textField
:
UITextField
,
shouldChangeCharactersIn
range
:
NSRange
,
replacementString
string
:
String
)
->
Bool
{
(
textField
as?
ErrorTextField
)?
.
isErrorRevealed
=
false
return
true
}
}
Material.xcworkspace/contents.xcworkspacedata
View file @
eb94bb7e
...
...
@@ -68,6 +68,9 @@
location =
"group:Examples/Programmatic/TabBar/TabBar.xcodeproj"
>
</FileRef>
<FileRef
location =
"group:Examples/Programmatic/TextField/TextField.xcodeproj"
>
</FileRef>
<FileRef
location =
"group:Examples/Programmatic/ToolbarController/ToolbarController.xcodeproj"
>
</FileRef>
<FileRef
...
...
Sources/iOS/Bar.swift
View file @
eb94bb7e
...
...
@@ -37,41 +37,6 @@ public enum ContentViewAlignment: Int {
}
open
class
Bar
:
View
{
/// Divider layer.
internal
private(set)
var
divider
:
Divider
!
/// Divider color.
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
get
{
return
divider
.
color
}
set
(
value
)
{
divider
.
color
=
value
}
}
/// Divider animation.
open
var
dividerAlignment
:
DividerAlignment
{
get
{
return
divider
.
alignment
}
set
(
value
)
{
divider
.
alignment
=
value
}
}
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
{
get
{
return
divider
.
height
}
set
(
value
)
{
divider
.
height
=
value
}
}
/// Should center the contentView.
open
var
contentViewAlignment
=
ContentViewAlignment
.
any
{
didSet
{
...
...
@@ -265,16 +230,10 @@ open class Bar: View {
open
override
func
prepare
()
{
super
.
prepare
()
prepareContentView
()
prepareDivider
()
}
/// Prepares the contentView.
private
func
prepareContentView
()
{
contentView
.
backgroundColor
=
nil
}
/// Prepares the divider.
private
func
prepareDivider
()
{
divider
=
Divider
(
view
:
self
)
}
}
Sources/iOS/BottomTabBar.swift
View file @
eb94bb7e
...
...
@@ -131,53 +131,3 @@ open class BottomTabBar: UITabBar {
backgroundImage
=
image
}
}
/// A memory reference to the TabBarItem instance.
private
var
TabBarKey
:
UInt8
=
0
extension
UITabBar
{
/// TabBarItem reference.
internal
private(set)
var
divider
:
Divider
{
get
{
return
AssociatedObject
(
base
:
self
,
key
:
&
TabBarKey
)
{
return
Divider
(
view
:
self
)
}
}
set
(
value
)
{
AssociateObject
(
base
:
self
,
key
:
&
TabBarKey
,
value
:
value
)
}
}
/// Divider color.
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
get
{
return
divider
.
color
}
set
(
value
)
{
divider
.
color
=
value
}
}
/// Divider animation.
open
var
dividerAlignment
:
DividerAlignment
{
get
{
return
divider
.
alignment
}
set
(
value
)
{
divider
.
alignment
=
value
}
}
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
{
get
{
return
divider
.
height
}
set
(
value
)
{
divider
.
height
=
value
}
}
}
Sources/iOS/CollectionViewCell.swift
View file @
eb94bb7e
...
...
@@ -32,41 +32,6 @@ import UIKit
@objc(CollectionViewCell)
open
class
CollectionViewCell
:
UICollectionViewCell
{
/// Divider layer.
internal
private(set)
var
divider
:
Divider
!
/// Divider color.
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
get
{
return
divider
.
color
}
set
(
value
)
{
divider
.
color
=
value
}
}
/// Divider animation.
open
var
dividerAlignment
:
DividerAlignment
{
get
{
return
divider
.
alignment
}
set
(
value
)
{
divider
.
alignment
=
value
}
}
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
{
get
{
return
divider
.
height
}
set
(
value
)
{
divider
.
height
=
value
}
}
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
...
...
@@ -331,7 +296,6 @@ open class CollectionViewCell: UICollectionViewCell {
open
func
prepare
()
{
contentScaleFactor
=
Device
.
scale
prepareVisualLayer
()
prepareDivider
()
}
/// Prepares the visualLayer property.
...
...
@@ -346,9 +310,4 @@ open class CollectionViewCell: UICollectionViewCell {
visualLayer
.
frame
=
bounds
visualLayer
.
cornerRadius
=
cornerRadius
}
/// Prepares the divider.
private
func
prepareDivider
()
{
divider
=
Divider
(
view
:
self
)
}
}
Sources/iOS/Divider.swift
View file @
eb94bb7e
...
...
@@ -103,3 +103,53 @@ open class Divider {
}
}
}
/// A memory reference to the Divider instance.
private
var
DividerKey
:
UInt8
=
0
extension
UIView
{
/// TabBarItem reference.
public
private(set)
var
divider
:
Divider
{
get
{
return
AssociatedObject
(
base
:
self
,
key
:
&
DividerKey
)
{
return
Divider
(
view
:
self
)
}
}
set
(
value
)
{
AssociateObject
(
base
:
self
,
key
:
&
DividerKey
,
value
:
value
)
}
}
/// Divider color.
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
get
{
return
divider
.
color
}
set
(
value
)
{
divider
.
color
=
value
}
}
/// Divider animation.
open
var
dividerAlignment
:
DividerAlignment
{
get
{
return
divider
.
alignment
}
set
(
value
)
{
divider
.
alignment
=
value
}
}
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
{
get
{
return
divider
.
height
}
set
(
value
)
{
divider
.
height
=
value
}
}
}
Sources/iOS/ErrorTextField.swift
View file @
eb94bb7e
...
...
@@ -30,11 +30,12 @@
import
UIKit
public
class
ErrorTextField
:
TextField
{
open
class
ErrorTextField
:
TextField
{
/// Controls the visibility of detailLabel
@IBInspectable
public
var
revealError
:
Bool
=
false
{
@IBInspectable
open
var
isErrorRevealed
=
false
{
didSet
{
detailLabel
.
isHidden
=
!
revealError
detailLabel
.
isHidden
=
!
isErrorRevealed
}
}
...
...
@@ -45,9 +46,8 @@ public class ErrorTextField: TextField {
The super.prepare method should always be called immediately
when subclassing.
*/
o
verride
public
func
prepare
()
{
o
pen
override
func
prepare
()
{
super
.
prepare
()
revealError
=
false
detailColor
=
Color
.
red
.
base
}
}
Sources/iOS/NavigationBar.swift
View file @
eb94bb7e
...
...
@@ -39,41 +39,6 @@ public enum NavigationBarStyle: Int {
}
open
class
NavigationBar
:
UINavigationBar
{
/// Divider layer.
internal
private(set)
var
divider
:
Divider
!
/// Divider color.
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
get
{
return
divider
.
color
}
set
(
value
)
{
divider
.
color
=
value
}
}
/// Divider animation.
open
var
dividerAlignment
:
DividerAlignment
{
get
{
return
divider
.
alignment
}
set
(
value
)
{
divider
.
alignment
=
value
}
}
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
{
get
{
return
divider
.
height
}
set
(
value
)
{
divider
.
height
=
value
}
}
open
override
var
intrinsicContentSize
:
CGSize
{
switch
navigationBarStyle
{
case
.
small
:
...
...
@@ -324,8 +289,6 @@ open class NavigationBar: UINavigationBar {
when subclassing.
*/
public
func
prepare
()
{
prepareDivider
()
barStyle
=
.
black
isTranslucent
=
false
depthPreset
=
.
depth1
...
...
@@ -358,9 +321,4 @@ open class NavigationBar: UINavigationBar {
}
item
.
titleView
=
UIView
(
frame
:
.
zero
)
}
/// Prepares the divider.
private
func
prepareDivider
()
{
divider
=
Divider
(
view
:
self
)
}
}
Sources/iOS/TextField.swift
View file @
eb94bb7e
...
...
@@ -49,36 +49,37 @@ open class TextField: UITextField {
}
}
/// Reference to the divider.
open
private(set)
var
divider
:
CAShapeLayer
!
/// Divider height.
@IBInspectable
open
var
dividerHeight
:
CGFloat
=
1
/// Divider active state height.
/// Divider active state height.
@IBInspectable
open
var
dividerActiveHeight
:
CGFloat
=
2
/// Sets the divider.
@IBInspectable
open
var
dividerColor
:
UIColor
=
Color
.
darkText
.
dividers
{
didSet
{
if
!
isEditing
{
divider
.
backgroundColor
=
dividerColor
.
cgColor
}
}
}
open
override
var
dividerColor
:
UIColor
?
{
get
{
return
super
.
dividerColor
}
set
(
value
)
{
guard
!
isEditing
else
{
return
}
super
.
dividerColor
=
value
}
}
/// Sets the divider.
@IBInspectable
open
var
dividerActiveColor
:
UIColor
?
{
didSet
{
if
let
v
:
UIColor
=
dividerActiveColor
{
if
isEditing
{
divider
.
backgroundColor
=
v
.
cgColor
}
}
guard
isEditing
else
{
return
}
guard
let
v
=
dividerActiveColor
else
{
return
}
dividerColor
=
v
}
}
...
...
@@ -198,7 +199,7 @@ open class TextField: UITextField {
/// Enables the clearIconButton.
@IBInspectable
open
var
isClearIconButtonEnable
:
Bool
{
open
var
isClearIconButtonEnable
d
:
Bool
{
get
{
return
nil
!=
clearIconButton
}
...
...
@@ -211,7 +212,7 @@ open class TextField: UITextField {
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
=
clearIconButton
clearIconButtonAutoHandle
=
clearIconButtonAutoHandle
?
true
:
false
isClearIconButtonAutoHandled
=
isClearIconButtonAutoHandled
?
true
:
false
}
}
else
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
...
...
@@ -222,10 +223,10 @@ open class TextField: UITextField {
/// Enables the automatic handling of the clearIconButton.
@IBInspectable
open
var
clearIconButtonAutoHandle
=
true
{
open
var
isClearIconButtonAutoHandled
=
true
{
didSet
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
if
clearIconButtonAutoHandle
{
if
isClearIconButtonAutoHandled
{
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
}
}
...
...
@@ -233,7 +234,7 @@ open class TextField: UITextField {
/// Enables the visibilityIconButton.
@IBInspectable
open
var
isVisibilityIconButtonEnable
:
Bool
{
open
var
isVisibilityIconButtonEnable
d
:
Bool
{
get
{
return
nil
!=
visibilityIconButton
}
...
...
@@ -247,7 +248,7 @@ open class TextField: UITextField {
clearButtonMode
=
.
never
rightViewMode
=
.
whileEditing
rightView
=
visibilityIconButton
visibilityIconButtonAutoHandle
=
visibilityIconButtonAutoHandle
?
true
:
false
isVisibilityIconButtonAutoHandled
=
isVisibilityIconButtonAutoHandled
?
true
:
false
}
}
else
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
...
...
@@ -258,10 +259,10 @@ open class TextField: UITextField {
/// Enables the automatic handling of the visibilityIconButton.
@IBInspectable
open
var
visibilityIconButtonAutoHandle
:
Bool
=
true
{
open
var
isVisibilityIconButtonAutoHandled
:
Bool
=
true
{
didSet
{
visibilityIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
if
visibilityIconButtonAutoHandle
{
if
isVisibilityIconButtonAutoHandled
{
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
}
}
...
...
@@ -312,13 +313,13 @@ open class TextField: UITextField {
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
layoutToSize
()
layoutDivider
()
}
open
override
func
layoutSublayers
(
of
layer
:
CALayer
)
{
super
.
layoutSublayers
(
of
:
layer
)
if
self
.
layer
==
layer
{
layoutShape
()
layoutDivider
()
}
}
...
...
@@ -388,7 +389,7 @@ open class TextField: UITextField {
/// Layout the divider.
open
func
layoutDivider
()
{
divider
.
frame
=
CGRect
(
x
:
0
,
y
:
height
,
width
:
width
,
height
:
isEditing
?
dividerActiveHeight
:
dividerHeight
)
divider
.
reload
(
)
}
/// Layout the placeholderLabel.
...
...
@@ -423,8 +424,11 @@ open class TextField: UITextField {
/// Layout the detailLabel.
open
func
layoutDetailLabel
()
{
let
h
:
CGFloat
=
nil
==
detail
?
12
:
detailLabel
.
font
.
stringSize
(
string
:
detail
!
,
constrainedToWidth
:
Double
(
width
))
.
height
detailLabel
.
frame
=
CGRect
(
x
:
0
,
y
:
divider
.
y
+
detailVerticalOffset
,
width
:
width
,
height
:
h
)
guard
let
v
=
divider
.
line
else
{
return
}
let
h
:
CGFloat
=
nil
==
detail
?
12
:
detailLabel
.
font
.
stringSize
(
string
:
detail
!
,
constrainedToWidth
:
Double
(
width
))
.
height
detailLabel
.
frame
=
CGRect
(
x
:
0
,
y
:
v
.
y
+
detailVerticalOffset
,
width
:
width
,
height
:
h
)
}
/// Layout the clearIconButton.
...
...
@@ -448,13 +452,13 @@ open class TextField: UITextField {
/// The animation for the divider when editing begins.
open
func
dividerEditingDidBeginAnimation
()
{
dividerHeight
=
dividerActiveHeight
divider
.
backgroundColor
=
nil
==
dividerActiveColor
?
placeholderActiveColor
.
cgColor
:
dividerActiveColor
!.
cg
Color
divider
Color
=
dividerActiveColor
??
placeholderActive
Color
}
/// The animation for the divider when editing ends.
open
func
dividerEditingDidEndAnimation
()
{
divider
.
frame
.
size
.
height
=
dividerHeight
divider
.
backgroundColor
=
dividerColor
.
cg
Color
//
divider.frame.size.height = dividerHeight
// divider.color = divider
Color
}
/// The animation for the placeholder when editing begins.
...
...
@@ -503,9 +507,7 @@ open class TextField: UITextField {
/// Prepares the divider.
private
func
prepareDivider
()
{
divider
=
CAShapeLayer
()
dividerColor
=
Color
.
darkText
.
dividers
layer
.
addSublayer
(
divider
)
dividerColor
=
Color
.
darkText
.
dividers
}
/// Prepares the placeholderLabel.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment