diff --git a/Example/LabelSwitch.xcodeproj/project.pbxproj b/Example/LabelSwitch.xcodeproj/project.pbxproj index b658115..7746871 100644 --- a/Example/LabelSwitch.xcodeproj/project.pbxproj +++ b/Example/LabelSwitch.xcodeproj/project.pbxproj @@ -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 = ""; }; 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 = ""; }; - 51D1FAC01FE40FEF716EE65E /* LabelSwitch.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LabelSwitch.podspec; path = ../LabelSwitch.podspec; sourceTree = ""; }; + 51D1FAC01FE40FEF716EE65E /* LabelSwitch.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LabelSwitch.podspec; path = ../LabelSwitch.podspec; sourceTree = ""; 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 = ""; }; 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; diff --git a/Example/LabelSwitch.xcworkspace/xcuserdata/zhu.bingyi.xcuserdatad/UserInterfaceState.xcuserstate b/Example/LabelSwitch.xcworkspace/xcuserdata/zhu.bingyi.xcuserdatad/UserInterfaceState.xcuserstate index 19b4212..efef7ca 100644 Binary files a/Example/LabelSwitch.xcworkspace/xcuserdata/zhu.bingyi.xcuserdatad/UserInterfaceState.xcuserstate and b/Example/LabelSwitch.xcworkspace/xcuserdata/zhu.bingyi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/LabelSwitch/ViewController.swift b/Example/LabelSwitch/ViewController.swift index 7371a5f..a685156 100644 --- a/Example/LabelSwitch/ViewController.swift +++ b/Example/LabelSwitch/ViewController.swift @@ -19,6 +19,7 @@ class ViewController: UIViewController { labelSwitch.curState = .R labelSwitch.circleShadow = false labelSwitch.circleColor = .red + labelSwitch.fullSizeTapEnabled = true // Do any additional setup after loading the view, typically from a nib. } diff --git a/LabelSwitch.podspec b/LabelSwitch.podspec index 11d0060..910c988 100644 --- a/LabelSwitch.podspec +++ b/LabelSwitch.podspec @@ -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,9 @@ 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/' - + s.swift_version = '4.0' 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 diff --git a/LabelSwitch/Classes/LabelSwitch.swift b/LabelSwitch/Classes/LabelSwitch.swift index a67c2c9..fd1a63a 100644 --- a/LabelSwitch/Classes/LabelSwitch.swift +++ b/LabelSwitch/Classes/LabelSwitch.swift @@ -47,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{ @@ -68,6 +70,18 @@ struct TextTypeUIState { } } + 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{ leftSetting.backgroundColor = lBackColor @@ -118,7 +132,6 @@ struct TextTypeUIState { self.rightSetting = rightSetting self.circlePadding = circlePadding self.curState = defaultState - self.circleShadow = true super.init(frame: .zero) self.center = center clipsToBounds = true @@ -297,7 +310,6 @@ struct TextTypeUIState { self.rightSetting = LabelSwtichSetting.defaultRight self.circlePadding = 1 self.curState = .L - self.circleShadow = true super.init(coder: aDecoder) clipsToBounds = true addSubview(leftTextBackground) diff --git a/README.md b/README.md index c53b697..57da11b 100644 --- a/README.md +++ b/README.md @@ -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 {