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
b66f37d2
Commit
b66f37d2
authored
Jan 02, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated internal presets and default values
parent
0209d364
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
774 additions
and
306 deletions
+774
-306
Examples/Programmatic/CardView/CardView/ViewController.swift
+3
-3
Examples/Programmatic/ImageCardView/ImageCardView/ViewController.swift
+2
-2
Examples/Programmatic/NavigationBarView/NavigationBarView/ViewController.swift
+2
-2
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/TextField/TextField/ViewController.swift
+5
-5
Examples/Programmatic/TextView/TextView/ViewController.swift
+2
-3
Examples/Storyboards/CardView/CardView/ViewController.swift
+3
-3
Examples/Storyboards/ImageCardView/ImageCardView/ViewController.swift
+2
-2
Examples/Storyboards/NavigationBarView/NavigationBarView/ViewController.swift
+2
-2
README.md
+57
-52
Sources/CaptureView.swift
+9
-9
Sources/CardView.swift
+47
-47
Sources/FlatButton.swift
+2
-1
Sources/ImageCardView.swift
+58
-58
Sources/MaterialButton.swift
+5
-5
Sources/MaterialView.swift
+1
-1
Sources/NavigationBarView.swift
+33
-33
Sources/RaisedButton.swift
+2
-1
Sources/TextField.swift
+211
-36
Sources/TextView.swift
+322
-41
No files found.
Examples/Programmatic/CardView/CardView/ViewController.swift
View file @
b66f37d2
...
...
@@ -141,9 +141,9 @@ class ViewController: UIViewController {
*/
private
func
prepareCardViewWithAlteredAlignmentExample
()
{
let
cardView
:
CardView
=
CardView
()
cardView
.
dividerInset
sRef
.
left
=
100
cardView
.
titleLabelInset
sRef
.
left
=
100
cardView
.
detailLabelInset
sRef
.
left
=
100
cardView
.
dividerInset
.
left
=
100
cardView
.
titleLabelInset
.
left
=
100
cardView
.
detailLabelInset
.
left
=
100
cardView
.
pulseColor
=
MaterialColor
.
teal
.
lighten4
// Image.
...
...
Examples/Programmatic/ImageCardView/ImageCardView/ViewController.swift
View file @
b66f37d2
...
...
@@ -69,7 +69,7 @@ class ViewController: UIViewController {
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
mediumWithSize
(
24
)
imageCardView
.
titleLabel
=
titleLabel
imageCardView
.
titleLabelInset
sRef
.
top
=
100
imageCardView
.
titleLabelInset
.
top
=
100
// Detail label.
let
detailLabel
:
UILabel
=
UILabel
()
...
...
@@ -120,7 +120,7 @@ class ViewController: UIViewController {
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
24
)
imageCardView
.
titleLabel
=
titleLabel
imageCardView
.
titleLabelInset
sRef
.
top
=
80
imageCardView
.
titleLabelInset
.
top
=
80
// Star button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_star_grey_darken_2"
)
...
...
Examples/Programmatic/NavigationBarView/NavigationBarView/ViewController.swift
View file @
b66f37d2
...
...
@@ -253,7 +253,7 @@ class ViewController: UIViewController {
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
20
)
navigationBarView
.
titleLabel
=
titleLabel
navigationBarView
.
titleLabelInset
sRef
.
left
=
64
navigationBarView
.
titleLabelInset
.
left
=
64
// Detail label.
let
detailLabel
:
UILabel
=
UILabel
()
...
...
@@ -262,7 +262,7 @@ class ViewController: UIViewController {
detailLabel
.
textColor
=
MaterialColor
.
white
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
navigationBarView
.
detailLabel
=
detailLabel
navigationBarView
.
detailLabelInset
sRef
.
left
=
64
navigationBarView
.
detailLabelInset
.
left
=
64
// Menu button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_menu_white"
)
...
...
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
b66f37d2
...
...
@@ -7,6 +7,8 @@
objects
=
{
/* Begin PBXBuildFile section */
960590361C38B80400691E88
/* MaterialKit.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590351C38B80400691E88
/* MaterialKit.framework */
;
};
960590371C38B80400691E88
/* MaterialKit.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
960590351C38B80400691E88
/* MaterialKit.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
...
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
960590371C38B80400691E88
/* MaterialKit.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
960590351C38B80400691E88
/* MaterialKit.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
MaterialKit.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"
;
sourceTree
=
"<absolute>"
;
};
966F579D1C226BAA009185B7
/* TextField.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
TextField.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
966F57A01C226BAA009185B7
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
966F57A21C226BAA009185B7
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
960590361C38B80400691E88
/* MaterialKit.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -49,6 +54,7 @@
966F57941C226BAA009185B7
=
{
isa
=
PBXGroup
;
children
=
(
960590351C38B80400691E88
/* MaterialKit.framework */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579E1C226BAA009185B7
/* Products */
,
);
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
b66f37d2
...
...
@@ -50,8 +50,8 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabel
Normal
Color
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabel
Highlighted
Color
=
MaterialColor
.
blue
.
accent3
nameField
.
titleLabel
Text
Color
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabel
ActiveText
Color
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
view
.
addSubview
(
nameField
)
}
...
...
@@ -68,13 +68,13 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField
.
textColor
=
MaterialColor
.
black
emailField
.
titleLabel
=
UILabel
()
emailField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
emailField
.
titleLabel
Normal
Color
=
MaterialColor
.
grey
.
lighten2
emailField
.
titleLabel
Highlighted
Color
=
MaterialColor
.
blue
.
accent3
emailField
.
titleLabel
Text
Color
=
MaterialColor
.
grey
.
lighten2
emailField
.
titleLabel
ActiveText
Color
=
MaterialColor
.
blue
.
accent3
emailField
.
clearButtonMode
=
.
WhileEditing
emailField
.
detailLabel
=
UILabel
()
emailField
.
detailLabel
!.
text
=
"Email is incorrect."
emailField
.
detailLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
emailField
.
detailLabel
Highlighted
Color
=
MaterialColor
.
red
.
accent3
emailField
.
detailLabel
ActiveText
Color
=
MaterialColor
.
red
.
accent3
view
.
addSubview
(
emailField
)
}
...
...
Examples/Programmatic/TextView/TextView/ViewController.swift
View file @
b66f37d2
...
...
@@ -53,8 +53,8 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
textView
.
titleLabel
=
UILabel
()
textView
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textView
.
titleLabel
Normal
Color
=
MaterialColor
.
grey
.
lighten2
textView
.
titleLabel
Highlighted
Color
=
MaterialColor
.
blue
.
accent3
textView
.
titleLabel
Text
Color
=
MaterialColor
.
grey
.
lighten2
textView
.
titleLabel
ActiveText
Color
=
MaterialColor
.
blue
.
accent3
view
.
addSubview
(
textView
)
textView
!.
translatesAutoresizingMaskIntoConstraints
=
false
...
...
@@ -69,6 +69,5 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
func
textDidProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
result
:
NSTextCheckingResult
?,
flags
:
NSMatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
{
textStorage
.
addAttribute
(
NSFontAttributeName
,
value
:
UIFont
.
boldSystemFontOfSize
(
16
),
range
:
result
!.
range
)
}
}
Examples/Storyboards/CardView/CardView/ViewController.swift
View file @
b66f37d2
...
...
@@ -83,9 +83,9 @@ class ViewController: UIViewController {
:description: General usage example.
*/
func
prepareCardViewExampleTwo
()
{
secondCardView
.
dividerInset
sRef
.
left
=
100
secondCardView
.
titleLabelInset
sRef
.
left
=
100
secondCardView
.
detailLabelInset
sRef
.
left
=
100
secondCardView
.
dividerInset
.
left
=
100
secondCardView
.
titleLabelInset
.
left
=
100
secondCardView
.
detailLabelInset
.
left
=
100
secondCardView
.
pulseColor
=
MaterialColor
.
teal
.
lighten4
// Image.
...
...
Examples/Storyboards/ImageCardView/ImageCardView/ViewController.swift
View file @
b66f37d2
...
...
@@ -46,7 +46,7 @@ class ViewController: UIViewController {
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
24
)
imageCardView
.
titleLabel
=
titleLabel
imageCardView
.
titleLabelInset
sRef
.
top
=
80
imageCardView
.
titleLabelInset
.
top
=
80
// Star button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_star_grey_darken_2"
)
...
...
@@ -77,7 +77,7 @@ class ViewController: UIViewController {
// Add buttons to right side.
imageCardView
.
rightButtons
=
[
btn1
,
btn2
,
btn3
]
imageCardView
.
rightButtonsInset
sRef
.
top
=
imageCardView
.
contentInsetsRef
.
top
imageCardView
.
rightButtonsInset
.
top
=
imageCardView
.
contentInset
.
top
}
}
Examples/Storyboards/NavigationBarView/NavigationBarView/ViewController.swift
View file @
b66f37d2
...
...
@@ -58,7 +58,7 @@ class ViewController: UIViewController {
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
20
)
navigationBarView
.
titleLabel
=
titleLabel
navigationBarView
.
titleLabelInset
sRef
.
left
=
64
navigationBarView
.
titleLabelInset
.
left
=
64
// Detail label.
let
detailLabel
:
UILabel
=
UILabel
()
...
...
@@ -67,7 +67,7 @@ class ViewController: UIViewController {
detailLabel
.
textColor
=
MaterialColor
.
white
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
navigationBarView
.
detailLabel
=
detailLabel
navigationBarView
.
detailLabelInset
sRef
.
left
=
64
navigationBarView
.
detailLabelInset
.
left
=
64
// Menu button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_menu_white"
)
...
...
README.md
View file @
b66f37d2
...
...
@@ -28,6 +28,7 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
### Table of Contents
*
[
MaterialColor
](
#materialcolor
)
*
[
MaterialLayer
](
#materiallayer
)
*
[
MaterialView
](
#materialview
)
*
[
MaterialPulseView
](
#materialpulseview
)
...
...
@@ -43,7 +44,6 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
*
[
Crop Image
](
#cropimage
)
*
[
Save Image To PhotoLibrary
](
#saveimagetophotolibrary
)
*
[
Asynchronous Image Loading
](
#asynchronousimageloading
)
*
[
MaterialColor
](
#materialcolor
)
*
[
TextField
](
#textfield
)
*
[
TextView
](
#textview
)
*
[
Lines of Text
](
#linesoftext
)
...
...
@@ -63,6 +63,40 @@ Run carthage to build the framework and drag the built MaterialKit.framework int
*
TimePicker
*
More Examples
<a
name=
"materialcolor"
/>
### MaterialColor
Explore a complete range of Material Design colors using MaterialColor. Below is an example of setting a button's background color property.

```
swift
let
button
:
FabButton
=
FabButton
()
button
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
```
<a
name=
"textfield"
/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.

```
swift
let
nameField
:
TextField
=
TextField
(
frame
:
CGRectMake
(
57
,
100
,
300
,
24
))
nameField
.
placeholder
=
"First Name"
nameField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
// Add nameField to UIViewController.
view
.
addSubview
(
nameField
)
```
<a
name=
"materiallayer"
/>
### MaterialLayer
...
...
@@ -266,9 +300,9 @@ Adjust the alignment of the UI elements to create different configurations of th
```
swift
let
cardView
:
CardView
=
CardView
()
cardView
.
dividerInset
sRef
.
left
=
100
cardView
.
titleLabelInset
sRef
.
left
=
100
cardView
.
detailLabelInset
sRef
.
left
=
100
cardView
.
dividerInset
.
left
=
100
cardView
.
titleLabelInset
.
left
=
100
cardView
.
detailLabelInset
.
left
=
100
cardView
.
pulseColor
=
MaterialColor
.
teal
.
lighten4
// Image.
...
...
@@ -376,7 +410,7 @@ titleLabel.text = "Welcome Back!"
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
mediumWithSize
(
24
)
imageCardView
.
titleLabel
=
titleLabel
imageCardView
.
titleLabelInset
sRef
.
top
=
100
imageCardView
.
titleLabelInset
.
top
=
100
// Detail label.
let
detailLabel
:
UILabel
=
UILabel
()
...
...
@@ -427,7 +461,7 @@ titleLabel.text = "Material Design"
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
24
)
imageCardView
.
titleLabel
=
titleLabel
imageCardView
.
titleLabelInset
sRef
.
top
=
80
imageCardView
.
titleLabelInset
.
top
=
80
// Star button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_star_grey_darken_2"
)
...
...
@@ -490,7 +524,7 @@ titleLabel.textAlignment = .Left
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
20
)
navigationBarView
.
titleLabel
=
titleLabel
navigationBarView
.
titleLabelInset
sRef
.
left
=
64
navigationBarView
.
titleLabelInset
.
left
=
64
// Detail label.
let
detailLabel
:
UILabel
=
UILabel
()
...
...
@@ -499,7 +533,7 @@ detailLabel.textAlignment = .Left
detailLabel
.
textColor
=
MaterialColor
.
white
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
navigationBarView
.
detailLabel
=
detailLabel
navigationBarView
.
detailLabelInset
sRef
.
left
=
64
navigationBarView
.
detailLabelInset
.
left
=
64
// Menu button.
let
img1
:
UIImage
?
=
UIImage
(
named
:
"ic_menu_white"
)
...
...
@@ -620,40 +654,6 @@ UIImage.contentsOfURL(url) { (image: UIImage?, error: NSError?) in
}
```
<a
name=
"materialcolor"
/>
### MaterialColor
Explore a complete range of Material Design colors using MaterialColor. Below is an example of setting a button's background color property.

```
swift
let
button
:
FabButton
=
FabButton
()
button
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
```
<a
name=
"textfield"
/>
### TextField
A TextField is an excellent way to improve UX. Checkout the Examples directory for a project using this component.

```
swift
let
nameField
:
TextField
=
TextField
(
frame
:
CGRectMake
(
57
,
100
,
300
,
24
))
nameField
.
placeholder
=
"First Name"
nameField
.
font
=
RobotoFont
.
regularWithSize
(
20
)
nameField
.
textColor
=
MaterialColor
.
black
nameField
.
titleLabel
=
UILabel
()
nameField
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
nameField
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
nameField
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
nameField
.
clearButtonMode
=
.
WhileEditing
// Add nameField to UIViewController.
view
.
addSubview
(
nameField
)
```
<a
name=
"textview"
/>
### TextView
...
...
@@ -664,7 +664,7 @@ Easily match any regular expression pattern in a body of text. Below is an examp
```
swift
class
ViewController
:
UIViewController
,
TextDelegate
,
TextViewDelegate
{
lazy
var
text
:
Text
=
Text
()
var
textView
:
TextView
?
var
textView
:
TextView
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -685,18 +685,23 @@ class ViewController: UIViewController, TextDelegate, TextViewDelegate {
text
.
textStorage
.
addLayoutManager
(
layoutManager
)
textView
=
TextView
(
frame
:
CGRectNull
,
textContainer
:
textContainer
)
textView
?
.
delegate
=
self
textView
!.
editable
=
true
textView
!.
selectable
=
true
textView
!.
font
=
RobotoFont
.
regular
textView
.
delegate
=
self
textView
.
editable
=
true
textView
.
selectable
=
true
textView
.
font
=
RobotoFont
.
regular
textView
.
placeholderLabel
=
UILabel
()
textView
.
placeholderLabel
!.
textColor
=
MaterialColor
.
grey
.
base
textView
.
placeholderLabel
!.
text
=
"Description"
textView
!.
placeholderLabel
=
UILabel
()
textView
!.
placeholderLabel
!.
textColor
=
MaterialColor
.
grey
.
base
textView
!.
placeholderLabel
!.
text
=
"MaterialKit TextView"
textView
.
titleLabel
=
UILabel
()
textView
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
12
)
textView
.
titleLabelNormalColor
=
MaterialColor
.
grey
.
lighten2
textView
.
titleLabelHighlightedColor
=
MaterialColor
.
blue
.
accent3
view
.
addSubview
(
textView
!
)
view
.
addSubview
(
textView
)
textView
!.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
textView
!
,
top
:
24
,
left
:
24
,
bottom
:
24
,
right
:
24
)
MaterialLayout
.
alignToParent
(
view
,
child
:
textView
!
,
top
:
1
24
,
left
:
24
,
bottom
:
24
,
right
:
24
)
}
func
textWillProcessEdit
(
text
:
Text
,
textStorage
:
TextStorage
,
string
:
String
,
range
:
NSRange
)
{
...
...
Sources/CaptureView.swift
View file @
b66f37d2
...
...
@@ -173,16 +173,16 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
/**
:name: contentInsets
*/
public
var
contentInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
contentInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
contentInset
sRef
=
MaterialEdgeInsetsToValue
(
contentInsets
)
contentInset
=
MaterialEdgeInsetsToValue
(
contentInsetPreset
)
}
}
/**
:name: contentInset
sRef
:name: contentInset
*/
public
var
contentInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square4
)
{
public
var
contentInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square4
)
{
didSet
{
reloadView
()
}
...
...
@@ -287,16 +287,16 @@ public class CaptureView : MaterialView, UIGestureRecognizerDelegate {
previewView
.
frame
=
bounds
if
let
v
:
UIButton
=
cameraButton
{
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
sRef
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
x
=
contentInset
sRef
.
left
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
x
=
contentInset
.
left
}
if
let
v
:
UIButton
=
captureButton
{
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
sRef
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
x
=
(
bounds
.
width
-
v
.
bounds
.
width
)
/
2
}
if
let
v
:
UIButton
=
videoButton
{
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
sRef
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
x
=
bounds
.
width
-
v
.
bounds
.
width
-
contentInset
sRef
.
right
v
.
frame
.
origin
.
y
=
bounds
.
height
-
contentInset
.
bottom
-
v
.
bounds
.
height
v
.
frame
.
origin
.
x
=
bounds
.
width
-
v
.
bounds
.
width
-
contentInset
.
right
}
if
let
v
:
AVCaptureConnection
=
(
previewView
.
layer
as!
AVCaptureVideoPreviewLayer
)
.
connection
{
v
.
videoOrientation
=
captureSession
.
currentVideoOrientation
...
...
Sources/CardView.swift
View file @
b66f37d2
...
...
@@ -45,16 +45,16 @@ public class CardView : MaterialPulseView {
/**
:name: dividerInsets
*/
public
var
dividerInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
dividerInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
dividerInset
sRef
=
MaterialEdgeInsetsToValue
(
dividerInsets
)
dividerInset
=
MaterialEdgeInsetsToValue
(
dividerInsetPreset
)
}
}
/**
:name: dividerInset
sRef
:name: dividerInset
*/
public
var
dividerInset
sRef
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
{
public
var
dividerInset
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
{
didSet
{
reloadView
()
}
...
...
@@ -63,16 +63,16 @@ public class CardView : MaterialPulseView {
/**
:name: contentInsets
*/
public
var
contentInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
contentInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
contentInset
sRef
=
MaterialEdgeInsetsToValue
(
contentInsets
)
contentInset
=
MaterialEdgeInsetsToValue
(
contentInsetPreset
)
}
}
/**
:name: contentInset
sRef
:name: contentInset
*/
public
var
contentInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
contentInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -81,16 +81,16 @@ public class CardView : MaterialPulseView {
/**
:name: titleLabelInsets
*/
public
var
titleLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
titleLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
titleLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
titleLabelInsets
)
titleLabelInset
=
MaterialEdgeInsetsToValue
(
titleLabelInsetPreset
)
}
}
/**
:name: titleLabelInset
sRef
:name: titleLabelInset
*/
public
var
titleLabelInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
titleLabelInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -109,16 +109,16 @@ public class CardView : MaterialPulseView {
/**
:name: detailLabelInsets
*/
public
var
detailLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
detailLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
detailLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
detailLabelInsets
)
detailLabelInset
=
MaterialEdgeInsetsToValue
(
detailLabelInsetPreset
)
}
}
/**
:name: detailLabelInset
sRef
:name: detailLabelInset
*/
public
var
detailLabelInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
detailLabelInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -137,16 +137,16 @@ public class CardView : MaterialPulseView {
/**
:name: leftButtonsInsets
*/
public
var
leftButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
leftButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
leftButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
leftButtonsInsets
)
leftButtonsInset
=
MaterialEdgeInsetsToValue
(
leftButtonsInsetPreset
)
}
}
/**
:name: leftButtonsInset
sRef
:name: leftButtonsInset
*/
public
var
leftButtonsInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
public
var
leftButtonsInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
didSet
{
reloadView
()
}
...
...
@@ -169,16 +169,16 @@ public class CardView : MaterialPulseView {
/**
:name: rightButtonsInsets
*/
public
var
rightButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
rightButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
rightButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
rightButtonsInsets
)
rightButtonsInset
=
MaterialEdgeInsetsToValue
(
rightButtonsInsetPreset
)
}
}
/**
:name: rightButtonsInset
sRef
:name: rightButtonsInset
*/
public
var
rightButtonsInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
public
var
rightButtonsInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
didSet
{
reloadView
()
}
...
...
@@ -234,11 +234,11 @@ public class CardView : MaterialPulseView {
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
if
divider
{
var
y
:
CGFloat
=
contentInset
sRef
.
bottom
+
dividerInsetsRef
.
bottom
var
y
:
CGFloat
=
contentInset
.
bottom
+
dividerInset
.
bottom
if
0
<
leftButtons
?
.
count
{
y
+=
leftButtonsInset
sRef
.
top
+
leftButtonsInsetsRef
.
bottom
+
leftButtons
!
[
0
]
.
frame
.
height
y
+=
leftButtonsInset
.
top
+
leftButtonsInset
.
bottom
+
leftButtons
!
[
0
]
.
frame
.
height
}
else
if
0
<
rightButtons
?
.
count
{
y
+=
rightButtonsInset
sRef
.
top
+
rightButtonsInsetsRef
.
bottom
+
rightButtons
!
[
0
]
.
frame
.
height
y
+=
rightButtonsInset
.
top
+
rightButtonsInset
.
bottom
+
rightButtons
!
[
0
]
.
frame
.
height
}
if
0
<
y
{
prepareDivider
(
bounds
.
height
-
y
-
0.5
,
width
:
bounds
.
width
)
...
...
@@ -266,10 +266,10 @@ public class CardView : MaterialPulseView {
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
titleLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
titleLabelInset
.
top
}
else
if
nil
!=
detailLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
detailLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
detailLabelInset
.
top
}
// title
...
...
@@ -279,7 +279,7 @@ public class CardView : MaterialPulseView {
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
titleLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
titleLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
// detail
...
...
@@ -287,16 +287,16 @@ public class CardView : MaterialPulseView {
addSubview
(
v
)
if
nil
==
titleLabel
{
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
top
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
detailLabelInset
.
top
}
else
{
verticalFormat
+=
"-(insetB)"
metrics
[
"insetB"
]
=
titleLabelInset
sRef
.
bottom
+
detailLabelInsetsRef
.
top
metrics
[
"insetB"
]
=
titleLabelInset
.
bottom
+
detailLabelInset
.
top
}
verticalFormat
+=
"-[detailLabel]"
views
[
"detailLabel"
]
=
v
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
detailLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
detailLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
detailLabelInset
.
left
,
right
:
contentInset
.
right
+
detailLabelInset
.
right
)
}
// leftButtons
...
...
@@ -319,10 +319,10 @@ public class CardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
sRef
.
left
+
leftButtonsInsetsRef
.
left
,
"left_right"
:
leftButtonsInsetsRef
.
left
+
leftButtonsInsetsRef
.
right
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
.
left
+
leftButtonsInset
.
left
,
"left_right"
:
leftButtonsInset
.
left
+
leftButtonsInset
.
right
],
views
:
d
))
}
}
...
...
@@ -347,39 +347,39 @@ public class CardView : MaterialPulseView {
}
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
sRef
.
right
+
rightButtonsInsetsRef
.
right
,
"right_left"
:
rightButtonsInsetsRef
.
right
+
rightButtonsInsetsRef
.
left
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
.
right
+
rightButtonsInset
.
right
,
"right_left"
:
rightButtonsInset
.
right
+
rightButtonsInset
.
left
],
views
:
d
))
}
}
if
0
<
leftButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
leftButtons
!
[
0
]
metrics
[
"insetC"
]
=
leftButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
leftButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
leftButtonsInset
.
bottom
}
else
if
0
<
rightButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
rightButtons
!
[
0
]
metrics
[
"insetC"
]
=
rightButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
rightButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
rightButtonsInset
.
bottom
}
if
nil
!=
detailLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
detailLabelInsetsRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
titleLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
titleLabelInsetsRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
titleLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
titleLabelInset
sRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
titleLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
metrics
[
"insetC"
]
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
contentInset
sRef
.
top
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
contentInset
.
top
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
...
...
@@ -409,7 +409,7 @@ public class CardView : MaterialPulseView {
layer
.
addSublayer
(
dividerLayer
!
)
}
dividerLayer
?
.
backgroundColor
=
dividerColor
?
.
CGColor
dividerLayer
?
.
frame
=
CGRectMake
(
dividerInset
sRef
.
left
,
y
,
width
-
dividerInsetsRef
.
left
-
dividerInsetsRef
.
right
,
1
)
dividerLayer
?
.
frame
=
CGRectMake
(
dividerInset
.
left
,
y
,
width
-
dividerInset
.
left
-
dividerInset
.
right
,
1
)
}
/**
...
...
Sources/FlatButton.swift
View file @
b66f37d2
...
...
@@ -31,6 +31,6 @@ public class FlatButton : MaterialButton {
setTitleColor
(
MaterialColor
.
blue
.
accent3
,
forState
:
.
Normal
)
pulseColor
=
MaterialColor
.
blue
.
accent3
cornerRadius
=
.
Radius1
contentInset
s
=
.
WideRectangle3
contentInset
Preset
=
.
WideRectangle3
}
}
\ No newline at end of file
Sources/ImageCardView.swift
View file @
b66f37d2
...
...
@@ -45,16 +45,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: dividerInsets
*/
public
var
dividerInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
dividerInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
dividerInset
sRef
=
MaterialEdgeInsetsToValue
(
dividerInsets
)
dividerInset
=
MaterialEdgeInsetsToValue
(
dividerInsetPreset
)
}
}
/**
:name: dividerInset
sRef
:name: dividerInset
*/
public
var
dividerInset
sRef
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
{
public
var
dividerInset
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
{
didSet
{
reloadView
()
}
...
...
@@ -153,16 +153,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: contentInsets
*/
public
var
contentInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
contentInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
contentInset
sRef
=
MaterialEdgeInsetsToValue
(
contentInsets
)
contentInset
=
MaterialEdgeInsetsToValue
(
contentInsetPreset
)
}
}
/**
:name: contentInset
sRef
:name: contentInset
*/
public
var
contentInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
contentInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -171,16 +171,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: titleLabelInsets
*/
public
var
titleLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
titleLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
titleLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
titleLabelInsets
)
titleLabelInset
=
MaterialEdgeInsetsToValue
(
titleLabelInsetPreset
)
}
}
/**
:name: titleLabelInset
sRef
:name: titleLabelInset
*/
public
var
titleLabelInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
titleLabelInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -199,16 +199,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: detailLabelInsets
*/
public
var
detailLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
detailLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
detailLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
detailLabelInsets
)
detailLabelInset
=
MaterialEdgeInsetsToValue
(
detailLabelInsetPreset
)
}
}
/**
:name: detailLabelInset
sRef
:name: detailLabelInset
*/
public
var
detailLabelInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
detailLabelInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -227,16 +227,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: leftButtonsInsets
*/
public
var
leftButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
leftButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
leftButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
leftButtonsInsets
)
leftButtonsInset
=
MaterialEdgeInsetsToValue
(
leftButtonsInsetPreset
)
}
}
/**
:name: leftButtonsInset
sRef
:name: leftButtonsInset
*/
public
var
leftButtonsInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
public
var
leftButtonsInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
didSet
{
reloadView
()
}
...
...
@@ -259,16 +259,16 @@ public class ImageCardView : MaterialPulseView {
/**
:name: rightButtonsInsets
*/
public
var
rightButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
rightButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
rightButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
rightButtonsInsets
)
rightButtonsInset
=
MaterialEdgeInsetsToValue
(
rightButtonsInsetPreset
)
}
}
/**
:name: rightButtonsInset
sRef
:name: rightButtonsInset
*/
public
var
rightButtonsInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
public
var
rightButtonsInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
didSet
{
reloadView
()
}
...
...
@@ -328,11 +328,11 @@ public class ImageCardView : MaterialPulseView {
// divider
if
divider
{
var
y
:
CGFloat
=
contentInset
sRef
.
bottom
+
dividerInsetsRef
.
bottom
var
y
:
CGFloat
=
contentInset
.
bottom
+
dividerInset
.
bottom
if
0
<
leftButtons
?
.
count
{
y
+=
leftButtonsInset
sRef
.
top
+
leftButtonsInsetsRef
.
bottom
+
leftButtons
!
[
0
]
.
frame
.
height
y
+=
leftButtonsInset
.
top
+
leftButtonsInset
.
bottom
+
leftButtons
!
[
0
]
.
frame
.
height
}
else
if
0
<
rightButtons
?
.
count
{
y
+=
rightButtonsInset
sRef
.
top
+
rightButtonsInsetsRef
.
bottom
+
rightButtons
!
[
0
]
.
frame
.
height
y
+=
rightButtonsInset
.
top
+
rightButtonsInset
.
bottom
+
rightButtons
!
[
0
]
.
frame
.
height
}
if
0
<
y
{
prepareDivider
(
bounds
.
height
-
y
-
0.5
,
width
:
bounds
.
width
)
...
...
@@ -363,10 +363,10 @@ public class ImageCardView : MaterialPulseView {
metrics
[
"insetTop"
]
=
imageLayer
!.
frame
.
height
}
else
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
titleLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
titleLabelInset
.
top
}
else
if
nil
!=
detailLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
detailLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
detailLabelInset
.
top
}
// title
...
...
@@ -377,9 +377,9 @@ public class ImageCardView : MaterialPulseView {
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
}
else
{
MaterialLayout
.
alignFromTop
(
self
,
child
:
v
,
top
:
contentInset
sRef
.
top
+
titleLabelInsetsRef
.
top
)
MaterialLayout
.
alignFromTop
(
self
,
child
:
v
,
top
:
contentInset
.
top
+
titleLabelInset
.
top
)
}
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
titleLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
titleLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
// detail
...
...
@@ -388,15 +388,15 @@ public class ImageCardView : MaterialPulseView {
if
nil
==
imageLayer
?
.
contents
&&
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetB)"
metrics
[
"insetB"
]
=
titleLabelInset
sRef
.
bottom
+
detailLabelInsetsRef
.
top
metrics
[
"insetB"
]
=
titleLabelInset
.
bottom
+
detailLabelInset
.
top
}
else
{
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
top
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
detailLabelInset
.
top
}
verticalFormat
+=
"-[detailLabel]"
views
[
"detailLabel"
]
=
v
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
detailLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
detailLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
detailLabelInset
.
left
,
right
:
contentInset
.
right
+
detailLabelInset
.
right
)
}
// leftButtons
...
...
@@ -419,10 +419,10 @@ public class ImageCardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
sRef
.
left
+
leftButtonsInsetsRef
.
left
,
"left_right"
:
leftButtonsInsetsRef
.
left
+
leftButtonsInsetsRef
.
right
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
.
left
+
leftButtonsInset
.
left
,
"left_right"
:
leftButtonsInset
.
left
+
leftButtonsInset
.
right
],
views
:
d
))
}
}
...
...
@@ -447,10 +447,10 @@ public class ImageCardView : MaterialPulseView {
}
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
sRef
.
right
+
rightButtonsInsetsRef
.
right
,
"right_left"
:
rightButtonsInsetsRef
.
right
+
rightButtonsInsetsRef
.
left
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
.
right
+
rightButtonsInset
.
right
,
"right_left"
:
rightButtonsInset
.
right
+
rightButtonsInset
.
left
],
views
:
d
))
}
}
...
...
@@ -458,59 +458,59 @@ public class ImageCardView : MaterialPulseView {
if
0
<
leftButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
leftButtons
!
[
0
]
metrics
[
"insetC"
]
=
leftButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
leftButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
leftButtonsInset
.
bottom
}
else
if
0
<
rightButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
rightButtons
!
[
0
]
metrics
[
"insetC"
]
=
rightButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
rightButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
rightButtonsInset
.
bottom
}
if
nil
!=
detailLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
detailLabelInsetsRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
titleLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
titleLabelInsetsRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
titleLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
titleLabelInset
sRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
titleLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
metrics
[
"insetC"
]
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
contentInset
sRef
.
top
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
contentInset
.
top
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
detailLabel
{
if
0
<
leftButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
leftButtons
!
[
0
]
metrics
[
"insetC"
]
=
leftButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
leftButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
leftButtonsInset
.
bottom
}
else
if
0
<
rightButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
rightButtons
!
[
0
]
metrics
[
"insetC"
]
=
rightButtonsInset
sRef
.
top
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
metrics
[
"insetC"
]
=
rightButtonsInset
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
rightButtonsInset
.
bottom
}
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
detailLabelInsetsRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
bottom
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
{
if
0
<
leftButtons
?
.
count
{
verticalFormat
+=
"-[button]"
views
[
"button"
]
=
leftButtons
!
[
0
]
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
contentInset
sRef
.
top
+
leftButtonsInsetsRef
.
top
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
contentInset
.
top
+
leftButtonsInset
.
top
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
leftButtonsInset
.
bottom
}
else
if
0
<
rightButtons
?
.
count
{
verticalFormat
+=
"-[button]"
views
[
"button"
]
=
rightButtons
!
[
0
]
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
contentInset
sRef
.
top
+
rightButtonsInsetsRef
.
top
+
(
divider
?
dividerInsetsRef
.
top
+
dividerInsetsRef
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
contentInset
.
top
+
rightButtonsInset
.
top
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
rightButtonsInset
.
bottom
}
else
{
if
translatesAutoresizingMaskIntoConstraints
{
addConstraints
(
MaterialLayout
.
constraint
(
"V:[view(height)]"
,
options
:
[],
metrics
:
[
"height"
:
imageLayer
!.
frame
.
height
],
views
:
[
"view"
:
self
]))
...
...
@@ -558,7 +558,7 @@ public class ImageCardView : MaterialPulseView {
layer
.
addSublayer
(
dividerLayer
!
)
}
dividerLayer
?
.
backgroundColor
=
dividerColor
?
.
CGColor
dividerLayer
?
.
frame
=
CGRectMake
(
dividerInset
sRef
.
left
,
y
,
width
-
dividerInsetsRef
.
left
-
dividerInsetsRef
.
right
,
1
)
dividerLayer
?
.
frame
=
CGRectMake
(
dividerInset
.
left
,
y
,
width
-
dividerInset
.
left
-
dividerInset
.
right
,
1
)
}
/**
...
...
Sources/MaterialButton.swift
View file @
b66f37d2
...
...
@@ -276,9 +276,9 @@ public class MaterialButton : UIButton {
/**
:name: contentInsets
*/
public
var
contentInset
s
:
MaterialEdgeInsets
{
public
var
contentInset
Preset
:
MaterialEdgeInsets
{
didSet
{
let
value
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
contentInset
s
)
let
value
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
contentInset
Preset
)
contentEdgeInsets
=
UIEdgeInsetsMake
(
value
.
top
,
value
.
left
,
value
.
bottom
,
value
.
right
)
}
}
...
...
@@ -292,7 +292,7 @@ public class MaterialButton : UIButton {
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
contentInset
s
=
.
None
contentInset
Preset
=
.
None
super
.
init
(
coder
:
aDecoder
)
prepareView
()
}
...
...
@@ -308,7 +308,7 @@ public class MaterialButton : UIButton {
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
contentInset
s
=
.
None
contentInset
Preset
=
.
None
super
.
init
(
frame
:
frame
)
prepareView
()
}
...
...
@@ -318,7 +318,7 @@ public class MaterialButton : UIButton {
self
.
init
(
frame
:
CGRectNull
)
}
/// Overriding the layout callback for
layer
sublayers.
/// Overriding the layout callback for sublayers.
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
...
...
Sources/MaterialView.swift
View file @
b66f37d2
...
...
@@ -325,7 +325,7 @@ public class MaterialView : UIView {
self
.
init
(
frame
:
CGRectNull
)
}
/// Overriding the layout callback for
layer
sublayers.
/// Overriding the layout callback for sublayers.
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
...
...
Sources/NavigationBarView.swift
View file @
b66f37d2
...
...
@@ -31,16 +31,16 @@ public class NavigationBarView : MaterialView {
/**
:name: contentInsets
*/
public
var
contentInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
contentInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
contentInset
sRef
=
MaterialEdgeInsetsToValue
(
contentInsets
)
contentInset
=
MaterialEdgeInsetsToValue
(
contentInsetPreset
)
}
}
/**
:name: contentInset
sRef
:name: contentInset
*/
public
var
contentInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
public
var
contentInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
Square2
)
{
didSet
{
reloadView
()
}
...
...
@@ -49,16 +49,16 @@ public class NavigationBarView : MaterialView {
/**
:name: titleLabelInsets
*/
public
var
titleLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
titleLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
titleLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
titleLabelInsets
)
titleLabelInset
=
MaterialEdgeInsetsToValue
(
titleLabelInsetPreset
)
}
}
/**
:name: titleLabelInset
sRef
:name: titleLabelInset
*/
public
var
titleLabelInset
sRef
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
public
var
titleLabelInset
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
didSet
{
reloadView
()
}
...
...
@@ -77,16 +77,16 @@ public class NavigationBarView : MaterialView {
/**
:name: detailLabelInsets
*/
public
var
detailLabelInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
detailLabelInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
detailLabelInset
sRef
=
MaterialEdgeInsetsToValue
(
detailLabelInsets
)
detailLabelInset
=
MaterialEdgeInsetsToValue
(
detailLabelInsetPreset
)
}
}
/**
:name: detailLabelInset
sRef
:name: detailLabelInset
*/
public
var
detailLabelInset
sRef
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
public
var
detailLabelInset
:
UIEdgeInsets
=
MaterialEdgeInsetsToValue
(
.
None
)
{
didSet
{
reloadView
()
}
...
...
@@ -105,16 +105,16 @@ public class NavigationBarView : MaterialView {
/**
:name: leftButtonsInsets
*/
public
var
leftButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
leftButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
leftButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
leftButtonsInsets
)
leftButtonsInset
=
MaterialEdgeInsetsToValue
(
leftButtonsInsetPreset
)
}
}
/**
:name: leftButtonsInset
sRef
:name: leftButtonsInset
*/
public
var
leftButtonsInset
sRef
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
public
var
leftButtonsInset
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
didSet
{
reloadView
()
}
...
...
@@ -137,16 +137,16 @@ public class NavigationBarView : MaterialView {
/**
:name: rightButtonsInsets
*/
public
var
rightButtonsInset
s
:
MaterialEdgeInsets
=
.
None
{
public
var
rightButtonsInset
Preset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
rightButtonsInset
sRef
=
MaterialEdgeInsetsToValue
(
rightButtonsInsets
)
rightButtonsInset
=
MaterialEdgeInsetsToValue
(
rightButtonsInsetPreset
)
}
}
/**
:name: rightButtonsInset
sRef
:name: rightButtonsInset
*/
public
var
rightButtonsInset
sRef
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
public
var
rightButtonsInset
:
UIEdgeInsets
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
0
,
right
:
0
)
{
didSet
{
reloadView
()
}
...
...
@@ -211,10 +211,10 @@ public class NavigationBarView : MaterialView {
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
titleLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
titleLabelInset
.
top
}
else
if
nil
!=
detailLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
sRef
.
top
+
detailLabelInsetsRef
.
top
metrics
[
"insetTop"
]
=
contentInset
.
top
+
detailLabelInset
.
top
}
// title
...
...
@@ -223,21 +223,21 @@ public class NavigationBarView : MaterialView {
views
[
"titleLabel"
]
=
v
addSubview
(
v
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
titleLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
titleLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
// detail
if
let
v
=
detailLabel
{
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetB)"
metrics
[
"insetB"
]
=
titleLabelInset
sRef
.
bottom
+
detailLabelInsetsRef
.
top
metrics
[
"insetB"
]
=
titleLabelInset
.
bottom
+
detailLabelInset
.
top
}
verticalFormat
+=
"-[detailLabel]"
views
[
"detailLabel"
]
=
v
addSubview
(
v
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
sRef
.
left
+
detailLabelInsetsRef
.
left
,
right
:
contentInsetsRef
.
right
+
detailLabelInsetsRef
.
right
)
MaterialLayout
.
alignToParentHorizontally
(
self
,
child
:
v
,
left
:
contentInset
.
left
+
detailLabelInset
.
left
,
right
:
contentInset
.
right
+
detailLabelInset
.
right
)
}
// leftButtons
...
...
@@ -260,10 +260,10 @@ public class NavigationBarView : MaterialView {
h
+=
"[
\(
k
)
]"
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
leftButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
sRef
.
left
+
leftButtonsInsetsRef
.
left
,
"left_right"
:
leftButtonsInsetsRef
.
left
+
leftButtonsInsetsRef
.
right
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
.
left
+
leftButtonsInset
.
left
,
"left_right"
:
leftButtonsInset
.
left
+
leftButtonsInset
.
right
],
views
:
d
))
}
}
...
...
@@ -288,24 +288,24 @@ public class NavigationBarView : MaterialView {
}
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
sRef
.
bottom
+
rightButtonsInsetsRef
.
bottom
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
sRef
.
right
+
rightButtonsInsetsRef
.
right
,
"right_left"
:
rightButtonsInsetsRef
.
right
+
rightButtonsInsetsRef
.
left
],
views
:
d
))
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
.
right
+
rightButtonsInset
.
right
,
"right_left"
:
rightButtonsInset
.
right
+
rightButtonsInset
.
left
],
views
:
d
))
}
}
if
nil
!=
detailLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
detailLabelInsetsRef
.
bottom
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
detailLabelInset
.
bottom
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
sRef
.
bottom
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInset
.
bottom
}
}
else
if
nil
!=
titleLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
sRef
.
bottom
+
titleLabelInsetsRef
.
bottom
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
titleLabelInset
.
bottom
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
titleLabelInset
sRef
.
bottom
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
titleLabelInset
.
bottom
}
}
...
...
Sources/RaisedButton.swift
View file @
b66f37d2
...
...
@@ -32,6 +32,6 @@ public class RaisedButton : MaterialButton {
backgroundColor
=
MaterialColor
.
blue
.
accent3
depth
=
.
Depth2
cornerRadius
=
.
Radius1
contentInset
s
=
.
WideRectangle3
contentInset
Preset
=
.
WideRectangle3
}
}
\ No newline at end of file
Sources/TextField.swift
View file @
b66f37d2
...
...
@@ -24,6 +24,21 @@ public class TextField : UITextField {
/// The bottom border layer.
public
private(set)
lazy
var
bottomBorderLayer
:
CAShapeLayer
=
CAShapeLayer
()
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public
var
masksToBounds
:
Bool
{
get
{
return
layer
.
masksToBounds
}
set
(
value
)
{
layer
.
masksToBounds
=
value
}
}
/// A property that accesses the backing layer's backgroundColor.
public
override
var
backgroundColor
:
UIColor
?
{
didSet
{
...
...
@@ -63,6 +78,9 @@ public class TextField : UITextField {
}
set
(
value
)
{
layer
.
frame
.
size
.
width
=
value
if
.
None
!=
shape
{
layer
.
frame
.
size
.
height
=
value
}
}
}
...
...
@@ -78,11 +96,98 @@ public class TextField : UITextField {
}
set
(
value
)
{
layer
.
frame
.
size
.
height
=
value
if
.
None
!=
shape
{
layer
.
frame
.
size
.
width
=
value
}
}
}
/// A property that accesses the backing layer's shadowColor.
public
var
shadowColor
:
UIColor
?
{
didSet
{
layer
.
shadowColor
=
shadowColor
?
.
CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public
var
shadowOffset
:
CGSize
{
get
{
return
layer
.
shadowOffset
}
set
(
value
)
{
layer
.
shadowOffset
=
value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public
var
shadowOpacity
:
Float
{
get
{
return
layer
.
shadowOpacity
}
set
(
value
)
{
layer
.
shadowOpacity
=
value
}
}
/// A property that accesses the backing layer's shadowRadius.
public
var
shadowRadius
:
CGFloat
{
get
{
return
layer
.
shadowRadius
}
set
(
value
)
{
layer
.
shadowRadius
=
value
}
}
/**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public
var
depth
:
MaterialDepth
{
didSet
{
let
value
:
MaterialDepthType
=
MaterialDepthToValue
(
depth
)
shadowOffset
=
value
.
offset
shadowOpacity
=
value
.
opacity
shadowRadius
=
value
.
radius
}
}
/**
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
become .None, as it no longer maintains its circle shape.
*/
public
var
cornerRadius
:
MaterialRadius
{
didSet
{
if
let
v
:
MaterialRadius
=
cornerRadius
{
layer
.
cornerRadius
=
MaterialRadiusToValue
(
v
)
if
.
Circle
==
shape
{
shape
=
.
None
}
}
}
}
/**
A property that accesses the layer.borderWith using a MaterialBorder
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public
var
shape
:
MaterialShape
{
didSet
{
if
.
None
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
}
else
{
frame
.
size
.
height
=
width
}
}
}
}
/**
A property that accesses the layer.borderWith using a MaterialBorder
enum preset.
*/
public
var
borderWidth
:
MaterialBorder
{
...
...
@@ -119,36 +224,35 @@ public class TextField : UITextField {
}
/**
:name: titleLabelNormalColor
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholder text
value before being displayed.
*/
public
var
titleLabel
NormalColor
:
UIColor
?
{
public
var
titleLabel
:
UILabel
?
{
didSet
{
titleLabel
?
.
textColor
=
titleLabelNormalColor
bottomBorderLayer
.
backgroundColor
=
titleLabelNormalColor
?
.
CGColor
prepareTitleLabel
()
}
}
/**
:name: titleLabelHighlightedColor
*/
public
var
titleLabelHighlightedColor
:
UIColor
?
/// The color of the titleLabel text when the textField is not active.
public
var
titleLabelTextColor
:
UIColor
?
{
didSet
{
titleLabel
?
.
textColor
=
titleLabelTextColor
bottomBorderLayer
.
backgroundColor
=
titleLabelTextColor
?
.
CGColor
}
}
/**
:name: detailLabelHighlightedColor
*/
public
var
detailLabelHighlightedColor
:
UIColor
?
/// The color of the titleLabel text when the textField is active.
public
var
titleLabelActiveTextColor
:
UIColor
?
/**
:name:
titleLabel
:name:
detailLabelActiveTextColor
*/
public
var
titleLabel
:
UILabel
?
{
didSet
{
prepareTitleLabel
()
}
}
public
var
detailLabelActiveTextColor
:
UIColor
?
/**
:name: detailLabel
The detail UILabel that is displayed when the detailLabelHidden property
is set to false.
*/
public
var
detailLabel
:
UILabel
?
{
didSet
{
...
...
@@ -162,11 +266,11 @@ public class TextField : UITextField {
public
var
detailLabelHidden
:
Bool
=
false
{
didSet
{
if
detailLabelHidden
{
bottomBorderLayer
.
backgroundColor
=
editing
?
titleLabel
HighlightedColor
?
.
CGColor
:
titleLabelNormal
Color
?
.
CGColor
bottomBorderLayer
.
backgroundColor
=
editing
?
titleLabel
ActiveTextColor
?
.
CGColor
:
titleLabelText
Color
?
.
CGColor
hideDetailLabel
()
}
else
{
detailLabel
?
.
textColor
=
detailLabel
Highlighted
Color
bottomBorderLayer
.
backgroundColor
=
detailLabel
Highlighted
Color
?
.
CGColor
detailLabel
?
.
textColor
=
detailLabel
ActiveText
Color
bottomBorderLayer
.
backgroundColor
=
detailLabel
ActiveText
Color
?
.
CGColor
showDetailLabel
()
}
}
...
...
@@ -176,6 +280,9 @@ public class TextField : UITextField {
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
borderWidth
=
.
None
super
.
init
(
coder
:
aDecoder
)
prepareView
()
...
...
@@ -185,6 +292,9 @@ public class TextField : UITextField {
:name: init
*/
public
override
init
(
frame
:
CGRect
)
{
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
borderWidth
=
.
None
super
.
init
(
frame
:
frame
)
prepareView
()
...
...
@@ -197,21 +307,79 @@ public class TextField : UITextField {
self
.
init
(
frame
:
CGRectNull
)
}
/**
:name: layoutSublayersOfLayer
*/
/// Overriding the layout callback for sublayers.
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
bottomBorderLayer
.
frame
=
CGRectMake
(
0
,
bounds
.
height
+
8
,
bounds
.
width
,
1
)
layoutShape
()
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
public
func
animate
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
layer
.
addAnimation
(
a
,
forKey
:
nil
)
}
else
if
let
a
:
CATransition
=
animation
as?
CATransition
{
layer
.
addAnimation
(
a
,
forKey
:
kCATransition
)
}
}
/**
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStart
?(
anim
)
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
/**
:name: prepareView
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public
func
prepareView
()
{
clipsToBounds
=
false
backgroundColor
=
MaterialColor
.
white
shadowColor
=
MaterialColor
.
black
borderColor
=
MaterialColor
.
black
masksToBounds
=
false
prepareBottomBorderLayer
()
}
...
...
@@ -221,12 +389,12 @@ public class TextField : UITextField {
internal
func
textFieldDidBegin
(
textField
:
TextField
)
{
titleLabel
?
.
text
=
placeholder
if
0
==
text
?
.
utf16
.
count
{
titleLabel
?
.
textColor
=
titleLabel
Normal
Color
bottomBorderLayer
.
backgroundColor
=
titleLabel
Normal
Color
?
.
CGColor
titleLabel
?
.
textColor
=
titleLabel
Text
Color
bottomBorderLayer
.
backgroundColor
=
titleLabel
Text
Color
?
.
CGColor
detailLabelHidden
=
true
}
else
{
titleLabel
?
.
textColor
=
titleLabel
Highlighted
Color
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabel
HighlightedColor
?
.
CGColor
:
detailLabelHighlighted
Color
?
.
CGColor
titleLabel
?
.
textColor
=
titleLabel
ActiveText
Color
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabel
ActiveTextColor
?
.
CGColor
:
detailLabelActiveText
Color
?
.
CGColor
}
}
...
...
@@ -236,8 +404,8 @@ public class TextField : UITextField {
internal
func
textFieldDidChange
(
textField
:
TextField
)
{
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
titleLabel
?
.
textColor
=
titleLabel
Highlighted
Color
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabel
HighlightedColor
?
.
CGColor
:
detailLabelHighlighted
Color
?
.
CGColor
titleLabel
?
.
textColor
=
titleLabel
ActiveText
Color
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabel
ActiveTextColor
?
.
CGColor
:
detailLabelActiveText
Color
?
.
CGColor
}
else
if
0
==
text
?
.
utf16
.
count
{
hideTitleLabel
()
detailLabelHidden
=
true
...
...
@@ -253,8 +421,15 @@ public class TextField : UITextField {
}
else
if
0
==
text
?
.
utf16
.
count
{
hideTitleLabel
()
}
titleLabel
?
.
textColor
=
titleLabelNormalColor
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabelNormalColor
?
.
CGColor
:
detailLabelHighlightedColor
?
.
CGColor
titleLabel
?
.
textColor
=
titleLabelTextColor
bottomBorderLayer
.
backgroundColor
=
detailLabelHidden
?
titleLabelTextColor
?
.
CGColor
:
detailLabelActiveTextColor
?
.
CGColor
}
/// Manages the layout for the shape of the view instance.
internal
func
layoutShape
()
{
if
.
Circle
==
shape
{
layer
.
cornerRadius
=
width
/
2
}
}
/**
...
...
Sources/TextView.swift
View file @
b66f37d2
...
...
@@ -21,51 +21,228 @@ import UIKit
public
protocol
TextViewDelegate
:
UITextViewDelegate
{}
public
class
TextView
:
UITextView
{
public
var
titleLabel
:
UILabel
?
{
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public
var
masksToBounds
:
Bool
{
get
{
return
layer
.
masksToBounds
}
set
(
value
)
{
layer
.
masksToBounds
=
value
}
}
/// A property that accesses the backing layer's backgroundColor.
public
override
var
backgroundColor
:
UIColor
?
{
didSet
{
prepareTitleLabel
()
layer
.
backgroundColor
=
backgroundColor
?
.
CGColor
}
}
/// A property that accesses the layer.frame.origin.x property.
public
var
x
:
CGFloat
{
get
{
return
layer
.
frame
.
origin
.
x
}
set
(
value
)
{
layer
.
frame
.
origin
.
x
=
value
}
}
/// A property that accesses the layer.frame.origin.y property.
public
var
y
:
CGFloat
{
get
{
return
layer
.
frame
.
origin
.
y
}
set
(
value
)
{
layer
.
frame
.
origin
.
y
=
value
}
}
/**
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public
var
width
:
CGFloat
{
get
{
return
layer
.
frame
.
size
.
width
}
set
(
value
)
{
layer
.
frame
.
size
.
width
=
value
if
.
None
!=
shape
{
layer
.
frame
.
size
.
height
=
value
}
}
}
/**
:name: titleLabelNormalColor
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public
var
titleLabelNormalColor
:
UIColor
?
{
public
var
height
:
CGFloat
{
get
{
return
layer
.
frame
.
size
.
height
}
set
(
value
)
{
layer
.
frame
.
size
.
height
=
value
if
.
None
!=
shape
{
layer
.
frame
.
size
.
width
=
value
}
}
}
/// A property that accesses the backing layer's shadowColor.
public
var
shadowColor
:
UIColor
?
{
didSet
{
titleLabel
?
.
textColor
=
titleLabelNormalColor
layer
.
shadowColor
=
shadowColor
?
.
CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public
var
shadowOffset
:
CGSize
{
get
{
return
layer
.
shadowOffset
}
set
(
value
)
{
layer
.
shadowOffset
=
value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public
var
shadowOpacity
:
Float
{
get
{
return
layer
.
shadowOpacity
}
set
(
value
)
{
layer
.
shadowOpacity
=
value
}
}
/// A property that accesses the backing layer's shadowRadius.
public
var
shadowRadius
:
CGFloat
{
get
{
return
layer
.
shadowRadius
}
set
(
value
)
{
layer
.
shadowRadius
=
value
}
}
/**
:name: titleLabelHighlightedColor
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public
var
titleLabelHighlightedColor
:
UIColor
?
public
var
depth
:
MaterialDepth
{
didSet
{
let
value
:
MaterialDepthType
=
MaterialDepthToValue
(
depth
)
shadowOffset
=
value
.
offset
shadowOpacity
=
value
.
opacity
shadowRadius
=
value
.
radius
}
}
/**
:name: init
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
become .None, as it no longer maintains its circle shape.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepareView
()
public
var
cornerRadius
:
MaterialRadius
{
didSet
{
if
let
v
:
MaterialRadius
=
cornerRadius
{
layer
.
cornerRadius
=
MaterialRadiusToValue
(
v
)
if
.
Circle
==
shape
{
shape
=
.
None
}
}
}
}
/**
:name: init
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
to maintain the shape of the object.
*/
public
override
init
(
frame
:
CGRect
,
textContainer
:
NSTextContainer
?)
{
super
.
init
(
frame
:
frame
,
textContainer
:
textContainer
)
prepareView
()
public
var
shape
:
MaterialShape
{
didSet
{
if
.
None
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
}
else
{
frame
.
size
.
height
=
width
}
}
}
}
//
// :name: deinit
//
deinit
{
removeNotificationHandlers
()
/**
A property that accesses the layer.borderWith using a MaterialBorder
enum preset.
*/
public
var
borderWidth
:
MaterialBorder
{
didSet
{
layer
.
borderWidth
=
MaterialBorderToValue
(
borderWidth
)
}
}
/// A property that accesses the layer.borderColor property.
public
var
borderColor
:
UIColor
?
{
didSet
{
layer
.
borderColor
=
borderColor
?
.
CGColor
}
}
/// A property that accesses the layer.position property.
public
var
position
:
CGPoint
{
get
{
return
layer
.
position
}
set
(
value
)
{
layer
.
position
=
value
}
}
/// A property that accesses the layer.zPosition property.
public
var
zPosition
:
CGFloat
{
get
{
return
layer
.
zPosition
}
set
(
value
)
{
layer
.
zPosition
=
value
}
}
/**
:name: placeholderLabel
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholderLabel
text value before being displayed.
*/
public
var
titleLabel
:
UILabel
?
{
didSet
{
prepareTitleLabel
()
}
}
/// The color of the titleLabel text when the textView is not active.
public
var
titleLabelTextColor
:
UIColor
?
{
didSet
{
titleLabel
?
.
textColor
=
titleLabelTextColor
}
}
/// The color of the titleLabel text when the textView is active.
public
var
titleLabelActiveTextColor
:
UIColor
?
/**
:name: placeholderLabel
*/
public
var
placeholderLabel
:
UILabel
?
{
didSet
{
...
...
@@ -75,7 +252,7 @@ public class TextView: UITextView {
/**
:name: text
:name: text
*/
public
override
var
text
:
String
!
{
didSet
{
...
...
@@ -84,7 +261,7 @@ public class TextView: UITextView {
}
/**
:name: attributedText
:name: attributedText
*/
public
override
var
attributedText
:
NSAttributedString
!
{
didSet
{
...
...
@@ -93,7 +270,16 @@ public class TextView: UITextView {
}
/**
:name: textContainerInset
:name: textContainerInset
*/
public
var
textContainerInsetPreset
:
MaterialEdgeInsets
=
.
None
{
didSet
{
textContainerInset
=
MaterialEdgeInsetsToValue
(
textContainerInsetPreset
)
}
}
/**
:name: textContainerInset
*/
public
override
var
textContainerInset
:
UIEdgeInsets
{
didSet
{
...
...
@@ -101,12 +287,104 @@ public class TextView: UITextView {
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
borderWidth
=
.
None
super
.
init
(
coder
:
aDecoder
)
prepareView
()
}
/**
:name: init
*/
public
override
init
(
frame
:
CGRect
,
textContainer
:
NSTextContainer
?)
{
depth
=
.
None
shape
=
.
None
cornerRadius
=
.
None
borderWidth
=
.
None
super
.
init
(
frame
:
frame
,
textContainer
:
textContainer
)
prepareView
()
}
//
// :name: deinit
//
deinit
{
removeNotificationHandlers
()
}
/// Overriding the layout callback for subviews.
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
placeholderLabel
?
.
preferredMaxLayoutWidth
=
textContainer
.
size
.
width
-
textContainer
.
lineFragmentPadding
*
2
titleLabel
?
.
frame
.
size
.
width
=
bounds
.
width
}
/// Overriding the layout callback for sublayers.
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
layoutShape
()
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
public
func
animate
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
layer
.
addAnimation
(
a
,
forKey
:
nil
)
}
else
if
let
a
:
CATransition
=
animation
as?
CATransition
{
layer
.
addAnimation
(
a
,
forKey
:
kCATransition
)
}
}
/**
A delegation method that is executed when the backing layer starts
running an animation.
- Parameter anim: The currently running CAAnimation instance.
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStart
?(
anim
)
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
{
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
}
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
/**
:name: reloadView
*/
...
...
@@ -128,9 +406,9 @@ public class TextView: UITextView {
internal
func
handleTextViewTextDidBegin
()
{
titleLabel
?
.
text
=
placeholderLabel
?
.
text
if
0
==
text
?
.
utf16
.
count
{
titleLabel
?
.
textColor
=
titleLabel
Normal
Color
titleLabel
?
.
textColor
=
titleLabel
Text
Color
}
else
{
titleLabel
?
.
textColor
=
titleLabel
Highlighted
Color
titleLabel
?
.
textColor
=
titleLabel
ActiveText
Color
}
}
...
...
@@ -144,7 +422,7 @@ public class TextView: UITextView {
if
0
<
text
?
.
utf16
.
count
{
showTitleLabel
()
titleLabel
?
.
textColor
=
titleLabel
Highlighted
Color
titleLabel
?
.
textColor
=
titleLabel
ActiveText
Color
}
else
if
0
==
text
?
.
utf16
.
count
{
hideTitleLabel
()
}
...
...
@@ -159,16 +437,23 @@ public class TextView: UITextView {
}
else
if
0
==
text
?
.
utf16
.
count
{
hideTitleLabel
()
}
titleLabel
?
.
textColor
=
titleLabelNormalColor
titleLabel
?
.
textColor
=
titleLabelTextColor
}
/// Manages the layout for the shape of the view instance.
internal
func
layoutShape
()
{
if
.
Circle
==
shape
{
layer
.
cornerRadius
=
width
/
2
}
}
//
// :name: prepareView
//
private
func
prepareView
()
{
textContainerInset
=
UIEdgeInsets
(
top
:
24
,
left
:
0
,
bottom
:
24
,
right
:
0
)
backgroundColor
=
MaterialColor
.
clear
clip
sToBounds
=
false
textContainerInset
=
UIEdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
backgroundColor
=
MaterialColor
.
white
mask
sToBounds
=
false
removeNotificationHandlers
()
prepareNotificationHandlers
()
reloadView
()
...
...
@@ -180,7 +465,7 @@ public class TextView: UITextView {
v
.
font
=
font
v
.
textAlignment
=
textAlignment
v
.
numberOfLines
=
0
v
.
backgroundColor
=
.
clearColor
()
v
.
backgroundColor
=
MaterialColor
.
clear
titleLabel
?
.
text
=
placeholderLabel
?
.
text
addSubview
(
v
)
reloadView
()
...
...
@@ -188,9 +473,7 @@ public class TextView: UITextView {
}
}
/**
:name: prepareTitleLabel
*/
/// Prepares the titleLabel property.
private
func
prepareTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
MaterialAnimation
.
animationDisabled
{
...
...
@@ -204,9 +487,7 @@ public class TextView: UITextView {
}
}
/**
:name: showTitleLabel
*/
/// Shows and animates the titleLabel property.
private
func
showTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
v
.
frame
.
size
.
height
=
v
.
font
.
pointSize
...
...
@@ -218,9 +499,7 @@ public class TextView: UITextView {
}
}
/**
:name: hideTitleLabel
*/
/// Hides and animates the titleLabel property.
private
func
hideTitleLabel
()
{
if
let
v
:
UILabel
=
titleLabel
{
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
...
...
@@ -232,12 +511,14 @@ public class TextView: UITextView {
}
}
/// Prepares the Notification handlers.
private
func
prepareNotificationHandlers
()
{
NSNotificationCenter
.
defaultCenter
()
.
addObserver
(
self
,
selector
:
"handleTextViewTextDidBegin"
,
name
:
UITextViewTextDidBeginEditingNotification
,
object
:
nil
)
NSNotificationCenter
.
defaultCenter
()
.
addObserver
(
self
,
selector
:
"handleTextViewTextDidChange"
,
name
:
UITextViewTextDidChangeNotification
,
object
:
nil
)
NSNotificationCenter
.
defaultCenter
()
.
addObserver
(
self
,
selector
:
"handleTextViewTextDidEnd"
,
name
:
UITextViewTextDidEndEditingNotification
,
object
:
nil
)
}
/// Removes the Notification handlers.
private
func
removeNotificationHandlers
()
{
NSNotificationCenter
.
defaultCenter
()
.
removeObserver
(
self
,
name
:
UITextViewTextDidBeginEditingNotification
,
object
:
nil
)
NSNotificationCenter
.
defaultCenter
()
.
removeObserver
(
self
,
name
:
UITextViewTextDidChangeNotification
,
object
:
nil
)
...
...
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