Skip to content

Commit 194ae42

Browse files
committed
Reorder type buttons and highlight the currently selected one.
1 parent 753e8ec commit 194ae42

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

Example/Source/Base.lproj/Main.storyboard

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,23 @@
106106
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AIo-Bv-jmO" userLabel="Linear">
107107
<rect key="frame" x="0.0" y="134" width="203" height="30"/>
108108
<color key="backgroundColor" red="0.9165864587" green="0.89184486870000002" blue="0.27463445069999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
109-
<state key="normal" title="Linear">
109+
<state key="normal" title="Logarithmic">
110110
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
111111
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
112112
</state>
113113
<connections>
114-
<action selector="doLinear" destination="GzX-4u-840" eventType="touchUpInside" id="Dfw-LG-KKA"/>
114+
<action selector="doLogarithmic" destination="GzX-4u-840" eventType="touchUpInside" id="2Ev-Xe-X0A"/>
115115
</connections>
116116
</button>
117117
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="t25-dP-LU3" userLabel="Logarithmic">
118118
<rect key="frame" x="211" y="134" width="203" height="30"/>
119119
<color key="backgroundColor" red="0.9165864587" green="0.89184486870000002" blue="0.27463445069999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
120-
<state key="normal" title="Logarithmic">
120+
<state key="normal" title="Linear">
121121
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
122122
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
123123
</state>
124124
<connections>
125-
<action selector="doLogarithmic" destination="GzX-4u-840" eventType="touchUpInside" id="8C2-de-x46"/>
125+
<action selector="doLinear" destination="GzX-4u-840" eventType="touchUpInside" id="t8d-KS-hFP"/>
126126
</connections>
127127
</button>
128128
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="C2Y-UB-xTc">
@@ -186,6 +186,8 @@
186186
</constraints>
187187
</view>
188188
<connections>
189+
<outlet property="linearButton" destination="t25-dP-LU3" id="A6s-ss-HvR"/>
190+
<outlet property="logarithmicButton" destination="AIo-Bv-jmO" id="suU-1L-G4Z"/>
189191
<outlet property="playButton" destination="oh1-vd-YBA" id="b9j-po-y99"/>
190192
<outlet property="waveform" destination="pHr-84-A7W" id="Cbo-cG-3Zd"/>
191193
</connections>

Example/Source/ViewController.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import FDWaveformView
1313
class ViewController: UIViewController {
1414
@IBOutlet weak var waveform: FDWaveformView!
1515
@IBOutlet var playButton: UIView!
16+
@IBOutlet weak var logarithmicButton: UIButton!
17+
@IBOutlet weak var linearButton: UIButton!
1618

1719
fileprivate var startRendering = Date()
1820
fileprivate var endRendering = Date()
@@ -89,10 +91,12 @@ class ViewController: UIViewController {
8991

9092
@IBAction func doLinear() {
9193
self.waveform.waveformType = .linear
94+
updateWaveformTypeButtons()
9295
}
9396

9497
@IBAction func doLogarithmic() {
9598
self.waveform.waveformType = .logarithmic
99+
updateWaveformTypeButtons()
96100
}
97101

98102
@IBAction func doChangeColors() {
@@ -116,6 +120,19 @@ class ViewController: UIViewController {
116120
self.waveform.doesAllowScrubbing = true
117121
self.waveform.doesAllowStretch = true
118122
self.waveform.doesAllowScroll = true
123+
updateWaveformTypeButtons()
124+
}
125+
126+
func updateWaveformTypeButtons() {
127+
let (selectedButton, nonSelectedButton): (UIButton, UIButton) = {
128+
switch self.waveform.waveformType {
129+
case .linear: return (self.linearButton, self.logarithmicButton)
130+
case .logarithmic: return (self.logarithmicButton, self.linearButton)
131+
}
132+
}()
133+
selectedButton.layer.borderColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
134+
selectedButton.layer.borderWidth = 2
135+
nonSelectedButton.layer.borderWidth = 0
119136
}
120137
}
121138

0 commit comments

Comments
 (0)