Skip to content

Commit 26c1c55

Browse files
committed
Add one more switcher using frame
1 parent edb0f74 commit 26c1c55

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

KNSwitcher.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class KNSwitcher: UIView {
7777
button.widthAnchor.constraint(equalTo: button.heightAnchor, multiplier: 1).isActive = true
7878
}
7979

80-
func setImages(onImage:UIImage , offImage :UIImage) {
80+
func setImages(onImage:UIImage? , offImage :UIImage?) {
8181
button.setImage(offImage, for: .normal)
8282
button.setImage(onImage, for: .selected)
8383
}

SwitcherExample/Base.lproj/Main.storyboard

-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2121
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2222
<subviews>
23-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QtP-RA-X1B">
24-
<rect key="frame" x="164" y="617" width="47" height="30"/>
25-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
26-
<state key="normal" title="Toggle"/>
27-
<connections>
28-
<action selector="toggleBig:" destination="BYZ-38-t0r" eventType="touchUpInside" id="zUA-le-ET5"/>
29-
</connections>
30-
</button>
3123
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vka-f4-iBa" customClass="KNSwitcher" customModule="SwitcherExample" customModuleProvider="target">
3224
<rect key="frame" x="67.5" y="269.5" width="240" height="128"/>
3325
<color key="backgroundColor" red="0.87058823529999996" green="0.92549019610000005" blue="0.80784313730000001" alpha="1" colorSpace="calibratedRGB"/>

SwitcherExample/ViewController.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ class ViewController: UIViewController, KNSwitcherChangeValueDelegate {
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515

16-
let switcher = KNSwitcher(frame: CGRect(x: 0, y: 0, width: 200, height: 40), on: false)
16+
let switcher = KNSwitcher(frame: CGRect(x: 100, y: 100, width: 200, height: 80), on: false)
17+
switcher.setImages(onImage: UIImage(named: "Checkmark"), offImage: UIImage(named: "Delete"))
1718
self.view.addSubview(switcher)
1819
}
1920

2021
override func didReceiveMemoryWarning() {
2122
super.didReceiveMemoryWarning()
2223
// Dispose of any resources that can be recreated.
2324
}
24-
25-
@IBAction func toggleBig(_ sender: AnyObject) {
26-
// big.setOn(on: !big.on)
27-
}
2825

2926
func switcherDidChangeValue(switcher:KNSwitcher, value: Bool) {
3027
if value {

0 commit comments

Comments
 (0)