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
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
59 deletions
+62
-59
Examples/Programmatic/App/App/AppSearchBarViewController.swift
+1
-1
Sources/ControlView.swift
+32
-22
Sources/NavigationBarView.swift
+12
-15
Sources/NavigationBarViewController.swift
+1
-1
Sources/SearchBarView.swift
+10
-12
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 {
searchBarView
.
tintColor
=
MaterialColor
.
grey
.
darken4
searchBarView
.
textColor
=
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
.
clearButton
=
clearButton
...
...
Sources/ControlView.swift
View file @
9696080d
...
...
@@ -31,6 +31,11 @@
import
UIKit
public
class
ControlView
:
MaterialView
{
/// Will render the view.
public
var
willRenderView
:
Bool
{
return
0
<
width
}
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
...
...
@@ -74,14 +79,36 @@ public class ControlView : MaterialView {
/// Left side UIControls.
public
var
leftControls
:
Array
<
UIControl
>
?
{
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.
public
var
rightControls
:
Array
<
UIControl
>
?
{
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 {
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
reloadView
()
}
public
override
func
didMoveToSuperview
()
{
super
.
didMoveToSuperview
()
reloadView
()
}
/// Reloads the view.
public
func
reloadView
()
{
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
if
0
<
width
{
if
willRenderView
{
// Size of single grid column.
if
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
axis
.
columns
?
grid
.
axis
.
columns
:
1
)
{
grid
.
views
=
[]
contentView
.
grid
.
views
=
[]
contentView
.
grid
.
columns
=
grid
.
axis
.
columns
// leftControls
...
...
@@ -145,13 +159,10 @@ public class ControlView : MaterialView {
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
addSubview
(
contentView
)
grid
.
views
?
.
append
(
contentView
)
// rightControls
...
...
@@ -165,13 +176,11 @@ public class ControlView : MaterialView {
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
grid
.
reloadLayout
()
contentView
.
grid
.
reloadLayout
()
}
}
}
...
...
@@ -191,6 +200,7 @@ public class ControlView : MaterialView {
/// Prepares the contentView.
public
func
prepareContentView
()
{
contentView
.
backgroundColor
=
nil
addSubview
(
contentView
)
}
/**
...
...
Sources/NavigationBarView.swift
View file @
9696080d
...
...
@@ -42,7 +42,7 @@ public class NavigationBarView : StatusBarView {
if
let
v
:
UILabel
=
titleLabel
{
contentView
.
addSubview
(
v
)
}
reloadView
()
layoutSubviews
()
}
}
...
...
@@ -52,7 +52,7 @@ public class NavigationBarView : StatusBarView {
if
let
v
:
UILabel
=
detailLabel
{
contentView
.
addSubview
(
v
)
}
reloadView
()
layoutSubviews
()
}
}
...
...
@@ -76,6 +76,8 @@ public class NavigationBarView : StatusBarView {
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
willRenderView
{
// TitleView alignment.
if
let
v
:
UILabel
=
titleLabel
{
if
let
d
:
UILabel
=
detailLabel
{
...
...
@@ -95,30 +97,25 @@ public class NavigationBarView : StatusBarView {
}
}
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
=
[]
if
let
v
:
UILabel
=
titleLabel
{
contentView
.
grid
.
views
?
.
append
(
v
)
}
if
let
v
:
UILabel
=
detailLabel
{
contentView
.
grid
.
views
?
.
append
(
v
)
}
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.
- Parameter titleLabel: UILabel for the title.
...
...
Sources/NavigationBarViewController.swift
View file @
9696080d
...
...
@@ -164,7 +164,7 @@ public class NavigationBarViewController: StatusBarViewController {
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
at the end
The super.prepareView method should always be called
immediately
when subclassing.
*/
public
override
func
prepareView
()
{
...
...
Sources/SearchBarView.swift
View file @
9696080d
...
...
@@ -85,24 +85,22 @@ public class SearchBarView : StatusBarView {
self
.
init
(
frame
:
CGRectZero
)
}
public
override
func
reloadView
()
{
super
.
reloadView
()
contentView
.
grid
.
views
=
[
textField
]
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
willRenderView
{
contentView
.
grid
.
views
?
.
append
(
textField
)
textField
.
font
=
textField
.
font
?
.
fontWithSize
(
20
)
textField
.
reloadView
()
}
}
/**
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
override
func
prepareView
()
{
super
.
prepareView
()
/// Prepares the contentView.
public
override
func
prepareContentView
()
{
super
.
prepareContentView
()
prepareTextField
()
}
/// Prepares the textField.
private
func
prepareTextField
()
{
textField
.
placeholder
=
"Search"
...
...
Sources/SearchBarViewController.swift
View file @
9696080d
...
...
@@ -86,12 +86,12 @@ public class SearchBarViewController: StatusBarViewController {
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
at the end
The super.prepareView method should always be called
immediately
when subclassing.
*/
public
override
func
prepareView
()
{
prepareSearchBarView
()
super
.
prepareView
()
prepareSearchBarView
()
}
/// Prepares the SearchBarView.
...
...
Sources/StatusBarView.swift
View file @
9696080d
...
...
@@ -63,15 +63,15 @@ public class StatusBarView : ControlView {
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
// Ensures a width.
if
1
>
width
{
if
!
willRenderView
{
width
=
MaterialDevice
.
width
}
grid
.
axis
.
columns
=
Int
(
width
/
48
)
super
.
layoutSubviews
()
// General alignment.
if
.
iPhone
==
MaterialDevice
.
type
&&
MaterialDevice
.
landscape
{
grid
.
contentInset
.
top
=
8
...
...
@@ -80,8 +80,6 @@ public class StatusBarView : ControlView {
grid
.
contentInset
.
top
=
heightForStatusBar
+
8
height
=
heightForPortraitOrientation
}
reloadView
()
}
public
override
func
intrinsicContentSize
()
->
CGSize
{
...
...
Sources/StatusBarViewController.swift
View file @
9696080d
...
...
@@ -109,7 +109,7 @@ public class StatusBarViewController: UIViewController {
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
at the end
The super.prepareView method should always be called
immediately
when subclassing.
*/
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