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
ef355c28
Commit
ef355c28
authored
Sep 26, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing conflicted files
parent
6b0bd134
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
172 additions
and
142 deletions
+172
-142
Sources/iOS/ChipBarController.swift
+12
-12
Sources/iOS/CollectionView.swift
+6
-2
Sources/iOS/Layer.swift
+18
-16
Sources/iOS/TextField.swift
+112
-112
Sources/iOS/Toolbar.swift
+24
-0
No files found.
Sources/iOS/ChipBarController.swift
View file @
ef355c28
...
@@ -45,7 +45,7 @@ extension UIViewController {
...
@@ -45,7 +45,7 @@ extension UIViewController {
This is the recommended method of accessing the ChipBarController
This is the recommended method of accessing the ChipBarController
through child UIViewControllers.
through child UIViewControllers.
*/
*/
public
var
chip
s
Controller
:
ChipBarController
?
{
public
var
chip
Bar
Controller
:
ChipBarController
?
{
return
traverseViewControllerHierarchyForClassType
()
return
traverseViewControllerHierarchyForClassType
()
}
}
}
}
...
@@ -61,25 +61,25 @@ open class ChipBarController: TransitionController {
...
@@ -61,25 +61,25 @@ open class ChipBarController: TransitionController {
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// The ChipBar used to switch between view controllers.
/// The ChipBar used to switch between view controllers.
@IBInspectable
@IBInspectable
open
let
chipBar
=
ChipBar
()
open
let
chipBar
=
ChipBar
()
/// The chipBar alignment.
/// The chipBar alignment.
open
var
chipBarAlignment
=
ChipBarAlignment
.
bottom
{
open
var
chipBarAlignment
=
ChipBarAlignment
.
bottom
{
didSet
{
didSet
{
layoutSubviews
()
layoutSubviews
()
}
}
}
}
open
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
layoutChipBar
()
layoutChipBar
()
layoutContainer
()
layoutContainer
()
layoutRootViewController
()
layoutRootViewController
()
}
}
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
prepareChipBar
()
prepareChipBar
()
...
@@ -98,12 +98,12 @@ fileprivate extension ChipBarController {
...
@@ -98,12 +98,12 @@ fileprivate extension ChipBarController {
/// Layout the container.
/// Layout the container.
func
layoutContainer
()
{
func
layoutContainer
()
{
chipBar
.
frame
.
size
.
width
=
view
.
bounds
.
width
chipBar
.
frame
.
size
.
width
=
view
.
bounds
.
width
switch
displayStyle
{
switch
displayStyle
{
case
.
partial
:
case
.
partial
:
let
p
=
chipBar
.
bounds
.
height
let
p
=
chipBar
.
bounds
.
height
let
y
=
view
.
bounds
.
height
-
p
let
y
=
view
.
bounds
.
height
-
p
switch
chipBarAlignment
{
switch
chipBarAlignment
{
case
.
top
:
case
.
top
:
container
.
frame
.
origin
.
y
=
p
container
.
frame
.
origin
.
y
=
p
...
@@ -115,18 +115,18 @@ fileprivate extension ChipBarController {
...
@@ -115,18 +115,18 @@ fileprivate extension ChipBarController {
container
.
frame
.
origin
.
y
=
0
container
.
frame
.
origin
.
y
=
0
container
.
frame
.
size
.
height
=
view
.
bounds
.
height
container
.
frame
.
size
.
height
=
view
.
bounds
.
height
}
}
container
.
frame
.
size
.
width
=
view
.
bounds
.
width
container
.
frame
.
size
.
width
=
view
.
bounds
.
width
case
.
full
:
case
.
full
:
container
.
frame
=
view
.
bounds
container
.
frame
=
view
.
bounds
}
}
}
}
/// Layout the chipBar.
/// Layout the chipBar.
func
layoutChipBar
()
{
func
layoutChipBar
()
{
chipBar
.
frame
.
size
.
width
=
view
.
bounds
.
width
chipBar
.
frame
.
size
.
width
=
view
.
bounds
.
width
switch
chipBarAlignment
{
switch
chipBarAlignment
{
case
.
top
:
case
.
top
:
chipBar
.
isHidden
=
false
chipBar
.
isHidden
=
false
...
@@ -138,7 +138,7 @@ fileprivate extension ChipBarController {
...
@@ -138,7 +138,7 @@ fileprivate extension ChipBarController {
chipBar
.
isHidden
=
true
chipBar
.
isHidden
=
true
}
}
}
}
/// Layout the rootViewController.
/// Layout the rootViewController.
func
layoutRootViewController
()
{
func
layoutRootViewController
()
{
rootViewController
.
view
.
frame
=
container
.
bounds
rootViewController
.
view
.
frame
=
container
.
bounds
...
...
Sources/iOS/CollectionView.swift
View file @
ef355c28
...
@@ -114,13 +114,17 @@ open class CollectionView: UICollectionView {
...
@@ -114,13 +114,17 @@ open class CollectionView: UICollectionView {
- Parameter frame: A CGRect defining the view's frame.
- Parameter frame: A CGRect defining the view's frame.
*/
*/
public
init
(
frame
:
CGRect
)
{
public
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
,
collectionViewLayout
:
CollectionViewLayout
())
let
layout
=
UICollectionViewFlowLayout
()
layout
.
itemSize
=
CGSize
(
width
:
100
,
height
:
100
)
super
.
init
(
frame
:
frame
,
collectionViewLayout
:
layout
)
prepare
()
prepare
()
}
}
/// A convenience initializer that initializes the object.
/// A convenience initializer that initializes the object.
public
init
()
{
public
init
()
{
super
.
init
(
frame
:
.
zero
,
collectionViewLayout
:
CollectionViewLayout
())
let
layout
=
UICollectionViewFlowLayout
()
layout
.
itemSize
=
CGSize
(
width
:
100
,
height
:
100
)
super
.
init
(
frame
:
.
zero
,
collectionViewLayout
:
layout
)
prepare
()
prepare
()
}
}
...
...
Sources/iOS/Layer.swift
View file @
ef355c28
...
@@ -39,7 +39,7 @@ open class Layer: CAShapeLayer {
...
@@ -39,7 +39,7 @@ open class Layer: CAShapeLayer {
the image to a desired shape within the visualLayer.
the image to a desired shape within the visualLayer.
*/
*/
open
let
visualLayer
=
CAShapeLayer
()
open
let
visualLayer
=
CAShapeLayer
()
/**
/**
A property that manages an image for the visualLayer's contents
A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
property. Images should not be set to the backing layer's contents
...
@@ -51,7 +51,7 @@ open class Layer: CAShapeLayer {
...
@@ -51,7 +51,7 @@ open class Layer: CAShapeLayer {
visualLayer
.
contents
=
image
?
.
cgImage
visualLayer
.
contents
=
image
?
.
cgImage
}
}
}
}
/**
/**
Allows a relative subrectangle within the range of 0 to 1 to be
Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows
specified for the visualLayer's contents property. This allows
...
@@ -63,7 +63,7 @@ open class Layer: CAShapeLayer {
...
@@ -63,7 +63,7 @@ open class Layer: CAShapeLayer {
visualLayer
.
contentsRect
=
contentsRect
visualLayer
.
contentsRect
=
contentsRect
}
}
}
}
/**
/**
A CGRect that defines a stretchable region inside the visualLayer
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
with a fixed border around the edge.
...
@@ -73,7 +73,7 @@ open class Layer: CAShapeLayer {
...
@@ -73,7 +73,7 @@ open class Layer: CAShapeLayer {
visualLayer
.
contentsCenter
=
contentsCenter
visualLayer
.
contentsCenter
=
contentsCenter
}
}
}
}
/**
/**
A floating point value that defines a ratio between the pixel
A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size
dimensions of the visualLayer's contents property and the size
...
@@ -85,14 +85,14 @@ open class Layer: CAShapeLayer {
...
@@ -85,14 +85,14 @@ open class Layer: CAShapeLayer {
visualLayer
.
contentsScale
=
contentsScale
visualLayer
.
contentsScale
=
contentsScale
}
}
}
}
/// A Preset for the contentsGravity property.
/// A Preset for the contentsGravity property.
open
var
contentsGravityPreset
:
Gravity
{
open
var
contentsGravityPreset
:
Gravity
{
didSet
{
didSet
{
contentsGravity
=
GravityToValue
(
gravity
:
contentsGravityPreset
)
contentsGravity
=
GravityToValue
(
gravity
:
contentsGravityPreset
)
}
}
}
}
/// Determines how content should be aligned within the visualLayer's bounds.
/// Determines how content should be aligned within the visualLayer's bounds.
@IBInspectable
@IBInspectable
open
override
var
contentsGravity
:
String
{
open
override
var
contentsGravity
:
String
{
...
@@ -103,7 +103,7 @@ open class Layer: CAShapeLayer {
...
@@ -103,7 +103,7 @@ open class Layer: CAShapeLayer {
visualLayer
.
contentsGravity
=
value
visualLayer
.
contentsGravity
=
value
}
}
}
}
/**
/**
A property that sets the cornerRadius of the backing layer. If the shape
A property that sets the cornerRadius of the backing layer. If the shape
property has a value of .circle when the cornerRadius is set, it will
property has a value of .circle when the cornerRadius is set, it will
...
@@ -116,7 +116,7 @@ open class Layer: CAShapeLayer {
...
@@ -116,7 +116,7 @@ open class Layer: CAShapeLayer {
shapePreset
=
.
none
shapePreset
=
.
none
}
}
}
}
/**
/**
An initializer that initializes the object with a NSCoder object.
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
...
@@ -126,7 +126,7 @@ open class Layer: CAShapeLayer {
...
@@ -126,7 +126,7 @@ open class Layer: CAShapeLayer {
super
.
init
(
coder
:
aDecoder
)
super
.
init
(
coder
:
aDecoder
)
prepareVisualLayer
()
prepareVisualLayer
()
}
}
/**
/**
An initializer the same as init(). The layer parameter is ignored
An initializer the same as init(). The layer parameter is ignored
to avoid crashes on certain architectures.
to avoid crashes on certain architectures.
...
@@ -137,14 +137,14 @@ open class Layer: CAShapeLayer {
...
@@ -137,14 +137,14 @@ open class Layer: CAShapeLayer {
super
.
init
(
layer
:
layer
)
super
.
init
(
layer
:
layer
)
prepareVisualLayer
()
prepareVisualLayer
()
}
}
/// A convenience initializer.
/// A convenience initializer.
public
override
init
()
{
public
override
init
()
{
contentsGravityPreset
=
.
resizeAspectFill
contentsGravityPreset
=
.
resizeAspectFill
super
.
init
()
super
.
init
()
prepareVisualLayer
()
prepareVisualLayer
()
}
}
/**
/**
An initializer that initializes the object with a CGRect object.
An initializer that initializes the object with a CGRect object.
- Parameter frame: A CGRect instance.
- Parameter frame: A CGRect instance.
...
@@ -153,23 +153,25 @@ open class Layer: CAShapeLayer {
...
@@ -153,23 +153,25 @@ open class Layer: CAShapeLayer {
self
.
init
()
self
.
init
()
self
.
frame
=
frame
self
.
frame
=
frame
}
}
open
override
func
layoutSublayers
()
{
open
override
func
layoutSublayers
()
{
super
.
layoutSublayers
()
super
.
layoutSublayers
()
layoutShape
()
layoutShape
()
layoutVisualLayer
()
layoutVisualLayer
()
layoutShadowPath
()
layoutShadowPath
()
}
}
}
fileprivate
extension
Layer
{
/// Prepares the visualLayer property.
/// Prepares the visualLayer property.
open
func
prepareVisualLayer
()
{
func
prepareVisualLayer
()
{
visualLayer
.
zPosition
=
0
visualLayer
.
zPosition
=
0
visualLayer
.
masksToBounds
=
true
visualLayer
.
masksToBounds
=
true
addSublayer
(
visualLayer
)
addSublayer
(
visualLayer
)
}
}
/// Manages the layout for the visualLayer property.
/// Manages the layout for the visualLayer property.
internal
func
layoutVisualLayer
()
{
func
layoutVisualLayer
()
{
visualLayer
.
frame
=
bounds
visualLayer
.
frame
=
bounds
visualLayer
.
cornerRadius
=
cornerRadius
visualLayer
.
cornerRadius
=
cornerRadius
}
}
...
...
Sources/iOS/TextField.swift
View file @
ef355c28
...
@@ -53,7 +53,7 @@ public protocol TextFieldDelegate: UITextFieldDelegate {
...
@@ -53,7 +53,7 @@ public protocol TextFieldDelegate: UITextFieldDelegate {
*/
*/
@objc
@objc
optional
func
textField
(
textField
:
TextField
,
willClear
text
:
String
?)
optional
func
textField
(
textField
:
TextField
,
willClear
text
:
String
?)
/**
/**
A delegation method that is executed when the textField is cleared.
A delegation method that is executed when the textField is cleared.
- Parameter textField: A TextField.
- Parameter textField: A TextField.
...
@@ -68,11 +68,11 @@ open class TextField: UITextField {
...
@@ -68,11 +68,11 @@ open class TextField: UITextField {
open
override
var
intrinsicContentSize
:
CGSize
{
open
override
var
intrinsicContentSize
:
CGSize
{
return
CGSize
(
width
:
bounds
.
width
,
height
:
32
)
return
CGSize
(
width
:
bounds
.
width
,
height
:
32
)
}
}
/// A Boolean that indicates if the placeholder label is animated.
/// A Boolean that indicates if the placeholder label is animated.
@IBInspectable
@IBInspectable
open
var
isPlaceholderAnimated
=
true
open
var
isPlaceholderAnimated
=
true
/// Set the placeholder animation value.
/// Set the placeholder animation value.
open
var
placeholderAnimation
=
TextFieldPlaceholderAnimation
.
default
{
open
var
placeholderAnimation
=
TextFieldPlaceholderAnimation
.
default
{
didSet
{
didSet
{
...
@@ -80,41 +80,41 @@ open class TextField: UITextField {
...
@@ -80,41 +80,41 @@ open class TextField: UITextField {
placeholderLabel
.
isHidden
=
!
isEmpty
&&
.
hidden
==
placeholderAnimation
placeholderLabel
.
isHidden
=
!
isEmpty
&&
.
hidden
==
placeholderAnimation
return
return
}
}
placeholderLabel
.
isHidden
=
.
hidden
==
placeholderAnimation
placeholderLabel
.
isHidden
=
.
hidden
==
placeholderAnimation
}
}
}
}
/// A boolean indicating whether the text is empty.
/// A boolean indicating whether the text is empty.
open
var
isEmpty
:
Bool
{
open
var
isEmpty
:
Bool
{
return
0
==
text
?
.
utf16
.
count
return
0
==
text
?
.
utf16
.
count
}
}
open
override
var
text
:
String
?
{
open
override
var
text
:
String
?
{
didSet
{
didSet
{
placeholderAnimation
=
{
placeholderAnimation
}()
placeholderAnimation
=
{
placeholderAnimation
}()
}
}
}
}
open
override
var
leftView
:
UIView
?
{
open
override
var
leftView
:
UIView
?
{
didSet
{
didSet
{
prepareLeftView
()
prepareLeftView
()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// The leftView width value.
/// The leftView width value.
open
var
leftViewWidth
:
CGFloat
{
open
var
leftViewWidth
:
CGFloat
{
guard
nil
!=
leftView
else
{
guard
nil
!=
leftView
else
{
return
0
return
0
}
}
return
leftViewOffset
+
bounds
.
height
return
leftViewOffset
+
bounds
.
height
}
}
/// The leftView offset value.
/// The leftView offset value.
open
var
leftViewOffset
:
CGFloat
=
16
open
var
leftViewOffset
:
CGFloat
=
16
/// Placeholder normal text
/// Placeholder normal text
@IBInspectable
@IBInspectable
open
var
leftViewNormalColor
=
Color
.
darkText
.
others
{
open
var
leftViewNormalColor
=
Color
.
darkText
.
others
{
...
@@ -122,7 +122,7 @@ open class TextField: UITextField {
...
@@ -122,7 +122,7 @@ open class TextField: UITextField {
updateLeftViewColor
()
updateLeftViewColor
()
}
}
}
}
/// Placeholder active text
/// Placeholder active text
@IBInspectable
@IBInspectable
open
var
leftViewActiveColor
=
Color
.
blue
.
base
{
open
var
leftViewActiveColor
=
Color
.
blue
.
base
{
...
@@ -130,7 +130,7 @@ open class TextField: UITextField {
...
@@ -130,7 +130,7 @@ open class TextField: UITextField {
updateLeftViewColor
()
updateLeftViewColor
()
}
}
}
}
/// Divider normal height.
/// Divider normal height.
@IBInspectable
@IBInspectable
open
var
dividerNormalHeight
:
CGFloat
=
1
{
open
var
dividerNormalHeight
:
CGFloat
=
1
{
...
@@ -138,12 +138,12 @@ open class TextField: UITextField {
...
@@ -138,12 +138,12 @@ open class TextField: UITextField {
guard
!
isEditing
else
{
guard
!
isEditing
else
{
return
return
}
}
dividerThickness
=
dividerNormalHeight
dividerThickness
=
dividerNormalHeight
}
}
}
}
/// Divider active height.
/// Divider active height.
@IBInspectable
@IBInspectable
open
var
dividerActiveHeight
:
CGFloat
=
2
{
open
var
dividerActiveHeight
:
CGFloat
=
2
{
...
@@ -151,11 +151,11 @@ open class TextField: UITextField {
...
@@ -151,11 +151,11 @@ open class TextField: UITextField {
guard
isEditing
else
{
guard
isEditing
else
{
return
return
}
}
dividerThickness
=
dividerActiveHeight
dividerThickness
=
dividerActiveHeight
}
}
}
}
/// Divider normal color.
/// Divider normal color.
@IBInspectable
@IBInspectable
open
var
dividerNormalColor
=
Color
.
grey
.
lighten2
{
open
var
dividerNormalColor
=
Color
.
grey
.
lighten2
{
...
@@ -163,11 +163,11 @@ open class TextField: UITextField {
...
@@ -163,11 +163,11 @@ open class TextField: UITextField {
guard
!
isEditing
else
{
guard
!
isEditing
else
{
return
return
}
}
dividerColor
=
dividerNormalColor
dividerColor
=
dividerNormalColor
}
}
}
}
/// Divider active color.
/// Divider active color.
@IBInspectable
@IBInspectable
open
var
dividerActiveColor
=
Color
.
blue
.
base
{
open
var
dividerActiveColor
=
Color
.
blue
.
base
{
...
@@ -175,11 +175,11 @@ open class TextField: UITextField {
...
@@ -175,11 +175,11 @@ open class TextField: UITextField {
guard
isEditing
else
{
guard
isEditing
else
{
return
return
}
}
dividerColor
=
dividerActiveColor
dividerColor
=
dividerActiveColor
}
}
}
}
/// The placeholderLabel font value.
/// The placeholderLabel font value.
@IBInspectable
@IBInspectable
open
override
var
font
:
UIFont
?
{
open
override
var
font
:
UIFont
?
{
...
@@ -187,7 +187,7 @@ open class TextField: UITextField {
...
@@ -187,7 +187,7 @@ open class TextField: UITextField {
placeholderLabel
.
font
=
font
placeholderLabel
.
font
=
font
}
}
}
}
/// The placeholderLabel text value.
/// The placeholderLabel text value.
@IBInspectable
@IBInspectable
open
override
var
placeholder
:
String
?
{
open
override
var
placeholder
:
String
?
{
...
@@ -203,11 +203,11 @@ open class TextField: UITextField {
...
@@ -203,11 +203,11 @@ open class TextField: UITextField {
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// The placeholder UILabel.
/// The placeholder UILabel.
@IBInspectable
@IBInspectable
open
let
placeholderLabel
=
UILabel
()
open
let
placeholderLabel
=
UILabel
()
/// Placeholder normal text
/// Placeholder normal text
@IBInspectable
@IBInspectable
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
open
var
placeholderNormalColor
=
Color
.
darkText
.
others
{
...
@@ -215,7 +215,7 @@ open class TextField: UITextField {
...
@@ -215,7 +215,7 @@ open class TextField: UITextField {
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
}
}
}
}
/// Placeholder active text
/// Placeholder active text
@IBInspectable
@IBInspectable
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
open
var
placeholderActiveColor
=
Color
.
blue
.
base
{
...
@@ -223,15 +223,15 @@ open class TextField: UITextField {
...
@@ -223,15 +223,15 @@ open class TextField: UITextField {
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
}
}
}
}
/// This property adds a padding to placeholder y position animation
/// This property adds a padding to placeholder y position animation
@IBInspectable
@IBInspectable
open
var
placeholderVerticalOffset
:
CGFloat
=
0
open
var
placeholderVerticalOffset
:
CGFloat
=
0
/// This property adds a padding to placeholder y position animation
/// This property adds a padding to placeholder y position animation
@IBInspectable
@IBInspectable
open
var
placeholderHorizontalOffset
:
CGFloat
=
0
open
var
placeholderHorizontalOffset
:
CGFloat
=
0
/// The scale of the active placeholder in relation to the inactive
/// The scale of the active placeholder in relation to the inactive
@IBInspectable
@IBInspectable
open
var
placeholderActiveScale
:
CGFloat
=
0.75
{
open
var
placeholderActiveScale
:
CGFloat
=
0.75
{
...
@@ -239,11 +239,11 @@ open class TextField: UITextField {
...
@@ -239,11 +239,11 @@ open class TextField: UITextField {
layoutPlaceholderLabel
()
layoutPlaceholderLabel
()
}
}
}
}
/// The detailLabel UILabel that is displayed.
/// The detailLabel UILabel that is displayed.
@IBInspectable
@IBInspectable
open
let
detailLabel
=
UILabel
()
open
let
detailLabel
=
UILabel
()
/// The detailLabel text value.
/// The detailLabel text value.
@IBInspectable
@IBInspectable
open
var
detail
:
String
?
{
open
var
detail
:
String
?
{
...
@@ -255,7 +255,7 @@ open class TextField: UITextField {
...
@@ -255,7 +255,7 @@ open class TextField: UITextField {
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Detail text
/// Detail text
@IBInspectable
@IBInspectable
open
var
detailColor
=
Color
.
darkText
.
others
{
open
var
detailColor
=
Color
.
darkText
.
others
{
...
@@ -263,7 +263,7 @@ open class TextField: UITextField {
...
@@ -263,7 +263,7 @@ open class TextField: UITextField {
updateDetailLabelColor
()
updateDetailLabelColor
()
}
}
}
}
/// Vertical distance for the detailLabel from the divider.
/// Vertical distance for the detailLabel from the divider.
@IBInspectable
@IBInspectable
open
var
detailVerticalOffset
:
CGFloat
=
8
{
open
var
detailVerticalOffset
:
CGFloat
=
8
{
...
@@ -271,7 +271,7 @@ open class TextField: UITextField {
...
@@ -271,7 +271,7 @@ open class TextField: UITextField {
layoutDetailLabel
()
layoutDetailLabel
()
}
}
}
}
/// Handles the textAlignment of the placeholderLabel.
/// Handles the textAlignment of the placeholderLabel.
open
override
var
textAlignment
:
NSTextAlignment
{
open
override
var
textAlignment
:
NSTextAlignment
{
get
{
get
{
...
@@ -283,10 +283,10 @@ open class TextField: UITextField {
...
@@ -283,10 +283,10 @@ open class TextField: UITextField {
detailLabel
.
textAlignment
=
value
detailLabel
.
textAlignment
=
value
}
}
}
}
/// A reference to the clearIconButton.
/// A reference to the clearIconButton.
open
fileprivate
(
set
)
var
clearIconButton
:
IconButton
?
open
fileprivate
(
set
)
var
clearIconButton
:
IconButton
?
/// Enables the clearIconButton.
/// Enables the clearIconButton.
@IBInspectable
@IBInspectable
open
var
isClearIconButtonEnabled
:
Bool
{
open
var
isClearIconButtonEnabled
:
Bool
{
...
@@ -299,11 +299,11 @@ open class TextField: UITextField {
...
@@ -299,11 +299,11 @@ open class TextField: UITextField {
clearIconButton
=
nil
clearIconButton
=
nil
return
return
}
}
guard
nil
==
clearIconButton
else
{
guard
nil
==
clearIconButton
else
{
return
return
}
}
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderNormalColor
)
clearIconButton
!.
contentEdgeInsetsPreset
=
.
none
clearIconButton
!.
contentEdgeInsetsPreset
=
.
none
clearIconButton
!.
pulseAnimation
=
.
none
clearIconButton
!.
pulseAnimation
=
.
none
...
@@ -311,28 +311,28 @@ open class TextField: UITextField {
...
@@ -311,28 +311,28 @@ open class TextField: UITextField {
rightViewMode
=
.
whileEditing
rightViewMode
=
.
whileEditing
rightView
=
clearIconButton
rightView
=
clearIconButton
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
isClearIconButtonAutoHandled
=
{
isClearIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Enables the automatic handling of the clearIconButton.
/// Enables the automatic handling of the clearIconButton.
@IBInspectable
@IBInspectable
open
var
isClearIconButtonAutoHandled
=
true
{
open
var
isClearIconButtonAutoHandled
=
true
{
didSet
{
didSet
{
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
?
.
removeTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
guard
isClearIconButtonAutoHandled
else
{
guard
isClearIconButtonAutoHandled
else
{
return
return
}
}
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
clearIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleClearIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
/// A reference to the visibilityIconButton.
/// A reference to the visibilityIconButton.
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
open
fileprivate
(
set
)
var
visibilityIconButton
:
IconButton
?
/// Enables the visibilityIconButton.
/// Enables the visibilityIconButton.
@IBInspectable
@IBInspectable
open
var
isVisibilityIconButtonEnabled
:
Bool
{
open
var
isVisibilityIconButtonEnabled
:
Bool
{
...
@@ -345,11 +345,11 @@ open class TextField: UITextField {
...
@@ -345,11 +345,11 @@ open class TextField: UITextField {
visibilityIconButton
=
nil
visibilityIconButton
=
nil
return
return
}
}
guard
nil
==
visibilityIconButton
else
{
guard
nil
==
visibilityIconButton
else
{
return
return
}
}
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholderNormalColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
contentEdgeInsetsPreset
=
.
none
visibilityIconButton
!.
pulseAnimation
=
.
none
visibilityIconButton
!.
pulseAnimation
=
.
none
...
@@ -358,11 +358,11 @@ open class TextField: UITextField {
...
@@ -358,11 +358,11 @@ open class TextField: UITextField {
rightViewMode
=
.
whileEditing
rightViewMode
=
.
whileEditing
rightView
=
visibilityIconButton
rightView
=
visibilityIconButton
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
isVisibilityIconButtonAutoHandled
=
{
isVisibilityIconButtonAutoHandled
}()
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Enables the automatic handling of the visibilityIconButton.
/// Enables the automatic handling of the visibilityIconButton.
@IBInspectable
@IBInspectable
open
var
isVisibilityIconButtonAutoHandled
=
true
{
open
var
isVisibilityIconButtonAutoHandled
=
true
{
...
@@ -371,18 +371,18 @@ open class TextField: UITextField {
...
@@ -371,18 +371,18 @@ open class TextField: UITextField {
guard
isVisibilityIconButtonAutoHandled
else
{
guard
isVisibilityIconButtonAutoHandled
else
{
return
return
}
}
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
visibilityIconButton
?
.
addTarget
(
self
,
action
:
#selector(
handleVisibilityIconButton
)
,
for
:
.
touchUpInside
)
}
}
}
}
@IBInspectable
@IBInspectable
open
var
isPlaceholderUppercasedWhenEditing
=
false
{
open
var
isPlaceholderUppercasedWhenEditing
=
false
{
didSet
{
didSet
{
updatePlaceholderTextToActiveState
()
updatePlaceholderTextToActiveState
()
}
}
}
}
/**
/**
An initializer that initializes the object with a NSCoder object.
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
...
@@ -391,7 +391,7 @@ open class TextField: UITextField {
...
@@ -391,7 +391,7 @@ open class TextField: UITextField {
super
.
init
(
coder
:
aDecoder
)
super
.
init
(
coder
:
aDecoder
)
prepare
()
prepare
()
}
}
/**
/**
An initializer that initializes the object with a CGRect object.
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
If AutoLayout is used, it is better to initilize the instance
...
@@ -402,12 +402,12 @@ open class TextField: UITextField {
...
@@ -402,12 +402,12 @@ open class TextField: UITextField {
super
.
init
(
frame
:
frame
)
super
.
init
(
frame
:
frame
)
prepare
()
prepare
()
}
}
/// A convenience initializer.
/// A convenience initializer.
public
convenience
init
()
{
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
self
.
init
(
frame
:
.
zero
)
}
}
open
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
layoutShape
()
layoutShape
()
...
@@ -418,26 +418,26 @@ open class TextField: UITextField {
...
@@ -418,26 +418,26 @@ open class TextField: UITextField {
layoutDivider
()
layoutDivider
()
layoutLeftView
()
layoutLeftView
()
}
}
open
override
func
becomeFirstResponder
()
->
Bool
{
open
override
func
becomeFirstResponder
()
->
Bool
{
layoutSubviews
()
layoutSubviews
()
return
super
.
becomeFirstResponder
()
return
super
.
becomeFirstResponder
()
}
}
/// EdgeInsets for text.
/// EdgeInsets for text.
open
var
textInset
:
CGFloat
=
0
open
var
textInset
:
CGFloat
=
0
open
override
func
textRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
open
override
func
textRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
var
b
=
super
.
textRect
(
forBounds
:
bounds
)
var
b
=
super
.
textRect
(
forBounds
:
bounds
)
b
.
origin
.
x
+=
textInset
b
.
origin
.
x
+=
textInset
b
.
size
.
width
-=
textInset
b
.
size
.
width
-=
textInset
return
b
return
b
}
}
open
override
func
editingRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
open
override
func
editingRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
return
textRect
(
forBounds
:
bounds
)
return
textRect
(
forBounds
:
bounds
)
}
}
/**
/**
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
it is recommended to override the prepare method
...
@@ -452,7 +452,7 @@ open class TextField: UITextField {
...
@@ -452,7 +452,7 @@ open class TextField: UITextField {
contentScaleFactor
=
Screen
.
scale
contentScaleFactor
=
Screen
.
scale
font
=
RobotoFont
.
regular
(
with
:
16
)
font
=
RobotoFont
.
regular
(
with
:
16
)
textColor
=
Color
.
darkText
.
primary
textColor
=
Color
.
darkText
.
primary
prepareDivider
()
prepareDivider
()
preparePlaceholderLabel
()
preparePlaceholderLabel
()
prepareDetailLabel
()
prepareDetailLabel
()
...
@@ -466,14 +466,14 @@ fileprivate extension TextField {
...
@@ -466,14 +466,14 @@ fileprivate extension TextField {
func
prepareDivider
()
{
func
prepareDivider
()
{
dividerColor
=
dividerNormalColor
dividerColor
=
dividerNormalColor
}
}
/// Prepares the placeholderLabel.
/// Prepares the placeholderLabel.
func
preparePlaceholderLabel
()
{
func
preparePlaceholderLabel
()
{
placeholderNormalColor
=
Color
.
darkText
.
others
placeholderNormalColor
=
Color
.
darkText
.
others
placeholderLabel
.
backgroundColor
=
.
clear
placeholderLabel
.
backgroundColor
=
.
clear
addSubview
(
placeholderLabel
)
addSubview
(
placeholderLabel
)
}
}
/// Prepares the detailLabel.
/// Prepares the detailLabel.
func
prepareDetailLabel
()
{
func
prepareDetailLabel
()
{
detailLabel
.
font
=
RobotoFont
.
regular
(
with
:
12
)
detailLabel
.
font
=
RobotoFont
.
regular
(
with
:
12
)
...
@@ -481,21 +481,21 @@ fileprivate extension TextField {
...
@@ -481,21 +481,21 @@ fileprivate extension TextField {
detailColor
=
Color
.
darkText
.
others
detailColor
=
Color
.
darkText
.
others
addSubview
(
detailLabel
)
addSubview
(
detailLabel
)
}
}
/// Prepares the leftView.
/// Prepares the leftView.
func
prepareLeftView
()
{
func
prepareLeftView
()
{
leftView
?
.
contentMode
=
.
left
leftView
?
.
contentMode
=
.
left
leftViewMode
=
.
always
leftViewMode
=
.
always
updateLeftViewColor
()
updateLeftViewColor
()
}
}
/// Prepares the target handlers.
/// Prepares the target handlers.
func
prepareTargetHandlers
()
{
func
prepareTargetHandlers
()
{
addTarget
(
self
,
action
:
#selector(
handleEditingDidBegin
)
,
for
:
.
editingDidBegin
)
addTarget
(
self
,
action
:
#selector(
handleEditingDidBegin
)
,
for
:
.
editingDidBegin
)
addTarget
(
self
,
action
:
#selector(
handleEditingChanged
)
,
for
:
.
editingChanged
)
addTarget
(
self
,
action
:
#selector(
handleEditingChanged
)
,
for
:
.
editingChanged
)
addTarget
(
self
,
action
:
#selector(
handleEditingDidEnd
)
,
for
:
.
editingDidEnd
)
addTarget
(
self
,
action
:
#selector(
handleEditingDidEnd
)
,
for
:
.
editingDidEnd
)
}
}
/// Prepares the textAlignment.
/// Prepares the textAlignment.
func
prepareTextAlignment
()
{
func
prepareTextAlignment
()
{
textAlignment
=
.
rightToLeft
==
Application
.
userInterfaceLayoutDirection
?
.
right
:
.
left
textAlignment
=
.
rightToLeft
==
Application
.
userInterfaceLayoutDirection
?
.
right
:
.
left
...
@@ -507,39 +507,39 @@ fileprivate extension TextField {
...
@@ -507,39 +507,39 @@ fileprivate extension TextField {
func
updateLeftViewColor
()
{
func
updateLeftViewColor
()
{
leftView
?
.
tintColor
=
isEditing
?
leftViewActiveColor
:
leftViewNormalColor
leftView
?
.
tintColor
=
isEditing
?
leftViewActiveColor
:
leftViewNormalColor
}
}
/// Updates the placeholderLabel text color.
/// Updates the placeholderLabel text color.
func
updatePlaceholderLabelColor
()
{
func
updatePlaceholderLabelColor
()
{
tintColor
=
placeholderActiveColor
tintColor
=
placeholderActiveColor
placeholderLabel
.
textColor
=
isEditing
?
placeholderActiveColor
:
placeholderNormalColor
placeholderLabel
.
textColor
=
isEditing
?
placeholderActiveColor
:
placeholderNormalColor
}
}
/// Update the placeholder text to the active state.
/// Update the placeholder text to the active state.
func
updatePlaceholderTextToActiveState
()
{
func
updatePlaceholderTextToActiveState
()
{
guard
isPlaceholderUppercasedWhenEditing
else
{
guard
isPlaceholderUppercasedWhenEditing
else
{
return
return
}
}
guard
isEditing
||
!
isEmpty
else
{
guard
isEditing
||
!
isEmpty
else
{
return
return
}
}
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
uppercased
()
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
uppercased
()
}
}
/// Update the placeholder text to the normal state.
/// Update the placeholder text to the normal state.
func
updatePlaceholderTextToNormalState
()
{
func
updatePlaceholderTextToNormalState
()
{
guard
isPlaceholderUppercasedWhenEditing
else
{
guard
isPlaceholderUppercasedWhenEditing
else
{
return
return
}
}
guard
isEmpty
else
{
guard
isEmpty
else
{
return
return
}
}
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
capitalized
placeholderLabel
.
text
=
placeholderLabel
.
text
?
.
capitalized
}
}
/// Updates the detailLabel text color.
/// Updates the detailLabel text color.
func
updateDetailLabelColor
()
{
func
updateDetailLabelColor
()
{
detailLabel
.
textColor
=
detailColor
detailLabel
.
textColor
=
detailColor
...
@@ -551,28 +551,28 @@ fileprivate extension TextField {
...
@@ -551,28 +551,28 @@ fileprivate extension TextField {
func
layoutPlaceholderLabel
()
{
func
layoutPlaceholderLabel
()
{
let
w
=
leftViewWidth
+
textInset
let
w
=
leftViewWidth
+
textInset
let
h
=
0
==
bounds
.
height
?
intrinsicContentSize
.
height
:
bounds
.
height
let
h
=
0
==
bounds
.
height
?
intrinsicContentSize
.
height
:
bounds
.
height
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
guard
isEditing
||
!
isEmpty
||
!
isPlaceholderAnimated
else
{
guard
isEditing
||
!
isEmpty
||
!
isPlaceholderAnimated
else
{
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
bounds
.
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
bounds
.
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
return
return
}
}
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
bounds
.
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
bounds
.
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
placeholderActiveScale
,
y
:
placeholderActiveScale
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
placeholderActiveScale
,
y
:
placeholderActiveScale
)
switch
textAlignment
{
switch
textAlignment
{
case
.
left
,
.
natural
:
case
.
left
,
.
natural
:
placeholderLabel
.
frame
.
origin
.
x
=
w
+
placeholderHorizontalOffset
placeholderLabel
.
frame
.
origin
.
x
=
w
+
placeholderHorizontalOffset
case
.
right
:
case
.
right
:
placeholderLabel
.
frame
.
origin
.
x
=
bounds
.
width
-
placeholderLabel
.
bounds
.
width
-
textInset
+
placeholderHorizontalOffset
placeholderLabel
.
frame
.
origin
.
x
=
(
bounds
.
width
*
(
1.0
-
placeholderActiveScale
))
-
textInset
+
placeholderHorizontalOffset
default
:
break
default
:
break
}
}
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
bounds
.
height
+
placeholderVerticalOffset
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
bounds
.
height
+
placeholderVerticalOffset
}
}
/// Layout the detailLabel.
/// Layout the detailLabel.
func
layoutDetailLabel
()
{
func
layoutDetailLabel
()
{
let
c
=
dividerContentEdgeInsets
let
c
=
dividerContentEdgeInsets
...
@@ -581,18 +581,18 @@ fileprivate extension TextField {
...
@@ -581,18 +581,18 @@ fileprivate extension TextField {
detailLabel
.
frame
.
origin
.
y
=
bounds
.
height
+
detailVerticalOffset
detailLabel
.
frame
.
origin
.
y
=
bounds
.
height
+
detailVerticalOffset
detailLabel
.
frame
.
size
.
width
=
bounds
.
width
-
c
.
left
-
c
.
right
detailLabel
.
frame
.
size
.
width
=
bounds
.
width
-
c
.
left
-
c
.
right
}
}
/// Layout the a button.
/// Layout the a button.
func
layoutButton
(
button
:
UIButton
?)
{
func
layoutButton
(
button
:
UIButton
?)
{
button
?
.
frame
=
CGRect
(
x
:
bounds
.
width
-
bounds
.
height
,
y
:
0
,
width
:
bounds
.
height
,
height
:
bounds
.
height
)
button
?
.
frame
=
CGRect
(
x
:
bounds
.
width
-
bounds
.
height
,
y
:
0
,
width
:
bounds
.
height
,
height
:
bounds
.
height
)
}
}
/// Layout the leftView.
/// Layout the leftView.
func
layoutLeftView
()
{
func
layoutLeftView
()
{
guard
let
v
=
leftView
else
{
guard
let
v
=
leftView
else
{
return
return
}
}
let
w
=
leftViewWidth
let
w
=
leftViewWidth
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
bounds
.
height
)
v
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
w
,
height
:
bounds
.
height
)
dividerContentEdgeInsets
.
left
=
w
dividerContentEdgeInsets
.
left
=
w
...
@@ -607,13 +607,13 @@ fileprivate extension TextField {
...
@@ -607,13 +607,13 @@ fileprivate extension TextField {
placeholderEditingDidBeginAnimation
()
placeholderEditingDidBeginAnimation
()
dividerEditingDidBeginAnimation
()
dividerEditingDidBeginAnimation
()
}
}
// Live updates the textField text.
// Live updates the textField text.
@objc
@objc
func
handleEditingChanged
(
textField
:
UITextField
)
{
func
handleEditingChanged
(
textField
:
UITextField
)
{
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
didChange
:
textField
.
text
)
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
didChange
:
textField
.
text
)
}
}
/// Handles the text editing did end state.
/// Handles the text editing did end state.
@objc
@objc
func
handleEditingDidEnd
()
{
func
handleEditingDidEnd
()
{
...
@@ -621,33 +621,33 @@ fileprivate extension TextField {
...
@@ -621,33 +621,33 @@ fileprivate extension TextField {
placeholderEditingDidEndAnimation
()
placeholderEditingDidEndAnimation
()
dividerEditingDidEndAnimation
()
dividerEditingDidEndAnimation
()
}
}
/// Handles the clearIconButton TouchUpInside event.
/// Handles the clearIconButton TouchUpInside event.
@objc
@objc
func
handleClearIconButton
()
{
func
handleClearIconButton
()
{
guard
nil
==
delegate
?
.
textFieldShouldClear
||
true
==
delegate
?
.
textFieldShouldClear
?(
self
)
else
{
guard
nil
==
delegate
?
.
textFieldShouldClear
||
true
==
delegate
?
.
textFieldShouldClear
?(
self
)
else
{
return
return
}
}
let
t
=
text
let
t
=
text
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
willClear
:
t
)
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
willClear
:
t
)
text
=
nil
text
=
nil
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
didClear
:
t
)
(
delegate
as?
TextFieldDelegate
)?
.
textField
?(
textField
:
self
,
didClear
:
t
)
}
}
/// Handles the visibilityIconButton TouchUpInside event.
/// Handles the visibilityIconButton TouchUpInside event.
@objc
@objc
func
handleVisibilityIconButton
()
{
func
handleVisibilityIconButton
()
{
isSecureTextEntry
=
!
isSecureTextEntry
isSecureTextEntry
=
!
isSecureTextEntry
if
!
isSecureTextEntry
{
if
!
isSecureTextEntry
{
super
.
font
=
nil
super
.
font
=
nil
font
=
placeholderLabel
.
font
font
=
placeholderLabel
.
font
}
}
visibilityIconButton
?
.
tintColor
=
visibilityIconButton
?
.
tintColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
)
visibilityIconButton
?
.
tintColor
=
visibilityIconButton
?
.
tintColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
)
}
}
}
}
...
@@ -657,87 +657,87 @@ extension TextField {
...
@@ -657,87 +657,87 @@ extension TextField {
fileprivate
func
leftViewEditingBeginAnimation
()
{
fileprivate
func
leftViewEditingBeginAnimation
()
{
updateLeftViewColor
()
updateLeftViewColor
()
}
}
/// The animation for leftView when editing ends.
/// The animation for leftView when editing ends.
fileprivate
func
leftViewEditingEndAnimation
()
{
fileprivate
func
leftViewEditingEndAnimation
()
{
updateLeftViewColor
()
updateLeftViewColor
()
}
}
/// The animation for the divider when editing begins.
/// The animation for the divider when editing begins.
fileprivate
func
dividerEditingDidBeginAnimation
()
{
fileprivate
func
dividerEditingDidBeginAnimation
()
{
dividerThickness
=
dividerActiveHeight
dividerThickness
=
dividerActiveHeight
dividerColor
=
dividerActiveColor
dividerColor
=
dividerActiveColor
}
}
/// The animation for the divider when editing ends.
/// The animation for the divider when editing ends.
fileprivate
func
dividerEditingDidEndAnimation
()
{
fileprivate
func
dividerEditingDidEndAnimation
()
{
dividerThickness
=
dividerNormalHeight
dividerThickness
=
dividerNormalHeight
dividerColor
=
dividerNormalColor
dividerColor
=
dividerNormalColor
}
}
/// The animation for the placeholder when editing begins.
/// The animation for the placeholder when editing begins.
fileprivate
func
placeholderEditingDidBeginAnimation
()
{
fileprivate
func
placeholderEditingDidBeginAnimation
()
{
guard
.
default
==
placeholderAnimation
else
{
guard
.
default
==
placeholderAnimation
else
{
placeholderLabel
.
isHidden
=
true
placeholderLabel
.
isHidden
=
true
return
return
}
}
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
guard
isPlaceholderAnimated
else
{
guard
isPlaceholderAnimated
else
{
updatePlaceholderTextToActiveState
()
updatePlaceholderTextToActiveState
()
return
return
}
}
guard
isEmpty
else
{
guard
isEmpty
else
{
updatePlaceholderTextToActiveState
()
updatePlaceholderTextToActiveState
()
return
return
}
}
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
}
}
s
.
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
s
.
placeholderActiveScale
,
y
:
s
.
placeholderActiveScale
)
s
.
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
s
.
placeholderActiveScale
,
y
:
s
.
placeholderActiveScale
)
s
.
updatePlaceholderTextToActiveState
()
s
.
updatePlaceholderTextToActiveState
()
switch
s
.
textAlignment
{
switch
s
.
textAlignment
{
case
.
left
,
.
natural
:
case
.
left
,
.
natural
:
s
.
placeholderLabel
.
frame
.
origin
.
x
=
s
.
leftViewWidth
+
s
.
textInset
+
s
.
placeholderHorizontalOffset
s
.
placeholderLabel
.
frame
.
origin
.
x
=
s
.
leftViewWidth
+
s
.
textInset
+
s
.
placeholderHorizontalOffset
case
.
right
:
case
.
right
:
s
.
placeholderLabel
.
frame
.
origin
.
x
=
s
.
bounds
.
width
-
s
.
placeholderLabel
.
bounds
.
width
-
s
.
textInset
+
s
.
placeholderHorizontalOffset
s
.
placeholderLabel
.
frame
.
origin
.
x
=
(
s
.
bounds
.
width
*
(
1.0
-
s
.
placeholderActiveScale
))
-
s
.
textInset
+
s
.
placeholderHorizontalOffset
default
:
break
default
:
break
}
}
s
.
placeholderLabel
.
frame
.
origin
.
y
=
-
s
.
placeholderLabel
.
bounds
.
height
+
s
.
placeholderVerticalOffset
s
.
placeholderLabel
.
frame
.
origin
.
y
=
-
s
.
placeholderLabel
.
bounds
.
height
+
s
.
placeholderVerticalOffset
})
})
}
}
/// The animation for the placeholder when editing ends.
/// The animation for the placeholder when editing ends.
fileprivate
func
placeholderEditingDidEndAnimation
()
{
fileprivate
func
placeholderEditingDidEndAnimation
()
{
guard
.
default
==
placeholderAnimation
else
{
guard
.
default
==
placeholderAnimation
else
{
placeholderLabel
.
isHidden
=
!
isEmpty
placeholderLabel
.
isHidden
=
!
isEmpty
return
return
}
}
updatePlaceholderLabelColor
()
updatePlaceholderLabelColor
()
updatePlaceholderTextToNormalState
()
updatePlaceholderTextToNormalState
()
guard
isPlaceholderAnimated
else
{
guard
isPlaceholderAnimated
else
{
return
return
}
}
guard
isEmpty
else
{
guard
isEmpty
else
{
return
return
}
}
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
}
}
s
.
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
s
.
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
s
.
placeholderLabel
.
frame
.
origin
.
x
=
s
.
leftViewWidth
+
s
.
textInset
s
.
placeholderLabel
.
frame
.
origin
.
x
=
s
.
leftViewWidth
+
s
.
textInset
s
.
placeholderLabel
.
frame
.
origin
.
y
=
0
s
.
placeholderLabel
.
frame
.
origin
.
y
=
0
...
...
Sources/iOS/Toolbar.swift
View file @
ef355c28
...
@@ -33,10 +33,34 @@ import UIKit
...
@@ -33,10 +33,34 @@ import UIKit
fileprivate
var
ToolbarContext
:
UInt8
=
0
fileprivate
var
ToolbarContext
:
UInt8
=
0
open
class
Toolbar
:
Bar
{
open
class
Toolbar
:
Bar
{
/// A convenience property to set the titleLabel.text.
@IBInspectable
open
var
title
:
String
?
{
get
{
return
titleLabel
.
text
}
set
(
value
)
{
titleLabel
.
text
=
value
layoutSubviews
()
}
}
/// Title label.
/// Title label.
@IBInspectable
@IBInspectable
open
let
titleLabel
=
UILabel
()
open
let
titleLabel
=
UILabel
()
/// A convenience property to set the detailLabel.text.
@IBInspectable
open
var
detail
:
String
?
{
get
{
return
detailLabel
.
text
}
set
(
value
)
{
detailLabel
.
text
=
value
layoutSubviews
()
}
}
/// Detail label.
/// Detail label.
@IBInspectable
@IBInspectable
open
let
detailLabel
=
UILabel
()
open
let
detailLabel
=
UILabel
()
...
...
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