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
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
155 additions
and
53 deletions
+155
-53
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
+33
-23
Sources/MaterialSwitch.swift
+15
-0
Sources/SearchBarView.swift
+78
-28
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 @@
...
@@ -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
"
>
<
!
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
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
en
<
/string
>
<
string
>
en
<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
...
@@ -33,6 +31,9 @@
...
@@ -33,6 +31,9 @@
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
/
a
rr
a
y
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
<
a
rr
a
y
>
...
@@ -41,5 +42,7 @@
...
@@ -41,5 +42,7 @@
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/plist
>
<
/plist
>
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
View file @
74fe8155
...
@@ -36,11 +36,8 @@ import UIKit
...
@@ -36,11 +36,8 @@ import UIKit
import
Material
import
Material
class
ViewController
:
UIViewController
,
MaterialSwitchDelegate
{
class
ViewController
:
UIViewController
,
MaterialSwitchDelegate
{
/// Reference for MaterialSwitch.
private
var
materialSwitch
:
MaterialSwitch
!
/// Reference for NavigationBarView.
/// Reference for NavigationBarView.
private
var
searchBarView
:
SearchBarView
=
SearchBarView
()
private
var
searchBarView
:
SearchBarView
=
SearchBarView
(
frame
:
CGRectNull
)
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
...
@@ -64,36 +61,49 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -64,36 +61,49 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
private
func
prepareSearchBarView
()
{
private
func
prepareSearchBarView
()
{
searchBarView
.
statusBarStyle
=
.
LightContent
searchBarView
.
statusBarStyle
=
.
LightContent
searchBarView
.
backgroundColor
=
MaterialColor
.
blue
.
base
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.
var
image
=
UIImage
(
named
:
"ic_close_white"
)
private
func
prepareSmallMaterialSwitch
()
{
let
clearButton
:
FlatButton
=
FlatButton
()
materialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Small
)
clearButton
.
pulseColor
=
MaterialColor
.
white
materialSwitch
.
delegate
=
self
clearButton
.
setImage
(
image
,
forState
:
.
Normal
)
clearButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
searchBarView
.
clearButton
=
clearButton
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_alarm_white"
)
image
=
UIImage
(
named
:
"ic_alarm_white"
)
let
alarmButton
:
FlatButton
=
FlatButton
()
let
alarmButton
:
FlatButton
=
FlatButton
()
alarmButton
.
pulseColor
=
MaterialColor
.
white
alarmButton
.
setImage
(
image
,
forState
:
.
Normal
)
alarmButton
.
setImage
(
image
,
forState
:
.
Normal
)
alarmButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
alarmButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
let
button
:
FlatButton
=
FlatButton
()
searchBarView
.
placeholder
=
"Search"
button
.
setTitle
(
"Back Button"
,
forState
:
.
Normal
)
searchBarView
.
tintColor
=
MaterialColor
.
white
searchBarView
.
textColor
=
MaterialColor
.
white
searchBarView
.
placeholderTextColor
=
MaterialColor
.
white
searchBarView
.
leftControls
=
[
materialSwitch
]
searchBarView
.
rightControls
=
[
alarmButton
]
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.
/// Prepares the Normal MaterialSwitch.
private
func
prepareNormalMaterialSwitch
()
{
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
.
center
=
view
.
center
materialSwitch
.
y
-=
100
materialSwitch
.
y
-=
100
materialSwitch
.
delegate
=
self
materialSwitch
.
delegate
=
self
materialSwitch
.
backgroundColor
=
MaterialColor
.
green
.
base
materialSwitch
.
backgroundColor
=
MaterialColor
.
green
.
base
view
.
addSubview
(
materialSwitch
)
view
.
addSubview
(
materialSwitch
)
materialSwitch
.
translatesAutoresizingMaskIntoConstraints
=
false
materialSwitch
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
size
(
view
,
child
:
materialSwitch
,
width
:
materialSwitch
.
width
+
100
,
height
:
materialSwitch
.
height
+
100
)
MaterialLayout
.
size
(
view
,
child
:
materialSwitch
,
width
:
materialSwitch
.
width
+
100
,
height
:
materialSwitch
.
height
+
100
)
...
@@ -103,7 +113,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -103,7 +113,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Large MaterialSwitch.
/// Prepares the Large MaterialSwitch.
private
func
prepareLargeMaterialSwitch
()
{
private
func
prepareLargeMaterialSwitch
()
{
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_alarm_white_18pt"
)
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
.
center
=
view
.
center
materialSwitch
.
y
-=
50
materialSwitch
.
y
-=
50
materialSwitch
.
delegate
=
self
materialSwitch
.
delegate
=
self
...
@@ -115,7 +125,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -115,7 +125,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Light On enabled = false MaterialSwitch.
/// Prepares the Light On enabled = false MaterialSwitch.
private
func
prepareLightOnDisabledMaterialSwitch
()
{
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
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
center
=
view
.
center
materialSwitch
.
delegate
=
self
materialSwitch
.
delegate
=
self
...
@@ -125,7 +135,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -125,7 +135,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Light Off enabled = false MaterialSwitch.
/// Prepares the Light Off enabled = false MaterialSwitch.
private
func
prepareLightOffDisabledMaterialSwitch
()
{
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
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
50
materialSwitch
.
y
+=
50
...
@@ -136,7 +146,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -136,7 +146,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Dark On enabled = false MaterialSwitch.
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOnDisabledMaterialSwitch
()
{
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
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
100
materialSwitch
.
y
+=
100
...
@@ -147,7 +157,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
...
@@ -147,7 +157,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
/// Prepares the Dark On enabled = false MaterialSwitch.
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOffDisabledMaterialSwitch
()
{
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
.
enabled
=
false
materialSwitch
.
center
=
view
.
center
materialSwitch
.
center
=
view
.
center
materialSwitch
.
y
+=
150
materialSwitch
.
y
+=
150
...
...
Sources/MaterialSwitch.swift
View file @
74fe8155
...
@@ -263,6 +263,17 @@ public class MaterialSwitch: UIControl {
...
@@ -263,6 +263,17 @@ public class MaterialSwitch: UIControl {
styleForState
(
switchState
)
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,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
it is recommended to override the prepareView method
...
@@ -468,5 +479,9 @@ public class MaterialSwitch: UIControl {
...
@@ -468,5 +479,9 @@ public class MaterialSwitch: UIControl {
button
.
frame
=
CGRectMake
(
px
,
(
height
-
buttonDiameter
)
/
2
,
buttonDiameter
,
buttonDiameter
)
button
.
frame
=
CGRectMake
(
px
,
(
height
-
buttonDiameter
)
/
2
,
buttonDiameter
,
buttonDiameter
)
onPosition
=
width
-
px
-
buttonDiameter
onPosition
=
width
-
px
-
buttonDiameter
offPosition
=
px
offPosition
=
px
if
.
On
==
switchState
{
button
.
x
=
onPosition
}
}
}
}
}
Sources/SearchBarView.swift
View file @
74fe8155
...
@@ -31,9 +31,10 @@
...
@@ -31,9 +31,10 @@
import
UIKit
import
UIKit
public
class
SearchBarView
:
MaterialView
{
public
class
SearchBarView
:
MaterialView
{
/**
/// The UITextField for the searchBar.
:name: statusBarStyle
public
private(set)
lazy
var
textField
:
TextField
=
TextField
()
*/
/// StatusBar style.
public
var
statusBarStyle
:
UIStatusBarStyle
=
UIApplication
.
sharedApplication
()
.
statusBarStyle
{
public
var
statusBarStyle
:
UIStatusBarStyle
=
UIApplication
.
sharedApplication
()
.
statusBarStyle
{
didSet
{
didSet
{
UIApplication
.
sharedApplication
()
.
statusBarStyle
=
statusBarStyle
UIApplication
.
sharedApplication
()
.
statusBarStyle
=
statusBarStyle
...
@@ -54,9 +55,6 @@ public class SearchBarView : MaterialView {
...
@@ -54,9 +55,6 @@ public class SearchBarView : MaterialView {
}
}
}
}
/// SearchBar textField.
public
private(set)
lazy
var
textField
:
TextField
=
TextField
()
/**
/**
:name: leftControls
:name: leftControls
*/
*/
...
@@ -75,6 +73,50 @@ public class SearchBarView : MaterialView {
...
@@ -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
:name: init
*/
*/
...
@@ -104,6 +146,11 @@ public class SearchBarView : MaterialView {
...
@@ -104,6 +146,11 @@ public class SearchBarView : MaterialView {
prepareProperties
(
leftControls
,
rightControls
:
rightControls
)
prepareProperties
(
leftControls
,
rightControls
:
rightControls
)
}
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
reloadView
()
}
public
override
func
didMoveToSuperview
()
{
public
override
func
didMoveToSuperview
()
{
super
.
didMoveToSuperview
()
super
.
didMoveToSuperview
()
reloadView
()
reloadView
()
...
@@ -113,66 +160,59 @@ public class SearchBarView : MaterialView {
...
@@ -113,66 +160,59 @@ public class SearchBarView : MaterialView {
:name: reloadView
:name: reloadView
*/
*/
public
func
reloadView
()
{
public
func
reloadView
()
{
layoutIfNeeded
()
// clear constraints so new ones do not conflict
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
removeConstraints
(
constraints
)
for
v
in
subviews
{
for
v
in
subviews
{
if
v
!=
textField
{
v
.
removeFromSuperview
()
v
.
removeFromSuperview
()
}
}
}
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
columns
?
grid
.
columns
:
1
)
grid
.
views
=
[]
grid
.
views
=
[]
textField
.
grid
.
columns
=
grid
.
columns
textField
.
grid
.
columns
=
grid
.
columns
// leftControls
// leftControls
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
if
0
<
v
.
count
{
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
grid
.
columns
)
for
c
in
v
{
for
c
in
v
{
var
w
:
CGFloat
=
c
.
frame
.
width
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
0
==
w
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
}
w
=
c
.
intrinsicContentSize
()
.
width
}
c
.
grid
.
columns
=
Int
(
ceil
(
w
/
g
))
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
textField
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
}
}
}
addSubview
(
textField
)
grid
.
views
?
.
append
(
textField
)
grid
.
views
?
.
append
(
textField
)
// rightControls
// rightControls
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
if
0
<
v
.
count
{
// Size of single grid column.
let
g
:
CGFloat
=
width
/
CGFloat
(
grid
.
columns
)
for
c
in
v
{
for
c
in
v
{
var
w
:
CGFloat
=
c
.
frame
.
width
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
0
==
w
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
}
w
=
c
.
intrinsicContentSize
()
.
width
}
c
.
grid
.
columns
=
Int
(
ceil
(
w
/
g
))
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
textField
.
grid
.
columns
-=
c
.
grid
.
columns
textField
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
addSubview
(
c
)
grid
.
views
?
.
append
(
c
)
grid
.
views
?
.
append
(
c
)
}
}
}
}
/// Prepare the clearButton
if
let
v
:
UIButton
=
clearButton
{
v
.
frame
=
CGRectMake
(
0
,
0
,
textField
.
height
,
textField
.
height
)
}
}
grid
.
reloadLayout
()
grid
.
reloadLayout
()
...
@@ -193,6 +233,11 @@ public class SearchBarView : MaterialView {
...
@@ -193,6 +233,11 @@ public class SearchBarView : MaterialView {
prepareTextField
()
prepareTextField
()
}
}
/// Clears the textField text.
internal
func
handleClearButton
()
{
textField
.
text
=
""
}
/**
/**
:name: prepareProperties
:name: prepareProperties
*/
*/
...
@@ -201,7 +246,12 @@ public class SearchBarView : MaterialView {
...
@@ -201,7 +246,12 @@ public class SearchBarView : MaterialView {
self
.
rightControls
=
rightControls
self
.
rightControls
=
rightControls
}
}
/// Prepares the textField.
private
func
prepareTextField
()
{
private
func
prepareTextField
()
{
textField
.
placeholder
=
"Search"
textField
.
backgroundColor
=
MaterialColor
.
clear
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