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
74fe8155
Commit
74fe8155
authored
Feb 14, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working SearchBarView
parent
787a893d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
70 deletions
+172
-70
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/Contents.json
+24
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white_2x.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white_3x.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Info.plist
+5
-2
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
+34
-24
Sources/MaterialSwitch.swift
+15
-0
Sources/SearchBarView.swift
+94
-44
No files found.
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/Contents.json
0 → 100644
View file @
74fe8155
{
"images"
:
[
{
"idiom"
:
"universal"
,
"filename"
:
"ic_close_white.png"
,
"scale"
:
"1x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_close_white_2x.png"
,
"scale"
:
"2x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_close_white_3x.png"
,
"scale"
:
"3x"
}
],
"info"
:
{
"version"
:
1
,
"author"
:
"xcode"
}
}
\ No newline at end of file
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white.png
0 → 100644
View file @
74fe8155
175 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white_2x.png
0 → 100644
View file @
74fe8155
257 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_close_white.imageset/ic_close_white_3x.png
0 → 100644
View file @
74fe8155
347 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Info.plist
View file @
74fe8155
...
...
@@ -2,8 +2,6 @@
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
en
<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
...
...
@@ -33,6 +31,9 @@
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
...
...
@@ -41,5 +42,7 @@
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
/
d
i
c
t
>
<
/plist
>
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
View file @
74fe8155
...
...
@@ -36,11 +36,8 @@ import UIKit
import
Material
class
ViewController
:
UIViewController
,
MaterialSwitchDelegate
{
/// Reference for MaterialSwitch.
private
var
materialSwitch
:
MaterialSwitch
!
/// Reference for NavigationBarView.
private
var
searchBarView
:
SearchBarView
=
SearchBarView
()
private
var
searchBarView
:
SearchBarView
=
SearchBarView
(
frame
:
CGRectNull
)
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -64,36 +61,49 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
private
func
prepareSearchBarView
()
{
searchBarView
.
statusBarStyle
=
.
LightContent
searchBarView
.
backgroundColor
=
MaterialColor
.
blue
.
base
searchBarView
.
textField
.
attributedPlaceholder
=
NSAttributedString
(
string
:
"Search"
,
attributes
:
[
NSForegroundColorAttributeName
:
MaterialColor
.
white
])
searchBarView
.
textField
.
clearButtonMode
=
.
WhileEditing
searchBarView
.
textField
.
tintColor
=
MaterialColor
.
white
view
.
addSubview
(
searchBarView
)
}
/// Prepares the Small MaterialSwitch.
private
func
prepareSmallMaterialSwitch
()
{
materialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Small
)
materialSwitch
.
delegate
=
self
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_alarm_white"
)
var
image
=
UIImage
(
named
:
"ic_close_white"
)
let
clearButton
:
FlatButton
=
FlatButton
()
clearButton
.
pulseColor
=
MaterialColor
.
white
clearButton
.
setImage
(
image
,
forState
:
.
Normal
)
clearButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
searchBarView
.
clearButton
=
clearButton
image
=
UIImage
(
named
:
"ic_alarm_white"
)
let
alarmButton
:
FlatButton
=
FlatButton
()
alarmButton
.
pulseColor
=
MaterialColor
.
white
alarmButton
.
setImage
(
image
,
forState
:
.
Normal
)
alarmButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
let
button
:
FlatButton
=
FlatButton
()
button
.
setTitle
(
"Back Button"
,
forState
:
.
Normal
)
searchBarView
.
placeholder
=
"Search"
searchBarView
.
tintColor
=
MaterialColor
.
white
searchBarView
.
textColor
=
MaterialColor
.
white
searchBarView
.
placeholderTextColor
=
MaterialColor
.
white
searchBarView
.
leftControls
=
[
materialSwitch
]
searchBarView
.
rightControls
=
[
alarmButton
]
view
.
addSubview
(
searchBarView
)
searchBarView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
height
(
view
,
child
:
searchBarView
,
height
:
70
)
MaterialLayout
.
alignFromTop
(
view
,
child
:
searchBarView
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
searchBarView
)
}
/// Prepares the Small MaterialSwitch.
private
func
prepareSmallMaterialSwitch
()
{
let
materialSwitch
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Small
)
materialSwitch
.
delegate
=
self
searchBarView
.
leftControls
=
[
materialSwitch
]
}
/// Prepares the Normal MaterialSwitch.
private
func
prepareNormalMaterialSwitch
()
{
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
,
size
:
.
Normal
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
,
size
:
.
Normal
)
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
-=
100
materialSwitch
.
delegate
=
self
materialSwitch
.
backgroundColor
=
MaterialColor
.
green
.
base
view
.
addSubview
(
materialSwitch
)
materialSwitch
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
size
(
view
,
child
:
materialSwitch
,
width
:
materialSwitch
.
width
+
100
,
height
:
materialSwitch
.
height
+
100
)
...
...
@@ -103,7 +113,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Large MaterialSwitch.
private
func
prepareLargeMaterialSwitch
()
{
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_alarm_white_18pt"
)
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Large
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Large
)
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
-=
50
materialSwitch
.
delegate
=
self
...
...
@@ -115,7 +125,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Light On enabled = false MaterialSwitch.
private
func
prepareLightOnDisabledMaterialSwitch
()
{
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
,
size
:
.
Normal
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
,
size
:
.
Normal
)
materialSwitch
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
delegate
=
self
...
...
@@ -125,7 +135,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Light Off enabled = false MaterialSwitch.
private
func
prepareLightOffDisabledMaterialSwitch
()
{
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Normal
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Normal
)
materialSwitch
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
50
...
...
@@ -136,7 +146,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOnDisabledMaterialSwitch
()
{
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Dark
,
size
:
.
Normal
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Dark
,
size
:
.
Normal
)
materialSwitch
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
100
...
...
@@ -147,7 +157,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOffDisabledMaterialSwitch
()
{
m
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Dark
,
size
:
.
Normal
)
let
materialSwitch
:
M
aterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Dark
,
size
:
.
Normal
)
materialSwitch
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
150
...
...
Sources/MaterialSwitch.swift
View file @
74fe8155
...
...
@@ -263,6 +263,17 @@ public class MaterialSwitch: UIControl {
styleForState
(
switchState
)
}
public
override
func
intrinsicContentSize
()
->
CGSize
{
switch
switchSize
{
case
.
Small
:
return
CGSizeMake
(
30
,
25
)
case
.
Normal
:
return
CGSizeMake
(
40
,
30
)
case
.
Large
:
return
CGSizeMake
(
50
,
40
)
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
...
...
@@ -468,5 +479,9 @@ public class MaterialSwitch: UIControl {
button
.
frame
=
CGRectMake
(
px
,
(
height
-
buttonDiameter
)
/
2
,
buttonDiameter
,
buttonDiameter
)
onPosition
=
width
-
px
-
buttonDiameter
offPosition
=
px
if
.
On
==
switchState
{
button
.
x
=
onPosition
}
}
}
Sources/SearchBarView.swift
View file @
74fe8155
...
...
@@ -31,9 +31,10 @@
import
UIKit
public
class
SearchBarView
:
MaterialView
{
/**
:name: statusBarStyle
*/
/// The UITextField for the searchBar.
public
private(set)
lazy
var
textField
:
TextField
=
TextField
()
/// StatusBar style.
public
var
statusBarStyle
:
UIStatusBarStyle
=
UIApplication
.
sharedApplication
()
.
statusBarStyle
{
didSet
{
UIApplication
.
sharedApplication
()
.
statusBarStyle
=
statusBarStyle
...
...
@@ -54,9 +55,6 @@ public class SearchBarView : MaterialView {
}
}
/// SearchBar textField.
public
private(set)
lazy
var
textField
:
TextField
=
TextField
()
/**
:name: leftControls
*/
...
...
@@ -75,6 +73,50 @@ public class SearchBarView : MaterialView {
}
}
/// The UIImage for the clear icon.
public
var
clearButton
:
UIButton
?
{
didSet
{
if
let
v
:
UIButton
=
clearButton
{
v
.
contentEdgeInsets
=
UIEdgeInsetsZero
v
.
addTarget
(
self
,
action
:
"handleClearButton"
,
forControlEvents
:
.
TouchUpInside
)
}
textField
.
rightView
=
clearButton
}
}
/// TintColor for searchBar.
public
override
var
tintColor
:
UIColor
?
{
didSet
{
textField
.
tintColor
=
tintColor
}
}
/// TextColor for searchBar.
public
var
textColor
:
UIColor
?
{
didSet
{
textField
.
textColor
=
textColor
}
}
/// Placeholder textColor.
public
var
placeholderTextColor
:
UIColor
?
{
didSet
{
if
let
v
:
String
=
textField
.
placeholder
{
textField
.
attributedPlaceholder
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
MaterialColor
.
white
])
}
}
}
/// A wrapper for searchBar.placeholder.
public
var
placeholder
:
String
?
{
didSet
{
textField
.
placeholder
=
placeholder
if
let
v
:
String
=
textField
.
placeholder
{
textField
.
attributedPlaceholder
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
MaterialColor
.
white
])
}
}
}
/**
:name: init
*/
...
...
@@ -104,6 +146,11 @@ public class SearchBarView : MaterialView {
prepareProperties
(
leftControls
,
rightControls
:
rightControls
)
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
reloadView
()
}
public
override
func
didMoveToSuperview
()
{
super
.
didMoveToSuperview
()
reloadView
()
...
...
@@ -113,68 +160,61 @@ public class SearchBarView : MaterialView {
:name: reloadView
*/
public
func
reloadView
()
{
layoutIfNeeded
()
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
if
v
!=
textField
{
v
.
removeFromSuperview
()
}
}
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
columns
?
grid
.
columns
:
1
)
grid
.
views
=
[]
textField
.
grid
.
columns
=
grid
.
columns
// leftControls
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
if
0
<
v
.
count
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
grid
.
columns
)
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
for
c
in
v
{
var
w
:
CGFloat
=
c
.
frame
.
width
if
0
==
w
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
w
=
c
.
intrinsicContentSize
()
.
width
}
c
.
grid
.
columns
=
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
addSubview
(
textField
)
grid
.
views
?
.
append
(
textField
)
// rightControls
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
if
0
<
v
.
count
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
grid
.
columns
)
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
for
c
in
v
{
var
w
:
CGFloat
=
c
.
frame
.
width
if
0
==
w
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
w
=
c
.
intrinsicContentSize
()
.
width
}
c
.
grid
.
columns
=
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
/// Prepare the clearButton
if
let
v
:
UIButton
=
clearButton
{
v
.
frame
=
CGRectMake
(
0
,
0
,
textField
.
height
,
textField
.
height
)
}
grid
.
reloadLayout
()
}
...
...
@@ -193,6 +233,11 @@ public class SearchBarView : MaterialView {
prepareTextField
()
}
/// Clears the textField text.
internal
func
handleClearButton
()
{
textField
.
text
=
""
}
/**
:name: prepareProperties
*/
...
...
@@ -201,7 +246,12 @@ public class SearchBarView : MaterialView {
self
.
rightControls
=
rightControls
}
/// Prepares the textField.
private
func
prepareTextField
()
{
textField
.
placeholder
=
"Search"
textField
.
backgroundColor
=
MaterialColor
.
clear
textField
.
clearButtonMode
=
.
Never
textField
.
rightViewMode
=
.
WhileEditing
addSubview
(
textField
)
}
}
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