-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable changing of pinning and layoutMargin options
- Loading branch information
Eric Hyche
committed
Aug 1, 2017
1 parent
da4ae0c
commit 1d51266
Showing
7 changed files
with
346 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+959 Bytes
(100%)
...codeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
46 changes: 46 additions & 0 deletions
46
LearnAboutStackViews/LearnAboutStackViews/Bool+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Bool+Extensions.swift | ||
// LearnAboutStackViews | ||
// | ||
// Created by Eric Hyche on 8/1/17. | ||
// Copyright © 2017 HeirPlay Software. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Bool: EHMultipleChoiceDataSource { | ||
|
||
func title() -> String { | ||
return "Boolean Selection" | ||
} | ||
|
||
func choiceCount() -> Int { | ||
return 2 | ||
} | ||
|
||
func choiceText(atIndex: Int) -> String { | ||
let indexChoice: Bool = (atIndex == 0 ? true : false) | ||
return "\(indexChoice)" | ||
} | ||
|
||
func isChoiceSelected(atIndex: Int) -> Bool { | ||
let indexChoice: Bool = (atIndex == 0 ? true : false) | ||
return self == indexChoice | ||
} | ||
|
||
func canSelectMultipleChoices() -> Bool { | ||
return false | ||
} | ||
|
||
func canSelectChoice(atIndex: Int) -> Bool { | ||
return true | ||
} | ||
|
||
mutating func setChoice(selected: Bool, atIndex: Int) { | ||
if atIndex < choiceCount() && selected { | ||
let indexChoice: Bool = (atIndex == 0 ? true : false) | ||
self = indexChoice | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
LearnAboutStackViews/LearnAboutStackViews/CGFloat+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// CGFloat+Extensions.swift | ||
// LearnAboutStackViews | ||
// | ||
// Created by Eric Hyche on 7/31/17. | ||
// Copyright © 2017 HeirPlay Software. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension CGFloat: EHMultipleChoiceDataSource { | ||
|
||
static let numberOfChoices = 25 | ||
static let choiceDelta: CGFloat = 5.0 | ||
|
||
func title() -> String { | ||
return "CGFloat Selection" | ||
} | ||
|
||
func choiceCount() -> Int { | ||
return CGFloat.numberOfChoices | ||
} | ||
|
||
func choiceText(atIndex: Int) -> String { | ||
return "\(CGFloat(atIndex) * CGFloat.choiceDelta)" | ||
} | ||
|
||
func isChoiceSelected(atIndex: Int) -> Bool { | ||
let indexValue = CGFloat(atIndex) * CGFloat.choiceDelta | ||
return indexValue == self | ||
} | ||
|
||
func canSelectMultipleChoices() -> Bool { | ||
return false | ||
} | ||
|
||
func canSelectChoice(atIndex: Int) -> Bool { | ||
return true | ||
} | ||
|
||
mutating func setChoice(selected: Bool, atIndex: Int) { | ||
if atIndex < choiceCount() && selected { | ||
let indexValue = CGFloat(atIndex) * CGFloat.choiceDelta | ||
self = indexValue | ||
} | ||
} | ||
|
||
} |
114 changes: 114 additions & 0 deletions
114
LearnAboutStackViews/LearnAboutStackViews/EHPinningOptions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// EHPinningOptions.swift | ||
// LearnAboutStackViews | ||
// | ||
// Created by Eric Hyche on 8/1/17. | ||
// Copyright © 2017 HeirPlay Software. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct EHPinningOptions: OptionSet { | ||
let rawValue: Int | ||
|
||
static let none = EHPinningOptions(rawValue: 0) | ||
static let leading = EHPinningOptions(rawValue: 1 << 0) | ||
static let centerX = EHPinningOptions(rawValue: 1 << 1) | ||
static let trailing = EHPinningOptions(rawValue: 1 << 2) | ||
static let top = EHPinningOptions(rawValue: 1 << 3) | ||
static let centerY = EHPinningOptions(rawValue: 1 << 4) | ||
static let bottom = EHPinningOptions(rawValue: 1 << 5) | ||
|
||
var textDescription: String { | ||
get { | ||
return EHPinningOptions.toString(options: self) | ||
} | ||
} | ||
|
||
static func toString(options: EHPinningOptions) -> String { | ||
var optionStrings = [String]() | ||
|
||
if options.contains(.leading) { | ||
optionStrings.append("leading") | ||
} | ||
if options.contains(.centerX) { | ||
optionStrings.append("centerX") | ||
} | ||
if options.contains(.trailing) { | ||
optionStrings.append("trailing") | ||
} | ||
if options.contains(.top) { | ||
optionStrings.append("top") | ||
} | ||
if options.contains(.centerY) { | ||
optionStrings.append("centerY") | ||
} | ||
if options.contains(.bottom) { | ||
optionStrings.append("bottom") | ||
} | ||
|
||
var desc = "" | ||
if optionStrings.isEmpty { | ||
desc = "none" | ||
} else if optionStrings.count == 1 { | ||
desc = optionStrings[0] | ||
} else { | ||
desc = "\(optionStrings)" | ||
} | ||
|
||
return desc | ||
} | ||
|
||
} | ||
|
||
extension EHPinningOptions: EHMultipleChoiceDataSource { | ||
|
||
func title() -> String { | ||
return "Pinning Options" | ||
} | ||
|
||
func choiceCount() -> Int { | ||
return 6 | ||
} | ||
|
||
func choiceText(atIndex: Int) -> String { | ||
var text = "unknown" | ||
|
||
if atIndex < choiceCount() { | ||
let option = EHPinningOptions(rawValue: (1 << atIndex)) | ||
text = option.textDescription | ||
} | ||
|
||
return text | ||
} | ||
|
||
func isChoiceSelected(atIndex: Int) -> Bool { | ||
var selected = false | ||
|
||
if atIndex < choiceCount() { | ||
selected = contains(EHPinningOptions(rawValue: (1 << atIndex))) | ||
} | ||
|
||
return selected | ||
} | ||
|
||
func canSelectMultipleChoices() -> Bool { | ||
return true | ||
} | ||
|
||
func canSelectChoice(atIndex: Int) -> Bool { | ||
return true | ||
} | ||
|
||
mutating func setChoice(selected: Bool, atIndex: Int) { | ||
if atIndex < choiceCount() { | ||
let option = EHPinningOptions(rawValue: (1 << atIndex)) | ||
if selected { | ||
insert(option) | ||
} else { | ||
remove(option) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.