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
48b9d4e9
Commit
48b9d4e9
authored
Aug 30, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated visual format logic for BasicCard
parent
22da2736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
29 deletions
+61
-29
Source/BasicCard.swift
+57
-24
Source/MaterialCard.swift
+3
-4
Source/MaterialTheme.swift
+1
-1
No files found.
Source/BasicCard.swift
View file @
48b9d4e9
...
...
@@ -17,7 +17,6 @@
//
import
UIKit
import
QuartzCore
public
class
BasicCard
:
MaterialCard
{
//
...
...
@@ -30,51 +29,76 @@ public class BasicCard : MaterialCard {
//
internal
lazy
var
views
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
//
// :name: detailTextContainer
//
internal
var
detailTextContainer
:
UIView
?
//
// :name: buttonsContainer
//
internal
var
buttonsContainer
:
UIView
?
/**
:name: titleLabel
:name: titleLabel
*/
public
var
titleLabel
:
UILabel
?
{
didSet
{
titleLabel
!.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
titleLabel
!.
textColor
=
MaterialTheme
.
white
.
color
titleLabel
!.
font
=
Roboto
.
regularWithSize
(
2
2
)
titleLabel
!.
font
=
Roboto
.
regularWithSize
(
2
4
)
addSubview
(
titleLabel
!
)
prepareCard
()
}
}
/**
:name: detailTextLabel
:name: detailTextLabel
*/
public
var
detailTextLabel
:
UILabel
?
{
didSet
{
// container
if
nil
==
detailTextContainer
{
detailTextContainer
=
UIView
()
detailTextContainer
!.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
detailTextContainer
!.
backgroundColor
=
MaterialTheme
.
white
.
color
addSubview
(
detailTextContainer
!
)
}
// text
detailTextContainer
!.
addSubview
(
detailTextLabel
!
)
detailTextLabel
!.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
detailTextLabel
!.
textColor
=
MaterialTheme
.
white
.
color
detailTextLabel
!.
font
=
Roboto
.
lightWithSize
(
1
6
)
detailTextLabel
!.
textColor
=
MaterialTheme
.
black
.
color
detailTextLabel
!.
font
=
Roboto
.
lightWithSize
(
1
4
)
detailTextLabel
!.
numberOfLines
=
0
detailTextLabel
!.
lineBreakMode
=
.
ByWordWrapping
addSubview
(
detailTextLabel
!
)
prepareCard
()
}
}
/**
:name: divider
:name: divider
*/
public
var
divider
:
UIView
?
{
didSet
{
divider
!.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
divider
!.
backgroundColor
=
MaterialTheme
.
blueGrey
.
darken2
divider
!.
backgroundColor
=
MaterialTheme
.
blueGrey
.
lighten4
addSubview
(
divider
!
)
prepareCard
()
}
}
/**
:name: buttons
:name: buttons
*/
public
var
buttons
:
Array
<
MaterialButton
>
?
{
didSet
{
if
nil
==
buttonsContainer
{
buttonsContainer
=
UIView
()
buttonsContainer
!.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
buttonsContainer
!.
backgroundColor
=
MaterialTheme
.
white
.
color
addSubview
(
buttonsContainer
!
)
}
prepareCard
()
}
}
...
...
@@ -85,7 +109,7 @@ public class BasicCard : MaterialCard {
internal
override
func
prepareView
()
{
super
.
prepareView
()
prepareShadow
()
backgroundColor
=
MaterialTheme
.
blueGrey
.
darken1
backgroundColor
=
MaterialTheme
.
clear
.
color
}
//
...
...
@@ -103,42 +127,51 @@ public class BasicCard : MaterialCard {
// title
if
nil
!=
titleLabel
{
layoutConstraints
+=
Layout
.
constraint
(
"H:|-(16)-[titleLabel]-(16)-|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"titleLabel"
:
titleLabel
!
])
verticalFormat
+=
"-(16)-[titleLabel(2
2
)]"
verticalFormat
+=
"-(16)-[titleLabel(2
4
)]"
views
[
"titleLabel"
]
=
titleLabel
!
}
// details
if
nil
!=
detailTextLabel
{
layoutConstraints
+=
Layout
.
constraint
(
"H:|-(16)-[detailTextLabel]-(16)-|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"detailTextLabel"
:
detailTextLabel
!
])
verticalFormat
+=
"-(16)-[detailTextLabel]"
views
[
"detailTextLabel"
]
=
detailTextLabel
!
if
nil
!=
detailTextContainer
&&
nil
!=
detailTextLabel
{
// container
layoutConstraints
+=
Layout
.
constraint
(
"H:|[detailTextContainer]|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"detailTextContainer"
:
detailTextContainer
!
])
verticalFormat
+=
"[detailTextContainer]"
views
[
"detailTextContainer"
]
=
detailTextContainer
!
// text
detailTextContainer
!.
addConstraints
(
Layout
.
constraint
(
"H:|-(16)-[detailTextLabel]-(16)-|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"detailTextLabel"
:
detailTextLabel
!
]))
detailTextContainer
!.
addConstraints
(
Layout
.
constraint
(
"V:|-(16)-[detailTextLabel(<=128)]|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"detailTextLabel"
:
detailTextLabel
!
]))
}
if
nil
!=
buttons
{
if
nil
!=
buttons
&&
nil
!=
buttonsContainer
{
// divider
if
nil
!=
divider
{
layoutConstraints
+=
Layout
.
constraint
(
"H:|[divider]|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"divider"
:
divider
!
])
views
[
"divider"
]
=
divider
!
verticalFormat
+=
"
-(16)-
[divider(1)]"
verticalFormat
+=
"[divider(1)]"
}
//container
layoutConstraints
+=
Layout
.
constraint
(
"H:|[buttonsContainer]|"
,
options
:
nil
,
metrics
:
nil
,
views
:
[
"buttonsContainer"
:
buttonsContainer
!
])
verticalFormat
+=
"[buttonsContainer]"
views
[
"buttonsContainer"
]
=
buttonsContainer
!
// buttons
var
horizontalFormat
:
String
=
"H:|"
var
buttonViews
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
for
var
i
:
Int
=
0
,
l
:
Int
=
buttons
!.
count
;
i
<
l
;
++
i
{
let
button
:
MaterialButton
=
buttons
!
[
i
]
addSubview
(
button
)
buttonsContainer
!.
addSubview
(
button
)
buttonViews
[
"button
\(
i
)
"
]
=
button
views
[
"button
\(
i
)
"
]
=
button
as
AnyObject
horizontalFormat
+=
"-(8)-[button
\(
i
)
]"
layoutConstraints
+=
Layout
.
constraint
(
verticalFormat
+
"-(8)-[button
\(
i
)
]-(8)-|"
,
options
:
nil
,
metrics
:
nil
,
views
:
views
)
Layout
.
expandToParentVerticallyWithPad
(
buttonsContainer
!
,
child
:
button
,
top
:
8
,
bottom
:
8
)
buttonsContainer
!.
addConstraints
(
Layout
.
constraint
(
horizontalFormat
,
options
:
nil
,
metrics
:
nil
,
views
:
buttonViews
))
}
layoutConstraints
+=
Layout
.
constraint
(
horizontalFormat
,
options
:
nil
,
metrics
:
nil
,
views
:
buttonViews
)
}
else
{
verticalFormat
+=
"-(16)-|"
}
verticalFormat
+=
"|"
// combine constraints
if
0
<
layoutConstraints
.
count
{
layoutConstraints
+=
Layout
.
constraint
(
verticalFormat
,
options
:
nil
,
metrics
:
nil
,
views
:
views
)
...
...
Source/MaterialCard.swift
View file @
48b9d4e9
...
...
@@ -114,10 +114,9 @@ public class MaterialCard : UIView {
//
internal
func
prepareShadow
()
{
layer
.
shadowColor
=
MaterialTheme
.
black
.
color
.
CGColor
layer
.
shadowOffset
=
CGSizeMake
(
0.5
,
0.5
)
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
layer
.
cornerRadius
=
2
layer
.
shadowOffset
=
CGSizeMake
(
0.05
,
0.05
)
layer
.
shadowOpacity
=
0.1
layer
.
shadowRadius
=
3
}
//
...
...
Source/MaterialTheme.swift
View file @
48b9d4e9
...
...
@@ -21,7 +21,7 @@ import UIKit
public
struct
MaterialTheme
{
// clear
public
struct
clear
{
public
static
let
color
:
UIColor
=
white
.
color
.
colorWithAlphaComponent
(
0
)
public
static
let
color
:
UIColor
=
UIColor
.
clearColor
(
)
}
// white
...
...
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