Skip to content

Commit

Permalink
Change switch button off state design
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Nov 14, 2023
1 parent 3440eaf commit ab12530
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
6 changes: 4 additions & 2 deletions MoppApp/MoppApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
DF4B841E284417CD005CB875 /* CertificateDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4B841D284417CD005CB875 /* CertificateDetail.swift */; };
DF51499E29E98127008AB161 /* ScaledTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF51499D29E98127008AB161 /* ScaledTextField.swift */; };
DF53DCEA2A0A9D8A00F5DAF6 /* NotificationMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF53DCE92A0A9D8A00F5DAF6 /* NotificationMessage.swift */; };
DF57DCCC2B02AFB700ABCBF3 /* SwitchButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF57DCCB2B02AFB700ABCBF3 /* SwitchButton.swift */; };
DF5BE6D229C8AE5200331609 /* SignatureWarningsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5BE6D129C8AE5200331609 /* SignatureWarningsCell.swift */; };
DF5BE6D429C8BD5600331609 /* WarningDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5BE6D329C8BD5600331609 /* WarningDetail.swift */; };
DF6299122664FEFE00E6C55E /* UrlSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF6299112664FEFE00E6C55E /* UrlSchemeHandler.swift */; };
Expand Down Expand Up @@ -499,7 +500,6 @@
C5E7D08C2031B1040081416F /* NativeShare.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeShare.swift; sourceTree = "<group>"; };
C5EA718A2176057A00440F4A /* TestEnvInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = TestEnvInfo.plist; sourceTree = "<group>"; };
C5F462A9209C6B05001B7D59 /* NSMutableAttributedString+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Additions.swift"; sourceTree = "<group>"; };
C5F974E4217733CB00A167C7 /* MoppAppTestEnv.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MoppAppTestEnv.entitlements; sourceTree = "<group>"; };
C5FA0BE820A1930400A208E5 /* MoppApp+Jailbreak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MoppApp+Jailbreak.swift"; sourceTree = "<group>"; };
C5FA0BEB20A19AE100A208E5 /* Jailbreak.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Jailbreak.storyboard; sourceTree = "<group>"; };
C5FA0BED20A19E4200A208E5 /* JailbreakViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JailbreakViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -527,6 +527,7 @@
DF4B841D284417CD005CB875 /* CertificateDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertificateDetail.swift; sourceTree = "<group>"; };
DF51499D29E98127008AB161 /* ScaledTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScaledTextField.swift; sourceTree = "<group>"; };
DF53DCE92A0A9D8A00F5DAF6 /* NotificationMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationMessage.swift; sourceTree = "<group>"; };
DF57DCCB2B02AFB700ABCBF3 /* SwitchButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwitchButton.swift; sourceTree = "<group>"; };
DF5BE6D129C8AE5200331609 /* SignatureWarningsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureWarningsCell.swift; sourceTree = "<group>"; };
DF5BE6D329C8BD5600331609 /* WarningDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WarningDetail.swift; sourceTree = "<group>"; };
DF6299112664FEFE00E6C55E /* UrlSchemeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlSchemeHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -972,6 +973,7 @@
DF0C2B3D29150E8F007E1745 /* Custom classes */ = {
isa = PBXGroup;
children = (
DF57DCCB2B02AFB700ABCBF3 /* SwitchButton.swift */,
DF0C2B3E29150EAB007E1745 /* ScaledLabel.swift */,
DFD8BEF4291C432400FE8F07 /* ScaledButton.swift */,
DFEE73032A151423003428E4 /* ScaledTextView.swift */,
Expand Down Expand Up @@ -1078,7 +1080,6 @@
isa = PBXGroup;
children = (
54A418351E83FB2800559E2B /* MoppApp.entitlements */,
C5F974E4217733CB00A167C7 /* MoppAppTestEnv.entitlements */,
54A5729E1E82AC760099BFAF /* AppStore.plist */,
C52E82791FC1D7000074B280 /* main.swift */,
C52E827B1FC1D7BC0074B280 /* MoppApp.swift */,
Expand Down Expand Up @@ -1706,6 +1707,7 @@
E42B08AE1E1EFC1800EA24A3 /* DateFormatter.swift in Sources */,
DFC2ADBE294375FA008A1CD2 /* TokenFlowUtil.swift in Sources */,
DFDF02C4241ED0CA006CF443 /* MobileIDSignature.swift in Sources */,
DF57DCCC2B02AFB700ABCBF3 /* SwitchButton.swift in Sources */,
C55BB1C720908EF300618AC4 /* DiagnosticsViewController.swift in Sources */,
54825EF81E1D270F00253FF0 /* String+Additions.swift in Sources */,
DFD176CB23F1B78000E2CC52 /* MimeTypeDecoder.swift in Sources */,
Expand Down
15 changes: 14 additions & 1 deletion MoppApp/MoppApp/Extensions/UISwitch+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@
import Foundation

extension UISwitch {
var isOff:Bool {
var isOff: Bool {
return !isOn
}

var offColor: UIColor? {
get {
if let layerBackgroundColor = self.layer.backgroundColor {
return UIColor(cgColor: layerBackgroundColor)
}
return self.subviews.first?.subviews.first?.backgroundColor
}
set {
layer.cornerRadius = bounds.height / 2
layer.backgroundColor = newValue?.cgColor
}
}
}
6 changes: 3 additions & 3 deletions MoppApp/MoppApp/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
<color key="textColor" name="MoppLabel"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5ZR-f6-fYn">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5ZR-f6-fYn" customClass="SwitchButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="294" y="6.5" width="51" height="31"/>
<connections>
<action selector="useDefaultToggled:" destination="S9f-IU-Vln" eventType="touchUpInside" id="gpv-K4-w5q"/>
Expand Down Expand Up @@ -359,7 +359,7 @@
<color key="textColor" name="MoppLabel"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="nSd-0O-0nE">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="nSd-0O-0nE" customClass="SwitchButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="294" y="84.5" width="51" height="31"/>
<connections>
<action selector="stateToggled:" destination="Jvo-qw-kMQ" eventType="valueChanged" id="VeS-PD-EfD"/>
Expand Down Expand Up @@ -613,7 +613,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="751" verticalHuggingPriority="750" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vjc-8d-DZD">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="751" verticalHuggingPriority="750" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="vjc-8d-DZD" customClass="SwitchButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="285.5" y="0.0" width="43.5" height="31"/>
<connections>
<action selector="fileLoggingSwitchChanged:" destination="B8K-Cg-QcU" eventType="valueChanged" id="843-Jb-vWY"/>
Expand Down
41 changes: 41 additions & 0 deletions MoppApp/MoppApp/SwitchButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SwitchButton.swift
// MoppApp
//
/*
* Copyright 2017 - 2023 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

import Foundation

class SwitchButton: UISwitch {

override init(frame: CGRect) {
super.init(frame: frame)
setDefaultOffColor()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setDefaultOffColor()
}

private func setDefaultOffColor() {
self.offColor = UIColor.moppLabel
}
}
4 changes: 2 additions & 2 deletions MoppApp/MoppApp/TokenFlow.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
<color key="textColor" red="0.45882352939999999" green="0.47058823529999999" blue="0.4823529412" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="right" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MHH-mX-gAV">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="right" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MHH-mX-gAV" customClass="SwitchButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="284.5" y="0.0" width="42.5" height="31"/>
<color key="onTintColor" red="0.54901960780000003" green="0.76470588240000004" blue="0.40784313729999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</switch>
Expand Down Expand Up @@ -801,7 +801,7 @@
<color key="textColor" red="0.45882352939999999" green="0.47058823529999999" blue="0.4823529412" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="right" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7QK-Af-BRR">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="right" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7QK-Af-BRR" customClass="SwitchButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="253.5" y="0.0" width="41.5" height="31"/>
</switch>
</subviews>
Expand Down

0 comments on commit ab12530

Please sign in to comment.