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
b8b1b899
Commit
b8b1b899
authored
Dec 25, 2017
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added documentation for Radio/Check things
parent
edfe8046
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
2 deletions
+65
-2
Sources/iOS/BaseButtonGroup.swift
+7
-0
Sources/iOS/BaseIconLayerButton.swift
+24
-2
Sources/iOS/CheckButton.swift
+1
-0
Sources/iOS/CheckButtonGroup.swift
+16
-0
Sources/iOS/RadioButtonGroup.swift
+17
-0
No files found.
Sources/iOS/BaseButtonGroup.swift
View file @
b8b1b899
...
...
@@ -6,7 +6,11 @@
// Copyright © 2017 CosmicMind, Inc. All rights reserved.
//
import
UIKit
open
class
BaseButtonGroup
<
T
:
Button
>
:
View
{
/// Holds reference to buttons within the group.
open
var
buttons
:
[
T
]
=
[]
{
didSet
{
oldValue
.
forEach
{
...
...
@@ -19,6 +23,9 @@ open class BaseButtonGroup<T: Button>: View {
}
}
/// Initializes group with the provided buttons.
///
/// - Parameter buttons: Array of buttons.
public
convenience
init
(
buttons
:
[
T
])
{
self
.
init
(
frame
:
.
zero
)
defer
{
self
.
buttons
=
buttons
}
// defer allows didSet to be called
...
...
Sources/iOS/BaseIconLayerButton.swift
View file @
b8b1b899
...
...
@@ -14,18 +14,28 @@ open class BaseIconLayerButton: Button {
class
var
iconLayer
:
BaseIconLayer
{
fatalError
(
"Has to be implemented by subclasses"
)
}
lazy
var
iconLayer
:
BaseIconLayer
=
{
return
type
(
of
:
self
)
.
iconLayer
}()
/// A Boolean value indicating whether the button is in the selected state
///
/// Use `setSelected(_:, animated:)` if the state change needs to be animated
open
override
var
isSelected
:
Bool
{
didSet
{
iconLayer
.
setSelected
(
isSelected
,
animated
:
false
)
}
}
/// A Boolean value indicating whether the control is enabled.
open
override
var
isEnabled
:
Bool
{
didSet
{
iconLayer
.
isEnabled
=
isEnabled
}
}
/// Sets the color of the icon to use for the specified state.
///
/// - Parameters:
/// - color: The color of the icon to use for the specified state.
/// - state: The state that uses the specified color. Supports only (.normal, .selected, .disabled)
open
func
setIconColor
(
_
color
:
UIColor
,
for
state
:
UIControlState
)
{
switch
state
{
case
.
normal
:
...
...
@@ -38,7 +48,11 @@ open class BaseIconLayerButton: Button {
fatalError
(
"unsupported state"
)
}
}
/// Returns the icon color used for a state.
///
/// - Parameter state: The state that uses the icon color. Supports only (.normal, .selected, .disabled)
/// - Returns: The color of the title for the specified state.
open
func
iconColor
(
for
state
:
UIControlState
)
->
UIColor
{
switch
state
{
case
.
normal
:
...
...
@@ -52,7 +66,15 @@ open class BaseIconLayerButton: Button {
}
}
/// A Boolean value indicating whether the button is being animated
open
var
isAnimating
:
Bool
{
return
iconLayer
.
isAnimating
}
/// Sets the `selected` state of the button, optionally animating the transition.
///
/// - Parameters:
/// - isSelected: A Boolean value indicating new `selected` state
/// - animated: true if the state change should be animated, otherwise false.
open
func
setSelected
(
_
isSelected
:
Bool
,
animated
:
Bool
)
{
guard
!
isAnimating
else
{
return
}
iconLayer
.
setSelected
(
isSelected
,
animated
:
animated
)
...
...
@@ -99,7 +121,7 @@ open class BaseIconLayerButton: Button {
visualLayer
.
frame
.
center
=
iconLayer
.
frame
.
center
visualLayer
.
cornerRadius
=
s
/
2
}
private
let
margin
:
CGFloat
=
5
private
let
iconSize
:
CGFloat
=
16
}
...
...
Sources/iOS/CheckButton.swift
View file @
b8b1b899
...
...
@@ -11,6 +11,7 @@ import UIKit
open
class
CheckButton
:
BaseIconLayerButton
{
class
override
var
iconLayer
:
BaseIconLayer
{
return
CheckBoxLayer
()
}
/// Color of the checkmark (✓)
open
var
checkmarkColor
:
UIColor
{
get
{
return
(
iconLayer
as!
CheckBoxLayer
)
.
checkmarkColor
...
...
Sources/iOS/CheckButtonGroup.swift
View file @
b8b1b899
...
...
@@ -6,16 +6,32 @@
// Copyright © 2017 CosmicMind, Inc. All rights reserved.
//
/// Lays out provided check buttons within itself.
///
/// Unlike RadioButtonGroup, checking one check button that belongs to a check group *does not* unchecks any previously checked
/// check button within the same group. Intially, all of the check buttons are unchecked.
///
/// The buttons are layout out by `Grid` system, so that changing properites of grid instance
/// (e.g interimSpace) are reflected.
open
class
CheckButtonGroup
:
BaseButtonGroup
<
CheckButton
>
{
/// Initializes CheckButtonGroup with an array of check buttons each having
/// title equal to corresponding string in the `titles` parameter.
///
/// - Parameter titles: An array of title strings
public
convenience
init
(
titles
:
[
String
])
{
let
buttons
=
titles
.
map
{
CheckButton
(
title
:
$0
)
}
self
.
init
(
buttons
:
buttons
)
}
/// Returns all selected check buttons within the group
/// or empty array if none is seleceted.
open
var
selecetedButtons
:
[
CheckButton
]
{
return
buttons
.
filter
{
$0
.
isSelected
}
}
/// Returns indexes of all selected check buttons within the group
/// or empty array if none is seleceted.
open
var
selectedIndices
:
[
Int
]
{
return
selecetedButtons
.
map
{
buttons
.
index
(
of
:
$0
)
!
}
}
...
...
Sources/iOS/RadioButtonGroup.swift
View file @
b8b1b899
...
...
@@ -6,16 +6,33 @@
// Copyright © 2017 CosmicMind, Inc. All rights reserved.
//
/// Lays out provided radio buttons within itself.
///
/// Checking one radio button that belongs to a radio group unchecks any previously checked
/// radio button within the same group. Intially, all of the radio buttons are unchecked.
///
/// The buttons are layout out by `Grid` system, so that changing properites of grid instance
/// (e.g interimSpace) are reflected.
open
class
RadioButtonGroup
:
BaseButtonGroup
<
RadioButton
>
{
/// Initializes RadioButtonGroup with an array of radio buttons each having
/// title equal to corresponding string in the `titles` parameter.
///
/// - Parameter titles: An array of title strings.
public
convenience
init
(
titles
:
[
String
])
{
let
buttons
=
titles
.
map
{
RadioButton
(
title
:
$0
)
}
self
.
init
(
buttons
:
buttons
)
}
/// Returns selected radio button within the group.
/// If none is selected (e.g in initial state), nil is returned.
open
var
selectedButton
:
RadioButton
?
{
return
buttons
.
first
{
$0
.
isSelected
}
}
/// Returns index of selected radio button within the group.
/// If none is selected (e.g in initial state), -1 is returned.
open
var
selectedIndex
:
Int
{
guard
let
b
=
selectedButton
else
{
return
-
1
}
return
buttons
.
index
(
of
:
b
)
!
...
...
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