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
9696080d
Commit
9696080d
authored
Mar 02, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduced code and drawing logic when rendering ControlViews
parent
e9d23e09
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
77 deletions
+80
-77
Examples/Programmatic/App/App/AppSearchBarViewController.swift
+1
-1
Sources/ControlView.swift
+32
-22
Sources/NavigationBarView.swift
+29
-32
Sources/NavigationBarViewController.swift
+1
-1
Sources/SearchBarView.swift
+11
-13
Sources/SearchBarViewController.swift
+2
-2
Sources/StatusBarView.swift
+3
-5
Sources/StatusBarViewController.swift
+1
-1
No files found.
Examples/Programmatic/App/App/AppSearchBarViewController.swift
View file @
9696080d
...
@@ -109,7 +109,7 @@ class AppSearchBarViewController: SearchBarViewController {
...
@@ -109,7 +109,7 @@ class AppSearchBarViewController: SearchBarViewController {
searchBarView
.
tintColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
tintColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
textColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
textColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
placeholderTextColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
placeholderTextColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
textField
.
font
=
RobotoFont
.
regular
WithSize
(
17
)
searchBarView
.
textField
.
font
=
RobotoFont
.
regular
searchBarView
.
textField
.
delegate
=
self
searchBarView
.
textField
.
delegate
=
self
searchBarView
.
clearButton
=
clearButton
searchBarView
.
clearButton
=
clearButton
...
...
Sources/ControlView.swift
View file @
9696080d
...
@@ -31,6 +31,11 @@
...
@@ -31,6 +31,11 @@
import
UIKit
import
UIKit
public
class
ControlView
:
MaterialView
{
public
class
ControlView
:
MaterialView
{
/// Will render the view.
public
var
willRenderView
:
Bool
{
return
0
<
width
}
/// A preset wrapper around contentInset.
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
get
{
...
@@ -74,14 +79,36 @@ public class ControlView : MaterialView {
...
@@ -74,14 +79,36 @@ public class ControlView : MaterialView {
/// Left side UIControls.
/// Left side UIControls.
public
var
leftControls
:
Array
<
UIControl
>
?
{
public
var
leftControls
:
Array
<
UIControl
>
?
{
didSet
{
didSet
{
reloadView
()
if
let
v
:
Array
<
UIControl
>
=
oldValue
{
for
b
in
v
{
b
.
removeFromSuperview
()
}
}
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
for
b
in
v
{
addSubview
(
b
)
}
}
layoutSubviews
()
}
}
}
}
/// Right side UIControls.
/// Right side UIControls.
public
var
rightControls
:
Array
<
UIControl
>
?
{
public
var
rightControls
:
Array
<
UIControl
>
?
{
didSet
{
didSet
{
reloadView
()
if
let
v
:
Array
<
UIControl
>
=
oldValue
{
for
b
in
v
{
b
.
removeFromSuperview
()
}
}
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
for
b
in
v
{
addSubview
(
b
)
}
}
layoutSubviews
()
}
}
}
}
...
@@ -115,24 +142,11 @@ public class ControlView : MaterialView {
...
@@ -115,24 +142,11 @@ public class ControlView : MaterialView {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
reloadView
()
if
willRenderView
{
}
public
override
func
didMoveToSuperview
()
{
super
.
didMoveToSuperview
()
reloadView
()
}
/// Reloads the view.
public
func
reloadView
()
{
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
if
0
<
width
{
// Size of single grid column.
// Size of single grid column.
if
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
axis
.
columns
?
grid
.
axis
.
columns
:
1
)
{
if
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
axis
.
columns
?
grid
.
axis
.
columns
:
1
)
{
grid
.
views
=
[]
grid
.
views
=
[]
contentView
.
grid
.
views
=
[]
contentView
.
grid
.
columns
=
grid
.
axis
.
columns
contentView
.
grid
.
columns
=
grid
.
axis
.
columns
// leftControls
// leftControls
...
@@ -145,13 +159,10 @@ public class ControlView : MaterialView {
...
@@ -145,13 +159,10 @@ public class ControlView : MaterialView {
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
}
}
addSubview
(
contentView
)
grid
.
views
?
.
append
(
contentView
)
grid
.
views
?
.
append
(
contentView
)
// rightControls
// rightControls
...
@@ -165,13 +176,11 @@ public class ControlView : MaterialView {
...
@@ -165,13 +176,11 @@ public class ControlView : MaterialView {
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
}
}
grid
.
reloadLayout
()
grid
.
reloadLayout
()
contentView
.
grid
.
reloadLayout
()
}
}
}
}
}
}
...
@@ -191,6 +200,7 @@ public class ControlView : MaterialView {
...
@@ -191,6 +200,7 @@ public class ControlView : MaterialView {
/// Prepares the contentView.
/// Prepares the contentView.
public
func
prepareContentView
()
{
public
func
prepareContentView
()
{
contentView
.
backgroundColor
=
nil
contentView
.
backgroundColor
=
nil
addSubview
(
contentView
)
}
}
/**
/**
...
...
Sources/NavigationBarView.swift
View file @
9696080d
...
@@ -42,7 +42,7 @@ public class NavigationBarView : StatusBarView {
...
@@ -42,7 +42,7 @@ public class NavigationBarView : StatusBarView {
if
let
v
:
UILabel
=
titleLabel
{
if
let
v
:
UILabel
=
titleLabel
{
contentView
.
addSubview
(
v
)
contentView
.
addSubview
(
v
)
}
}
reloadView
()
layoutSubviews
()
}
}
}
}
...
@@ -52,7 +52,7 @@ public class NavigationBarView : StatusBarView {
...
@@ -52,7 +52,7 @@ public class NavigationBarView : StatusBarView {
if
let
v
:
UILabel
=
detailLabel
{
if
let
v
:
UILabel
=
detailLabel
{
contentView
.
addSubview
(
v
)
contentView
.
addSubview
(
v
)
}
}
reloadView
()
layoutSubviews
()
}
}
}
}
...
@@ -76,49 +76,46 @@ public class NavigationBarView : StatusBarView {
...
@@ -76,49 +76,46 @@ public class NavigationBarView : StatusBarView {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
// TitleView alignment.
if
willRenderView
{
if
let
v
:
UILabel
=
titleLabel
{
if
let
d
:
UILabel
=
detailLabel
{
// TitleView alignment.
v
.
grid
.
rows
=
2
if
let
v
:
UILabel
=
titleLabel
{
v
.
font
=
v
.
font
.
fontWithSize
(
17
)
if
let
d
:
UILabel
=
detailLabel
{
d
.
grid
.
rows
=
2
v
.
grid
.
rows
=
2
d
.
font
=
d
.
font
.
fontWithSize
(
12
)
v
.
font
=
v
.
font
.
fontWithSize
(
17
)
contentView
.
grid
.
axis
.
rows
=
3
d
.
grid
.
rows
=
2
contentView
.
grid
.
spacing
=
-
8
d
.
font
=
d
.
font
.
fontWithSize
(
12
)
contentView
.
grid
.
contentInset
.
top
=
-
8
contentView
.
grid
.
axis
.
rows
=
3
}
else
{
contentView
.
grid
.
spacing
=
-
8
v
.
grid
.
rows
=
1
contentView
.
grid
.
contentInset
.
top
=
-
8
v
.
font
=
v
.
font
.
fontWithSize
(
20
)
}
else
{
contentView
.
grid
.
axis
.
rows
=
1
v
.
grid
.
rows
=
1
contentView
.
grid
.
spacing
=
0
v
.
font
=
v
.
font
.
fontWithSize
(
20
)
contentView
.
grid
.
contentInset
.
top
=
0
contentView
.
grid
.
axis
.
rows
=
1
contentView
.
grid
.
spacing
=
0
contentView
.
grid
.
contentInset
.
top
=
0
}
}
}
}
reloadView
()
}
/// Prepares the contentView.
public
override
func
prepareContentView
()
{
super
.
prepareContentView
()
contentView
.
grid
.
axis
.
direction
=
.
Vertical
}
/// Reloads the view.
public
override
func
reloadView
()
{
super
.
reloadView
()
if
0
<
width
{
contentView
.
grid
.
views
=
[]
contentView
.
grid
.
views
=
[]
if
let
v
:
UILabel
=
titleLabel
{
if
let
v
:
UILabel
=
titleLabel
{
contentView
.
grid
.
views
?
.
append
(
v
)
contentView
.
grid
.
views
?
.
append
(
v
)
}
}
if
let
v
:
UILabel
=
detailLabel
{
if
let
v
:
UILabel
=
detailLabel
{
contentView
.
grid
.
views
?
.
append
(
v
)
contentView
.
grid
.
views
?
.
append
(
v
)
}
}
contentView
.
grid
.
reloadLayout
()
contentView
.
grid
.
reloadLayout
()
}
}
}
}
/// Prepares the contentView.
public
override
func
prepareContentView
()
{
super
.
prepareContentView
()
contentView
.
grid
.
axis
.
direction
=
.
Vertical
}
/**
/**
Used to trigger property changes that initializers avoid.
Used to trigger property changes that initializers avoid.
- Parameter titleLabel: UILabel for the title.
- Parameter titleLabel: UILabel for the title.
...
...
Sources/NavigationBarViewController.swift
View file @
9696080d
...
@@ -164,7 +164,7 @@ public class NavigationBarViewController: StatusBarViewController {
...
@@ -164,7 +164,7 @@ public class NavigationBarViewController: StatusBarViewController {
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
it is recommended to override the prepareView method
to initialize property values and other setup operations.
to initialize property values and other setup operations.
The super.prepareView method should always be called
at the end
The super.prepareView method should always be called
immediately
when subclassing.
when subclassing.
*/
*/
public
override
func
prepareView
()
{
public
override
func
prepareView
()
{
...
...
Sources/SearchBarView.swift
View file @
9696080d
...
@@ -85,24 +85,22 @@ public class SearchBarView : StatusBarView {
...
@@ -85,24 +85,22 @@ public class SearchBarView : StatusBarView {
self
.
init
(
frame
:
CGRectZero
)
self
.
init
(
frame
:
CGRectZero
)
}
}
public
override
func
reloadView
()
{
public
override
func
layoutSubviews
()
{
super
.
reloadView
()
super
.
layoutSubviews
()
contentView
.
grid
.
views
=
[
textField
]
if
willRenderView
{
textField
.
reloadView
()
contentView
.
grid
.
views
?
.
append
(
textField
)
textField
.
font
=
textField
.
font
?
.
fontWithSize
(
20
)
textField
.
reloadView
()
}
}
}
/**
/// Prepares the contentView.
Prepares the view instance when intialized. When subclassing,
public
override
func
prepareContentView
()
{
it is recommended to override the prepareView method
super
.
prepareContentView
()
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public
override
func
prepareView
()
{
super
.
prepareView
()
prepareTextField
()
prepareTextField
()
}
}
/// Prepares the textField.
/// Prepares the textField.
private
func
prepareTextField
()
{
private
func
prepareTextField
()
{
textField
.
placeholder
=
"Search"
textField
.
placeholder
=
"Search"
...
...
Sources/SearchBarViewController.swift
View file @
9696080d
...
@@ -86,12 +86,12 @@ public class SearchBarViewController: StatusBarViewController {
...
@@ -86,12 +86,12 @@ public class SearchBarViewController: StatusBarViewController {
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
it is recommended to override the prepareView method
to initialize property values and other setup operations.
to initialize property values and other setup operations.
The super.prepareView method should always be called
at the end
The super.prepareView method should always be called
immediately
when subclassing.
when subclassing.
*/
*/
public
override
func
prepareView
()
{
public
override
func
prepareView
()
{
prepareSearchBarView
()
super
.
prepareView
()
super
.
prepareView
()
prepareSearchBarView
()
}
}
/// Prepares the SearchBarView.
/// Prepares the SearchBarView.
...
...
Sources/StatusBarView.swift
View file @
9696080d
...
@@ -63,15 +63,15 @@ public class StatusBarView : ControlView {
...
@@ -63,15 +63,15 @@ public class StatusBarView : ControlView {
}
}
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
// Ensures a width.
// Ensures a width.
if
1
>
width
{
if
!
willRenderView
{
width
=
MaterialDevice
.
width
width
=
MaterialDevice
.
width
}
}
grid
.
axis
.
columns
=
Int
(
width
/
48
)
grid
.
axis
.
columns
=
Int
(
width
/
48
)
super
.
layoutSubviews
()
// General alignment.
// General alignment.
if
.
iPhone
==
MaterialDevice
.
type
&&
MaterialDevice
.
landscape
{
if
.
iPhone
==
MaterialDevice
.
type
&&
MaterialDevice
.
landscape
{
grid
.
contentInset
.
top
=
8
grid
.
contentInset
.
top
=
8
...
@@ -80,8 +80,6 @@ public class StatusBarView : ControlView {
...
@@ -80,8 +80,6 @@ public class StatusBarView : ControlView {
grid
.
contentInset
.
top
=
heightForStatusBar
+
8
grid
.
contentInset
.
top
=
heightForStatusBar
+
8
height
=
heightForPortraitOrientation
height
=
heightForPortraitOrientation
}
}
reloadView
()
}
}
public
override
func
intrinsicContentSize
()
->
CGSize
{
public
override
func
intrinsicContentSize
()
->
CGSize
{
...
...
Sources/StatusBarViewController.swift
View file @
9696080d
...
@@ -109,7 +109,7 @@ public class StatusBarViewController: UIViewController {
...
@@ -109,7 +109,7 @@ public class StatusBarViewController: UIViewController {
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
it is recommended to override the prepareView method
to initialize property values and other setup operations.
to initialize property values and other setup operations.
The super.prepareView method should always be called
at the end
The super.prepareView method should always be called
immediately
when subclassing.
when subclassing.
*/
*/
public
func
prepareView
()
{
public
func
prepareView
()
{
...
...
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