5 Commits

Author SHA1 Message Date
zbydonuts e716db602a edit podspec 2018-04-10 10:48:55 +09:00
zbydonuts bf9ebb8bcb add full-size tap 2018-04-10 10:42:30 +09:00
zbydonuts a6e2d4009e add circle color 2018-04-10 10:25:23 +09:00
zbydonuts 861a91f999 add backgroundColor to UI state 2018-04-09 19:00:39 +09:00
zbydonuts 62d301cd59 add circle shadow control 2018-04-09 18:51:02 +09:00
11 changed files with 68 additions and 25 deletions
@@ -30,7 +30,7 @@
/* Begin PBXFileReference section */
3FCE599881BA9C988E5C908E /* Pods-LabelSwitch_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LabelSwitch_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-LabelSwitch_Tests/Pods-LabelSwitch_Tests.release.xcconfig"; sourceTree = "<group>"; };
4B4702550120B5E68063AD24 /* Pods-LabelSwitch_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LabelSwitch_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LabelSwitch_Example/Pods-LabelSwitch_Example.debug.xcconfig"; sourceTree = "<group>"; };
51D1FAC01FE40FEF716EE65E /* LabelSwitch.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LabelSwitch.podspec; path = ../LabelSwitch.podspec; sourceTree = "<group>"; };
51D1FAC01FE40FEF716EE65E /* LabelSwitch.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LabelSwitch.podspec; path = ../LabelSwitch.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
607FACD01AFB9204008FA782 /* LabelSwitch_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LabelSwitch_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
+3
View File
@@ -17,6 +17,9 @@ class ViewController: UIViewController {
super.viewDidLoad()
labelSwitch.delegate = self
labelSwitch.curState = .R
labelSwitch.circleShadow = false
labelSwitch.circleColor = .red
labelSwitch.fullSizeTapEnabled = true
// Do any additional setup after loading the view, typically from a nib.
}
+2 -2
View File
@@ -1,5 +1,5 @@
PODS:
- LabelSwitch (0.1.0)
- LabelSwitch (0.1.2)
DEPENDENCIES:
- LabelSwitch (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ../
SPEC CHECKSUMS:
LabelSwitch: 0433b71ee222606795ba549d708c7cd945c7d5ed
LabelSwitch: 91f9db2e1cbb200aabe1de4a879f95d60d99527c
PODFILE CHECKSUM: a898de11b0f271336544f6e30dfc02c11c75244a
+4 -5
View File
@@ -1,6 +1,6 @@
{
"name": "LabelSwitch",
"version": "0.1.0",
"version": "0.1.2",
"summary": "Switch with label in background",
"description": "TODO: Add long description of the pod here.",
"homepage": "https://github.com/Cookiezby/LabelSwitch",
@@ -9,15 +9,14 @@
"file": "LICENSE"
},
"authors": {
"zhubingyi1992@gmail.com": "zhu.bingyi1992@gmail.com"
"cookiezby@gmail.com": "cookiezby@gmail.com"
},
"source": {
"git": "https://github.com/Cookiezby/LabelSwitch.git",
"tag": "0.1.0"
"tag": "0.1.2"
},
"platforms": {
"ios": "9.0"
},
"source_files": "LabelSwitch/Classes/**/*",
"swift_version": "4.0"
"source_files": "LabelSwitch/Classes/**/*"
}
+2 -2
View File
@@ -1,5 +1,5 @@
PODS:
- LabelSwitch (0.1.0)
- LabelSwitch (0.1.2)
DEPENDENCIES:
- LabelSwitch (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ../
SPEC CHECKSUMS:
LabelSwitch: 0433b71ee222606795ba549d708c7cd945c7d5ed
LabelSwitch: 91f9db2e1cbb200aabe1de4a879f95d60d99527c
PODFILE CHECKSUM: a898de11b0f271336544f6e30dfc02c11c75244a
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<string>0.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+1 -10
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'LabelSwitch'
s.version = '0.1.2'
s.version = '0.1.3'
s.summary = 'Switch with label in background'
# This description is used to generate tags and improve search results.
@@ -26,17 +26,8 @@ TODO: Add long description of the pod here.
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'cookiezby@gmail.com' => 'cookiezby@gmail.com' }
s.source = { :git => 'https://github.com/Cookiezby/LabelSwitch.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.source_files = 'LabelSwitch/Classes/**/*'
# s.resource_bundles = {
# 'LabelSwitch' => ['LabelSwitch/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
+37
View File
@@ -21,6 +21,8 @@ struct TextTypeUIState {
var leftTextMaskFrame: CGRect = .zero
var rightTextMaskFrame: CGRect = .zero
var backgroundColor: UIColor = .clear
}
@IBDesignable public class LabelSwitch: UIView {
@@ -45,6 +47,8 @@ struct TextTypeUIState {
private var leftUIState = TextTypeUIState()
private var rightUIState = TextTypeUIState()
private var fullSizeTapGesture: UITapGestureRecognizer?
public weak var delegate: LabelSwitchDelegate?
public var curState: SwitchState {
didSet{
@@ -54,6 +58,29 @@ struct TextTypeUIState {
}
}
}
public var circleShadow: Bool = true {
didSet{
circleView.layer.shadowOpacity = circleShadow ? 0.5 : 0.0
}
}
public var circleColor: UIColor = .white {
didSet{
circleView.backgroundColor = circleColor
}
}
public var fullSizeTapEnabled: Bool = false {
didSet{
if fullSizeTapEnabled {
fullSizeTapGesture = UITapGestureRecognizer(target: self, action: #selector(switchTaped(sender:)))
addGestureRecognizer(fullSizeTapGesture!)
} else {
fullSizeTapGesture?.removeTarget(self, action: #selector(switchTaped(sender:)))
fullSizeTapGesture = nil
}
}
}
@IBInspectable var lBackColor: UIColor = .white {
didSet{
@@ -120,6 +147,7 @@ struct TextTypeUIState {
setupBounds()
setupTextMask()
setupTextBackground()
setupBackgroundColor()
setupText()
setupCircle()
@@ -241,6 +269,14 @@ struct TextTypeUIState {
leftTextBackground.backgroundColor = leftSetting.backgroundColor
rightTextBackground.backgroundColor = rightSetting.backgroundColor
leftTextBackground.layer.cornerRadius = bounds.height / 2
rightTextBackground.layer.cornerRadius = bounds.height / 2
}
private func setupBackgroundColor() {
leftUIState.backgroundColor = leftSetting.backgroundColor
rightUIState.backgroundColor = rightSetting.backgroundColor
}
/// Called when the circle is touched
@@ -265,6 +301,7 @@ struct TextTypeUIState {
leftTextBackground.frame = state.leftBgFrame
rightTextBackground.frame = state.rightBgFrame
backgroundColor = state.backgroundColor
}
+10 -4
View File
@@ -21,21 +21,27 @@ pod 'LabelSwitch'
You can create the view through code or InterfaceBuilder
```swift
let ls = LabelSwtichSetting(text: "午前",
let ls = LabelSwtichSetting(text: "Text1",
textColor: .white,
font: UIFont.boldSystemFont(ofSize: 15),
backgroundColor: .red)
let rs = LabelSwtichSetting(text: "午後",
let rs = LabelSwtichSetting(text: "Text2",
textColor: .white,
font: UIFont.boldSystemFont(ofSize: 20),
backgroundColor: .green)
// You can set the default state of the switch,
// Set the default state of the switch,
let labelSwitch = LabelSwitch(center: .zero, leftSetting: ls, rightSetting: rs, defaultState: .L)
// And you can set the delegate to know when the switch was tapped
// Set the appearance of the circle button
labelSwitch.circleShadow = false
labelSwitch.circleColor = .red
// Make switch be triggered by tapping on any position in the switch
labelSwitch.fullSizeTapEnabled = true
// Set the delegate to inform when the switch was triggered
labelSwitch.delegate = self
extension ViewController: LabelSwitchDelegate {