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
141e5838
Unverified
Commit
141e5838
authored
Sep 22, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added Card project with latest Card component
parent
f714cc4c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
200 additions
and
578 deletions
+200
-578
Examples/Programmatic/Card/Card.xcodeproj/project.pbxproj
+0
-6
Examples/Programmatic/Card/Card/ViewController.swift
+33
-22
Material.xcodeproj/project.pbxproj
+0
-6
Sources/iOS/Card.swift
+167
-391
Sources/iOS/ContentCard.swift
+0
-153
No files found.
Examples/Programmatic/Card/Card.xcodeproj/project.pbxproj
View file @
141e5838
...
...
@@ -11,8 +11,6 @@
96B5B02B1D936DBC00449DDD
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96B5B02A1D936DBC00449DDD
/* ViewController.swift */
;
};
96B5B0301D936DBC00449DDD
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96B5B02F1D936DBC00449DDD
/* Assets.xcassets */
;
};
96B5B0331D936DBC00449DDD
/* LaunchScreen.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96B5B0311D936DBC00449DDD
/* LaunchScreen.storyboard */
;
};
96B5B03B1D937E5400449DDD
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96B5B03A1D937E5400449DDD
/* Material.framework */
;
};
96B5B03C1D937E5400449DDD
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96B5B03A1D937E5400449DDD
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -22,7 +20,6 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
96B5B03C1D937E5400449DDD
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -36,7 +33,6 @@
96B5B02F1D936DBC00449DDD
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
96B5B0321D936DBC00449DDD
/* Base */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.storyboard
;
name
=
Base
;
path
=
Base.lproj/LaunchScreen.storyboard
;
sourceTree
=
"<group>"
;
};
96B5B0341D936DBC00449DDD
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
96B5B03A1D937E5400449DDD
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
path
=
Material.framework
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -44,7 +40,6 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
96B5B03B1D937E5400449DDD
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -54,7 +49,6 @@
96B5B01C1D936DBC00449DDD
=
{
isa
=
PBXGroup
;
children
=
(
96B5B03A1D937E5400449DDD
/* Material.framework */
,
96B5B0271D936DBC00449DDD
/* Card */
,
96B5B0261D936DBC00449DDD
/* Products */
,
);
...
...
Examples/Programmatic/Card/Card/ViewController.swift
View file @
141e5838
...
...
@@ -32,44 +32,55 @@ import UIKit
import
Material
class
ViewController
:
UIViewController
{
private
var
titleBar
:
Toolbar
!
private
var
contentView
:
UILabel
!
private
var
bottomBar
:
Bar
!
private
var
favoriteButton
:
IconButton
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
view
.
backgroundColor
=
Color
.
white
view
.
backgroundColor
=
Color
.
grey
.
lighten5
prepareTitleBar
()
prepareContentView
()
prepareFavoriteButton
()
prepareBottomBar
()
prepareCard
()
}
private
func
prepareTitleBar
()
{
titleBar
=
Toolbar
()
titleBar
.
title
=
"Title"
titleBar
.
backgroundColor
=
nil
}
private
func
prepareContentView
()
{
contentView
=
UILabel
()
contentView
.
numberOfLines
=
0
contentView
.
text
=
"It’s been a while, have you read any new books lately?"
contentView
.
font
=
RobotoFont
.
regular
(
with
:
14
)
}
private
func
prepareFavoriteButton
()
{
favoriteButton
=
IconButton
(
image
:
Icon
.
favorite
,
tintColor
:
Color
.
whit
e
)
favoriteButton
.
pulseColor
=
Color
.
whit
e
favoriteButton
=
IconButton
(
image
:
Icon
.
favorite
,
tintColor
:
Color
.
blue
.
bas
e
)
favoriteButton
.
pulseColor
=
Color
.
blue
.
bas
e
}
private
func
prepareBottomBar
()
{
bottomBar
=
Bar
()
bottomBar
.
backgroundColor
=
nil
bottomBar
.
leftViews
=
[
favoriteButton
]
}
private
func
prepareCard
()
{
view
.
backgroundColor
=
Color
.
white
let
card
=
ContentCard
()
card
.
depthPreset
=
.
depth2
card
.
titleBar
=
Toolbar
()
card
.
titleBar
?
.
title
=
"Title"
card
.
titleBar
?
.
backgroundColor
=
Color
.
red
.
base
card
.
contentView
.
backgroundColor
=
Color
.
grey
.
base
card
.
contentView
.
height
=
300
card
.
bottomBar
=
Bar
()
card
.
bottomBar
?
.
backgroundColor
=
Color
.
blue
.
base
card
.
bottomBar
?
.
contentEdgeInsetsPreset
=
.
square1
card
.
bottomBar
?
.
rightViews
=
[
favoriteButton
]
let
card
=
Card
()
card
.
pulseAnimation
=
.
pointWithBacking
let
button
=
FlatButton
(
frame
:
CGRect
(
x
:
0
,
y
:
0
,
width
:
100
,
height
:
100
))
card
.
contentView
.
addSubview
(
button
)
card
.
titleBar
=
titleBar
card
.
contentView
=
contentView
card
.
bottomBar
=
bottomBar
_
=
view
.
layout
(
card
)
.
left
(
20
)
.
right
(
20
)
.
top
(
10
0
)
view
.
layout
(
card
)
.
top
(
100
)
.
left
(
20
)
.
right
(
2
0
)
}
}
Material.xcodeproj/project.pbxproj
View file @
141e5838
...
...
@@ -13,7 +13,6 @@
96264BE71D833D2800576F37
/* Reminders.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264BE61D833D2800576F37
/* Reminders.swift */
;
};
96264BE91D833D3400576F37
/* RemindersController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264BE81D833D3400576F37
/* RemindersController.swift */
;
};
96264C0E1D84051900576F37
/* Checkbox.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264C0D1D84051900576F37
/* Checkbox.swift */
;
};
96264C121D840B5F00576F37
/* ContentCard.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264C111D840B5F00576F37
/* ContentCard.swift */
;
};
9628645A1D53FE3E00690B69
/* Material+UIWindow.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
962864591D53FE3E00690B69
/* Material+UIWindow.swift */
;
};
9628645F1D540AF300690B69
/* DynamicFontType.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9628645E1D540AF300690B69
/* DynamicFontType.swift */
;
};
962864621D54111D00690B69
/* JSON.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
962864611D54111D00690B69
/* JSON.swift */
;
};
...
...
@@ -32,7 +31,6 @@
968C99471D377849000074FF
/* Offset.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
968C99461D377849000074FF
/* Offset.swift */
;
};
9697F7B71D8F22A4004741EC
/* MenuItem.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9697F7B61D8F22A4004741EC
/* MenuItem.swift */
;
};
9697F7BC1D8F2572004741EC
/* BasicAnimation.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96E3C39D1D3A1D0C0086A024
/* BasicAnimation.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9697F7BD1D8F2572004741EC
/* ContentCard.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264C111D840B5F00576F37
/* ContentCard.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9697F7BE1D8F2572004741EC
/* Checkbox.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96264C0D1D84051900576F37
/* Checkbox.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9697F7BF1D8F2572004741EC
/* Divider.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96230AB71D6A520C00AF47DC
/* Divider.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9697F7C01D8F2572004741EC
/* Material+CALayer.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96F1DC871D654FDF0025F925
/* Material+CALayer.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
...
...
@@ -225,7 +223,6 @@
96264BE61D833D2800576F37
/* Reminders.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Reminders.swift
;
sourceTree
=
"<group>"
;
};
96264BE81D833D3400576F37
/* RemindersController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
RemindersController.swift
;
sourceTree
=
"<group>"
;
};
96264C0D1D84051900576F37
/* Checkbox.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Checkbox.swift
;
sourceTree
=
"<group>"
;
};
96264C111D840B5F00576F37
/* ContentCard.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ContentCard.swift
;
sourceTree
=
"<group>"
;
};
962864591D53FE3E00690B69
/* Material+UIWindow.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"Material+UIWindow.swift"
;
sourceTree
=
"<group>"
;
};
9628645E1D540AF300690B69
/* DynamicFontType.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DynamicFontType.swift
;
sourceTree
=
"<group>"
;
};
962864611D54111D00690B69
/* JSON.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
JSON.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -630,7 +627,6 @@
96BCB8021CB40F3B00C806FE
/* Card */
=
{
isa
=
PBXGroup
;
children
=
(
96264C111D840B5F00576F37
/* ContentCard.swift */
,
96BCB75D1CB40DC500C806FE
/* Card.swift */
,
96BCB7621CB40DC500C806FE
/* ImageCard.swift */
,
);
...
...
@@ -871,7 +867,6 @@
96E3C39A1D3A1CC20086A024
/* ErrorTextField.swift in Headers */
,
96E3C39C1D3A1CC20086A024
/* Offset.swift in Headers */
,
9697F7BC1D8F2572004741EC
/* BasicAnimation.swift in Headers */
,
9697F7BD1D8F2572004741EC
/* ContentCard.swift in Headers */
,
9697F7BE1D8F2572004741EC
/* Checkbox.swift in Headers */
,
9697F7BF1D8F2572004741EC
/* Divider.swift in Headers */
,
9697F7C01D8F2572004741EC
/* Material+CALayer.swift in Headers */
,
...
...
@@ -1156,7 +1151,6 @@
96BCB7CD1CB40DC500C806FE
/* PulseView.swift in Sources */
,
96BCB7DA1CB40DC500C806FE
/* NavigationController.swift in Sources */
,
96BCB7A81CB40DC500C806FE
/* FabButton.swift in Sources */
,
96264C121D840B5F00576F37
/* ContentCard.swift in Sources */
,
96BCB7E41CB40DC500C806FE
/* Text.swift in Sources */
,
96BCB7AB1CB40DC500C806FE
/* ImageCard.swift in Sources */
,
96BCB7CB1CB40DC500C806FE
/* PulseAnimation.swift in Sources */
,
...
...
Sources/iOS/Card.swift
View file @
141e5838
...
...
@@ -31,400 +31,176 @@
import
UIKit
open
class
Card
:
PulseView
{
/**
:name: dividerLayer
*/
internal
var
dividerLayer
:
CAShapeLayer
?
/**
:name: dividerColor
*/
@IBInspectable
open
var
dividerColor
:
UIColor
?
{
didSet
{
dividerLayer
?
.
backgroundColor
=
dividerColor
?
.
cgColor
}
}
/**
:name: divider
*/
@IBInspectable
open
var
divider
=
true
{
didSet
{
reloadView
()
}
}
/**
:name: dividerInsets
*/
open
var
dividerEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
none
{
didSet
{
dividerInset
=
EdgeInsetsPresetToValue
(
preset
:
dividerEdgeInsetsPreset
)
}
}
/**
:name: dividerInset
*/
@IBInspectable
open
var
dividerInset
=
EdgeInsets
(
top
:
8
,
left
:
0
,
bottom
:
8
,
right
:
0
)
{
didSet
{
reloadView
()
}
}
/**
:name: contentInsets
*/
open
var
contentEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
square2
{
didSet
{
contentInset
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
}
}
/**
:name: contentInset
*/
@IBInspectable
open
var
contentInset
=
EdgeInsetsPresetToValue
(
preset
:
.
square2
)
{
didSet
{
reloadView
()
}
}
/**
:name: titleLabelInsets
*/
open
var
titleLabelEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
square2
{
didSet
{
titleLabelInset
=
EdgeInsetsPresetToValue
(
preset
:
titleLabelEdgeInsetsPreset
)
}
}
/**
:name: titleLabelInset
*/
@IBInspectable
open
var
titleLabelInset
=
EdgeInsetsPresetToValue
(
preset
:
.
square2
)
{
didSet
{
reloadView
()
}
}
/**
:name: titleLabel
*/
@IBInspectable
open
var
titleLabel
:
UILabel
?
{
didSet
{
reloadView
()
}
}
/// Will render the view.
open
var
willLayout
:
Bool
{
return
0
<
width
&&
nil
!=
superview
}
/// A preset wrapper around contentInset.
open
var
contentEdgeInsetsPreset
:
EdgeInsetsPreset
{
get
{
return
grid
.
contentEdgeInsetsPreset
}
set
(
value
)
{
grid
.
contentEdgeInsetsPreset
=
value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open
var
contentEdgeInsets
:
EdgeInsets
{
get
{
return
grid
.
contentEdgeInsets
}
set
(
value
)
{
grid
.
contentEdgeInsets
=
value
}
}
/// A preset wrapper around interimSpace.
open
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
didSet
{
interimSpace
=
InterimSpacePresetToValue
(
preset
:
interimSpacePreset
)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open
var
interimSpace
:
InterimSpace
{
get
{
return
grid
.
interimSpace
}
set
(
value
)
{
grid
.
interimSpace
=
value
}
}
/// A reference to the titleBar.
@IBInspectable
open
var
titleBar
:
Toolbar
?
{
didSet
{
layoutSubviews
()
}
}
/// A reference to the contentView.
@IBInspectable
open
internal(set)
lazy
var
toolbar
:
Toolbar
=
Toolbar
()
/**
:name: contentViewInsets
*/
open
var
contentViewEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
square2
{
didSet
{
contentViewInset
=
EdgeInsetsPresetToValue
(
preset
:
contentViewEdgeInsetsPreset
)
}
}
/**
:name: contentViewInset
*/
@IBInspectable
open
var
contentViewInset
=
EdgeInsetsPresetToValue
(
preset
:
.
square2
)
{
didSet
{
reloadView
()
}
}
/**
:name: contentView
*/
@IBInspectable
open
var
contentView
:
UIView
?
{
didSet
{
reloadView
()
}
}
/**
:name: leftButtonsInsets
*/
open
var
leftButtonsEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
none
{
didSet
{
leftButtonsInset
=
EdgeInsetsPresetToValue
(
preset
:
leftButtonsEdgeInsetsPreset
)
}
}
/**
:name: leftButtonsInset
*/
@IBInspectable
open
var
leftButtonsInset
=
EdgeInsets
.
zero
{
didSet
{
reloadView
()
}
}
/**
:name: leftButtons
*/
open
var
leftButtons
=
[
UIView
]()
{
didSet
{
reloadView
()
}
}
/**
:name: rightButtonsInsets
*/
open
var
rightButtonsEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
none
{
didSet
{
rightButtonsInset
=
EdgeInsetsPresetToValue
(
preset
:
rightButtonsEdgeInsetsPreset
)
}
}
/**
:name: rightButtonsInset
*/
@IBInspectable
open
var
rightButtonsInset
=
EdgeInsets
.
zero
{
didSet
{
reloadView
()
}
}
/**
:name: rightButtons
*/
open
var
rightButtons
=
[
UIView
]()
{
didSet
{
reloadView
()
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
:name: init
*/
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
}
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
}
/**
:name: init
*/
public
convenience
init
?(
image
:
UIImage
?
=
nil
,
titleLabel
:
UILabel
?
=
nil
,
contentView
:
UIView
?
=
nil
,
leftButtons
:
[
UIView
]?
=
nil
,
rightButtons
:
[
UIView
]?
=
nil
)
{
self
.
init
(
frame
:
.
zero
)
prepareProperties
(
image
:
image
,
titleLabel
:
titleLabel
,
contentView
:
contentView
,
leftButtons
:
leftButtons
,
rightButtons
:
rightButtons
)
}
/**
:name: layoutSublayersOfLayer
*/
open
override
func
layoutSublayers
(
of
layer
:
CALayer
)
{
super
.
layoutSublayers
(
of
:
layer
)
if
self
.
layer
==
layer
{
if
divider
{
var
y
:
CGFloat
=
contentInset
.
bottom
+
dividerInset
.
bottom
if
0
<
leftButtons
.
count
{
y
+=
leftButtonsInset
.
top
+
leftButtonsInset
.
bottom
+
leftButtons
[
0
]
.
frame
.
height
}
else
if
0
<
rightButtons
.
count
{
y
+=
rightButtonsInset
.
top
+
rightButtonsInset
.
bottom
+
rightButtons
[
0
]
.
frame
.
height
}
if
0
<
y
{
prepareDivider
(
y
:
bounds
.
height
-
y
-
0.5
,
width
:
bounds
.
width
)
}
}
else
{
dividerLayer
?
.
removeFromSuperlayer
()
dividerLayer
=
nil
}
}
}
/**
:name: reloadView
*/
open
func
reloadView
()
{
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
var
verticalFormat
:
String
=
"V:|"
var
views
:
Dictionary
<
String
,
Any
>
=
Dictionary
<
String
,
Any
>
()
var
metrics
:
Dictionary
<
String
,
Any
>
=
Dictionary
<
String
,
Any
>
()
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
.
top
+
titleLabelInset
.
top
}
else
if
nil
!=
contentView
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInset
.
top
+
contentViewInset
.
top
}
// title
if
let
v
:
UILabel
=
titleLabel
{
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
toolbar
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
// detail
if
let
v
:
UIView
=
contentView
{
if
nil
==
titleLabel
{
metrics
[
"insetTop"
]
=
(
metrics
[
"insetTop"
]
as!
CGFloat
)
+
contentViewInset
.
top
}
else
{
verticalFormat
+=
"-(insetB)"
metrics
[
"insetB"
]
=
titleLabelInset
.
bottom
+
contentViewInset
.
top
}
verticalFormat
+=
"-[contentView]"
views
[
"contentView"
]
=
v
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
contentViewInset
.
left
,
right
:
contentInset
.
right
+
contentViewInset
.
right
)
}
// leftButtons
if
0
<
leftButtons
.
count
{
var
h
=
"H:|"
var
d
=
Dictionary
<
String
,
Any
>
()
var
i
=
0
for
b
in
leftButtons
{
let
k
:
String
=
"b
\(
i
)
"
d
[
k
]
=
b
if
0
==
i
{
h
+=
"-(left)-"
}
else
{
h
+=
"-(left_right)-"
}
h
+=
"[
\(
k
)
]"
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
i
+=
1
}
addConstraints
(
Layout
.
constraint
(
format
:
h
,
options
:
[],
metrics
:
[
"left"
:
contentInset
.
left
+
leftButtonsInset
.
left
,
"left_right"
:
leftButtonsInset
.
left
+
leftButtonsInset
.
right
],
views
:
d
))
didSet
{
layoutSubviews
()
}
// rightButtons
if
0
<
rightButtons
.
count
{
var
h
=
"H:"
var
d
=
Dictionary
<
String
,
Any
>
()
var
i
=
rightButtons
.
count
-
1
for
b
in
rightButtons
{
let
k
:
String
=
"b
\(
i
)
"
d
[
k
]
=
b
h
+=
"[
\(
k
)
]"
if
0
==
i
{
h
+=
"-(right)-"
}
else
{
h
+=
"-(right_left)-"
}
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
i
-=
1
}
addConstraints
(
Layout
.
constraint
(
format
:
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
contentInset
.
right
+
rightButtonsInset
.
right
,
"right_left"
:
rightButtonsInset
.
right
+
rightButtonsInset
.
left
],
views
:
d
))
}
/// A reference to the bottomBar.
@IBInspectable
open
var
bottomBar
:
Bar
?
{
didSet
{
layoutSubviews
()
}
}
/**
An initializer that accepts a NSCoder.
- Parameter coder aDecoder: A NSCoder.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
An initializer that accepts a CGRect.
- Parameter frame: A CGRect.
*/
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
}
/// A convenience initializer.
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
}
/**
A convenience initiazlier.
- Parameter titleBar: An optional Toolbar.
- Parameter contentView: An optional UIView.
- Parameter bottomBar: An optional Bar.
*/
public
convenience
init
?(
titleBar
:
Toolbar
?,
contentView
:
UIView
?,
bottomBar
:
Bar
?)
{
self
.
init
(
frame
:
.
zero
)
prepareProperties
(
titleBar
:
titleBar
,
contentView
:
contentView
,
bottomBar
:
bottomBar
)
}
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
guard
willLayout
else
{
return
}
if
0
<
leftButtons
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
leftButtons
[
0
]
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
.
top
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
rightButtonsInset
.
bottom
}
if
nil
!=
contentView
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
contentViewInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
contentViewInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
}
else
if
nil
!=
titleLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInset
.
bottom
+
titleLabelInset
.
bottom
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
else
{
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
.
top
+
(
divider
?
dividerInset
.
top
+
dividerInset
.
bottom
:
0
)
}
if
0
<
views
.
count
{
verticalFormat
+=
"-(insetBottom)-|"
addConstraints
(
Layout
.
constraint
(
format
:
verticalFormat
,
options
:
[],
metrics
:
metrics
,
views
:
views
))
}
}
/**
:name: prepare
*/
open
override
func
prepare
()
{
super
.
prepare
()
depthPreset
=
.
depth1
dividerColor
=
Color
.
grey
.
lighten3
cornerRadiusPreset
=
.
cornerRadius1
}
/**
:name: prepareDivider
*/
internal
func
prepareDivider
(
y
:
CGFloat
,
width
:
CGFloat
)
{
if
nil
==
dividerLayer
{
dividerLayer
=
CAShapeLayer
()
dividerLayer
!.
zPosition
=
0
layer
.
addSublayer
(
dividerLayer
!
)
}
dividerLayer
?
.
backgroundColor
=
dividerColor
?
.
cgColor
dividerLayer
?
.
frame
=
CGRect
(
x
:
dividerInset
.
left
,
y
:
y
,
width
:
width
-
dividerInset
.
left
-
dividerInset
.
right
,
height
:
1
)
}
/**
:name: prepareProperties
*/
internal
func
prepareProperties
(
image
:
UIImage
?,
titleLabel
:
UILabel
?,
contentView
:
UIView
?,
leftButtons
:
[
UIView
]?,
rightButtons
:
[
UIView
]?)
{
self
.
image
=
image
self
.
titleLabel
=
titleLabel
self
.
contentView
=
contentView
self
.
leftButtons
=
leftButtons
??
[]
self
.
rightButtons
=
rightButtons
??
[]
}
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
var
format
=
"V:|-(insetTop)"
var
views
=
[
String
:
Any
]()
var
metrics
=
[
String
:
Any
]()
metrics
[
"insetTop"
]
=
contentEdgeInsets
.
top
metrics
[
"insetBottom"
]
=
contentEdgeInsets
.
bottom
metrics
[
"interimSpace"
]
=
interimSpace
if
let
v
=
titleBar
{
format
+=
"-[titleBar]"
views
[
"titleBar"
]
=
v
layout
(
v
)
.
horizontally
(
left
:
contentEdgeInsets
.
left
,
right
:
contentEdgeInsets
.
right
)
}
if
let
v
=
contentView
{
format
+=
"-(interimSpace)-[contentView]"
views
[
"contentView"
]
=
v
layout
(
v
)
.
horizontally
(
left
:
contentEdgeInsets
.
left
,
right
:
contentEdgeInsets
.
right
)
}
if
let
v
=
bottomBar
{
format
+=
"-(interimSpace)-[bottomBar]"
views
[
"bottomBar"
]
=
v
layout
(
v
)
.
horizontally
(
left
:
contentEdgeInsets
.
left
,
right
:
contentEdgeInsets
.
right
)
}
format
+=
"-(insetBottom)-|"
if
0
<
views
.
count
{
addConstraints
(
Layout
.
constraint
(
format
:
format
,
options
:
[],
metrics
:
metrics
,
views
:
views
))
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open
override
func
prepare
()
{
super
.
prepare
()
depthPreset
=
.
depth1
interimSpacePreset
=
.
interimSpace3
contentEdgeInsetsPreset
=
.
wideRectangle3
cornerRadiusPreset
=
.
cornerRadius1
pulseAnimation
=
.
none
}
/**
A preparation method that sets the base UI elements.
- Parameter titleBar: An optional Toolbar.
- Parameter contentView: An optional UIView.
- Parameter bottomBar: An optional Bar.
*/
internal
func
prepareProperties
(
titleBar
:
Toolbar
?,
contentView
:
UIView
?,
bottomBar
:
Bar
?)
{
self
.
titleBar
=
titleBar
self
.
contentView
=
contentView
self
.
bottomBar
=
bottomBar
}
}
Sources/iOS/ContentCard.swift
deleted
100644 → 0
View file @
f714cc4c
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
open
class
ContentCard
:
PulseView
{
/// Will render the view.
open
var
willLayout
:
Bool
{
return
0
<
width
&&
nil
!=
superview
}
/// A preset wrapper around contentInset.
open
var
contentEdgeInsetsPreset
:
EdgeInsetsPreset
{
get
{
return
grid
.
contentEdgeInsetsPreset
}
set
(
value
)
{
grid
.
contentEdgeInsetsPreset
=
value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open
var
contentEdgeInsets
:
EdgeInsets
{
get
{
return
grid
.
contentEdgeInsets
}
set
(
value
)
{
grid
.
contentEdgeInsets
=
value
}
}
/// A preset wrapper around interimSpace.
open
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
didSet
{
interimSpace
=
InterimSpacePresetToValue
(
preset
:
interimSpacePreset
)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open
var
interimSpace
:
InterimSpace
{
get
{
return
grid
.
interimSpace
}
set
(
value
)
{
grid
.
interimSpace
=
value
}
}
/// A reference to the titleBar.
open
var
titleBar
:
Toolbar
?
{
didSet
{
layoutSubviews
()
}
}
/// A reference to the contentView.
open
var
contentView
=
UIView
()
{
didSet
{
layoutSubviews
()
}
}
/// A reference to the bottomBar.
open
var
bottomBar
:
Bar
?
{
didSet
{
layoutSubviews
()
}
}
/// Grid cell factor.
@IBInspectable
open
var
gridFactor
:
CGFloat
=
24
{
didSet
{
assert
(
0
<
gridFactor
,
"[Material Error: gridFactor must be greater than 0.]"
)
layoutSubviews
()
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open
override
func
prepare
()
{
super
.
prepare
()
pulseAnimation
=
.
none
}
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
guard
willLayout
else
{
return
}
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
var
views
=
[
String
:
Any
]()
var
format
=
"V:|"
if
let
v
=
titleBar
{
views
[
"titleBar"
]
=
v
format
+=
"[titleBar]"
layout
(
v
)
.
horizontally
()
}
views
[
"contentView"
]
=
contentView
format
+=
"[contentView]"
layout
(
contentView
)
.
horizontally
()
// if let v = bottomBar {
// views["bottomBar"] = v
// format += "[bottomBar]"
// layout(v).horizontally()
// }
addConstraints
(
Layout
.
constraint
(
format
:
"
\(
format
)
|"
,
options
:
[],
metrics
:
nil
,
views
:
views
))
}
}
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