├── .gitignore ├── ControlSlider.podspec ├── ControlSlider.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── ControlSlider ├── ControlSlider.h ├── ControlSlider.swift ├── ControlVSlider.swift └── Info.plist ├── LICENSE ├── README.md └── screens ├── adjust.png ├── integration0.png ├── integration1.png ├── integration2.png ├── screen0.png ├── screen0_s.png ├── screen1.png ├── screen1_s.png ├── screen2.png └── screen2_s.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /ControlSlider.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |spec| 3 | spec.name = 'ControlSlider' 4 | spec.version = '0.6.0' 5 | spec.license = { :type => 'Apache 2' } 6 | spec.homepage = 'https://github.com/msedd/ControlSlider.git' 7 | spec.authors = { 'Marko Seifert' => 'http://www.marko-seifert.de' } 8 | spec.summary = 'Sliding UIControl for controlling IoT or home devices ' 9 | spec.source = { :git => 'https://github.com/msedd/ControlSlider.git'} 10 | spec.source_files = 'ControlSlider/*.{h,swift}' 11 | spec.framework = 'Foundation' 12 | spec.swift_version = '5.0' 13 | 14 | end 15 | -------------------------------------------------------------------------------- /ControlSlider.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E1145FF23C1386E007ACC78 /* ControlVSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E1145FE23C1386E007ACC78 /* ControlVSlider.swift */; }; 11 | 5E569C5C1C3E72E100A97FCC /* ControlSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E569C5B1C3E72E100A97FCC /* ControlSlider.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | 5E569C641C3E735800A97FCC /* ControlSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E569C631C3E735800A97FCC /* ControlSlider.swift */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXFileReference section */ 16 | 5E1145FE23C1386E007ACC78 /* ControlVSlider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlVSlider.swift; sourceTree = ""; }; 17 | 5E569C581C3E72E100A97FCC /* ControlSlider.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ControlSlider.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | 5E569C5B1C3E72E100A97FCC /* ControlSlider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ControlSlider.h; sourceTree = ""; }; 19 | 5E569C5D1C3E72E100A97FCC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 20 | 5E569C631C3E735800A97FCC /* ControlSlider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlSlider.swift; sourceTree = ""; }; 21 | /* End PBXFileReference section */ 22 | 23 | /* Begin PBXFrameworksBuildPhase section */ 24 | 5E569C541C3E72E100A97FCC /* Frameworks */ = { 25 | isa = PBXFrameworksBuildPhase; 26 | buildActionMask = 2147483647; 27 | files = ( 28 | ); 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXFrameworksBuildPhase section */ 32 | 33 | /* Begin PBXGroup section */ 34 | 5E569C4E1C3E72E100A97FCC = { 35 | isa = PBXGroup; 36 | children = ( 37 | 5E569C5A1C3E72E100A97FCC /* ControlSlider */, 38 | 5E569C591C3E72E100A97FCC /* Products */, 39 | ); 40 | sourceTree = ""; 41 | }; 42 | 5E569C591C3E72E100A97FCC /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 5E569C581C3E72E100A97FCC /* ControlSlider.framework */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 5E569C5A1C3E72E100A97FCC /* ControlSlider */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 5E569C631C3E735800A97FCC /* ControlSlider.swift */, 54 | 5E1145FE23C1386E007ACC78 /* ControlVSlider.swift */, 55 | 5E569C5B1C3E72E100A97FCC /* ControlSlider.h */, 56 | 5E569C5D1C3E72E100A97FCC /* Info.plist */, 57 | ); 58 | path = ControlSlider; 59 | sourceTree = ""; 60 | }; 61 | /* End PBXGroup section */ 62 | 63 | /* Begin PBXHeadersBuildPhase section */ 64 | 5E569C551C3E72E100A97FCC /* Headers */ = { 65 | isa = PBXHeadersBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | 5E569C5C1C3E72E100A97FCC /* ControlSlider.h in Headers */, 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXHeadersBuildPhase section */ 73 | 74 | /* Begin PBXNativeTarget section */ 75 | 5E569C571C3E72E100A97FCC /* ControlSlider */ = { 76 | isa = PBXNativeTarget; 77 | buildConfigurationList = 5E569C601C3E72E100A97FCC /* Build configuration list for PBXNativeTarget "ControlSlider" */; 78 | buildPhases = ( 79 | 5E569C531C3E72E100A97FCC /* Sources */, 80 | 5E569C541C3E72E100A97FCC /* Frameworks */, 81 | 5E569C551C3E72E100A97FCC /* Headers */, 82 | 5E569C561C3E72E100A97FCC /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = ControlSlider; 89 | productName = ControlSlider; 90 | productReference = 5E569C581C3E72E100A97FCC /* ControlSlider.framework */; 91 | productType = "com.apple.product-type.framework"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | 5E569C4F1C3E72E100A97FCC /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastUpgradeCheck = 0710; 100 | ORGANIZATIONNAME = "Marko Seifert"; 101 | TargetAttributes = { 102 | 5E569C571C3E72E100A97FCC = { 103 | CreatedOnToolsVersion = 7.1; 104 | LastSwiftMigration = 0820; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = 5E569C521C3E72E100A97FCC /* Build configuration list for PBXProject "ControlSlider" */; 109 | compatibilityVersion = "Xcode 3.2"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | ); 115 | mainGroup = 5E569C4E1C3E72E100A97FCC; 116 | productRefGroup = 5E569C591C3E72E100A97FCC /* Products */; 117 | projectDirPath = ""; 118 | projectRoot = ""; 119 | targets = ( 120 | 5E569C571C3E72E100A97FCC /* ControlSlider */, 121 | ); 122 | }; 123 | /* End PBXProject section */ 124 | 125 | /* Begin PBXResourcesBuildPhase section */ 126 | 5E569C561C3E72E100A97FCC /* Resources */ = { 127 | isa = PBXResourcesBuildPhase; 128 | buildActionMask = 2147483647; 129 | files = ( 130 | ); 131 | runOnlyForDeploymentPostprocessing = 0; 132 | }; 133 | /* End PBXResourcesBuildPhase section */ 134 | 135 | /* Begin PBXSourcesBuildPhase section */ 136 | 5E569C531C3E72E100A97FCC /* Sources */ = { 137 | isa = PBXSourcesBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | 5E569C641C3E735800A97FCC /* ControlSlider.swift in Sources */, 141 | 5E1145FF23C1386E007ACC78 /* ControlVSlider.swift in Sources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXSourcesBuildPhase section */ 146 | 147 | /* Begin XCBuildConfiguration section */ 148 | 5E569C5E1C3E72E100A97FCC /* Debug */ = { 149 | isa = XCBuildConfiguration; 150 | buildSettings = { 151 | ALWAYS_SEARCH_USER_PATHS = NO; 152 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 153 | CLANG_CXX_LIBRARY = "libc++"; 154 | CLANG_ENABLE_MODULES = YES; 155 | CLANG_ENABLE_OBJC_ARC = YES; 156 | CLANG_WARN_BOOL_CONVERSION = YES; 157 | CLANG_WARN_CONSTANT_CONVERSION = YES; 158 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 159 | CLANG_WARN_EMPTY_BODY = YES; 160 | CLANG_WARN_ENUM_CONVERSION = YES; 161 | CLANG_WARN_INT_CONVERSION = YES; 162 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 163 | CLANG_WARN_UNREACHABLE_CODE = YES; 164 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 165 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 166 | COPY_PHASE_STRIP = NO; 167 | CURRENT_PROJECT_VERSION = 1; 168 | DEBUG_INFORMATION_FORMAT = dwarf; 169 | ENABLE_STRICT_OBJC_MSGSEND = YES; 170 | ENABLE_TESTABILITY = YES; 171 | GCC_C_LANGUAGE_STANDARD = gnu99; 172 | GCC_DYNAMIC_NO_PIC = NO; 173 | GCC_NO_COMMON_BLOCKS = YES; 174 | GCC_OPTIMIZATION_LEVEL = 0; 175 | GCC_PREPROCESSOR_DEFINITIONS = ( 176 | "DEBUG=1", 177 | "$(inherited)", 178 | ); 179 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 180 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 181 | GCC_WARN_UNDECLARED_SELECTOR = YES; 182 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 183 | GCC_WARN_UNUSED_FUNCTION = YES; 184 | GCC_WARN_UNUSED_VARIABLE = YES; 185 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 186 | MTL_ENABLE_DEBUG_INFO = YES; 187 | ONLY_ACTIVE_ARCH = YES; 188 | SDKROOT = iphoneos; 189 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 190 | SWIFT_VERSION = 5.0; 191 | TARGETED_DEVICE_FAMILY = "1,2"; 192 | VERSIONING_SYSTEM = "apple-generic"; 193 | VERSION_INFO_PREFIX = ""; 194 | }; 195 | name = Debug; 196 | }; 197 | 5E569C5F1C3E72E100A97FCC /* Release */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_ENABLE_MODULES = YES; 204 | CLANG_ENABLE_OBJC_ARC = YES; 205 | CLANG_WARN_BOOL_CONVERSION = YES; 206 | CLANG_WARN_CONSTANT_CONVERSION = YES; 207 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 208 | CLANG_WARN_EMPTY_BODY = YES; 209 | CLANG_WARN_ENUM_CONVERSION = YES; 210 | CLANG_WARN_INT_CONVERSION = YES; 211 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 212 | CLANG_WARN_UNREACHABLE_CODE = YES; 213 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 214 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 215 | COPY_PHASE_STRIP = NO; 216 | CURRENT_PROJECT_VERSION = 1; 217 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 218 | ENABLE_NS_ASSERTIONS = NO; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_NO_COMMON_BLOCKS = YES; 222 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 223 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 224 | GCC_WARN_UNDECLARED_SELECTOR = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 226 | GCC_WARN_UNUSED_FUNCTION = YES; 227 | GCC_WARN_UNUSED_VARIABLE = YES; 228 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 229 | MTL_ENABLE_DEBUG_INFO = NO; 230 | SDKROOT = iphoneos; 231 | SWIFT_VERSION = 5.0; 232 | TARGETED_DEVICE_FAMILY = "1,2"; 233 | VALIDATE_PRODUCT = YES; 234 | VERSIONING_SYSTEM = "apple-generic"; 235 | VERSION_INFO_PREFIX = ""; 236 | }; 237 | name = Release; 238 | }; 239 | 5E569C611C3E72E100A97FCC /* Debug */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | CLANG_ENABLE_MODULES = YES; 243 | DEFINES_MODULE = YES; 244 | DYLIB_COMPATIBILITY_VERSION = 1; 245 | DYLIB_CURRENT_VERSION = 1; 246 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 247 | INFOPLIST_FILE = ControlSlider/Info.plist; 248 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 249 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 250 | PRODUCT_BUNDLE_IDENTIFIER = "de.marko-seifert.ControlSlider"; 251 | PRODUCT_NAME = "$(TARGET_NAME)"; 252 | SKIP_INSTALL = YES; 253 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 254 | SWIFT_VERSION = 5.0; 255 | }; 256 | name = Debug; 257 | }; 258 | 5E569C621C3E72E100A97FCC /* Release */ = { 259 | isa = XCBuildConfiguration; 260 | buildSettings = { 261 | CLANG_ENABLE_MODULES = YES; 262 | DEFINES_MODULE = YES; 263 | DYLIB_COMPATIBILITY_VERSION = 1; 264 | DYLIB_CURRENT_VERSION = 1; 265 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 266 | INFOPLIST_FILE = ControlSlider/Info.plist; 267 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 268 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 269 | PRODUCT_BUNDLE_IDENTIFIER = "de.marko-seifert.ControlSlider"; 270 | PRODUCT_NAME = "$(TARGET_NAME)"; 271 | SKIP_INSTALL = YES; 272 | SWIFT_VERSION = 5.0; 273 | }; 274 | name = Release; 275 | }; 276 | /* End XCBuildConfiguration section */ 277 | 278 | /* Begin XCConfigurationList section */ 279 | 5E569C521C3E72E100A97FCC /* Build configuration list for PBXProject "ControlSlider" */ = { 280 | isa = XCConfigurationList; 281 | buildConfigurations = ( 282 | 5E569C5E1C3E72E100A97FCC /* Debug */, 283 | 5E569C5F1C3E72E100A97FCC /* Release */, 284 | ); 285 | defaultConfigurationIsVisible = 0; 286 | defaultConfigurationName = Release; 287 | }; 288 | 5E569C601C3E72E100A97FCC /* Build configuration list for PBXNativeTarget "ControlSlider" */ = { 289 | isa = XCConfigurationList; 290 | buildConfigurations = ( 291 | 5E569C611C3E72E100A97FCC /* Debug */, 292 | 5E569C621C3E72E100A97FCC /* Release */, 293 | ); 294 | defaultConfigurationIsVisible = 0; 295 | defaultConfigurationName = Release; 296 | }; 297 | /* End XCConfigurationList section */ 298 | }; 299 | rootObject = 5E569C4F1C3E72E100A97FCC /* Project object */; 300 | } 301 | -------------------------------------------------------------------------------- /ControlSlider.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ControlSlider.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ControlSlider/ControlSlider.h: -------------------------------------------------------------------------------- 1 | // 2 | // ControlSlider.h 3 | // ControlSlider 4 | // 5 | // Created by Marko Seifert on 07.01.16. 6 | // 7 | // Copyright © 2015 Marko Seifert. 8 | // Licensed under the Apache License, Version 2.0 (the "License") 9 | 10 | #import 11 | 12 | //! Project version number for ControlSlider. 13 | FOUNDATION_EXPORT double ControlSliderVersionNumber; 14 | 15 | //! Project version string for ControlSlider. 16 | FOUNDATION_EXPORT const unsigned char ControlSliderVersionString[]; 17 | 18 | // In this header, you should import all the public headers of your framework using statements like #import 19 | 20 | 21 | -------------------------------------------------------------------------------- /ControlSlider/ControlSlider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DimSlider.swift 3 | // ControlSlider.h 4 | // 5 | // Created by Marko Seifert on 21.12.15. 6 | // 7 | // Copyright © 2015 Marko Seifert. 8 | // Licensed under the Apache License, Version 2.0 (the "License") 9 | 10 | import UIKit 11 | 12 | @IBDesignable open class ControlSlider: UIControl { 13 | 14 | 15 | @IBInspectable open var activeFillColor: UIColor = UIColor(red: 0.232, green: 0.653, blue: 0.999, alpha: 1.000) 16 | @IBInspectable open var textForeground: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000) 17 | @IBInspectable open var buttonColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.640) 18 | @IBInspectable open var buttonStrokeColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000) 19 | @IBInspectable open var bgBarColor: UIColor = UIColor(red: 0.1647, green: 0.1647, blue: 0.1647, alpha: 1.0) 20 | @IBInspectable open var bgColor: UIColor = UIColor(red: 0.1255, green: 0.1255, blue: 0.1255, alpha: 1.0) 21 | @IBInspectable open var maxValue:CGFloat = 255 22 | @IBInspectable open var minValue:CGFloat = 0 23 | @IBInspectable open var relative:Bool = false 24 | 25 | fileprivate var offset: Float = 0 26 | fileprivate var _value: Float = 0 27 | 28 | dynamic open var value: Float { 29 | get { 30 | return _value 31 | } 32 | } 33 | 34 | var size:CGRect { 35 | get { 36 | let bounds = self.bounds 37 | let offset: CGFloat = 30.0 38 | return CGRect(x: bounds.origin.x, y: (bounds.origin.y+offset/2), width: bounds.size.width,height: (bounds.size.height - offset)) 39 | } 40 | } 41 | var viewSize:CGRect { 42 | get { 43 | let bounds = self.bounds 44 | return CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width,height: bounds.size.height) 45 | } 46 | } 47 | 48 | var length:CGFloat{ 49 | get { 50 | return CGFloat(value) * (size.height)/maxValue 51 | } 52 | } 53 | 54 | override public init(frame: CGRect) { 55 | 56 | super.init(frame: frame) 57 | 58 | 59 | } 60 | 61 | required public init?(coder aDecoder: NSCoder) { 62 | 63 | super.init(coder: aDecoder) 64 | } 65 | 66 | open func setValue(value: Float) { 67 | let mav = Float(maxValue) 68 | let miv = Float(minValue) 69 | if value > mav { 70 | _value = mav 71 | } else if value < miv { 72 | _value = miv 73 | } else { 74 | _value = value 75 | } 76 | } 77 | 78 | fileprivate func setValueInternal(value: Float) { 79 | setValue(value: value) 80 | sendActions(for: .valueChanged) 81 | } 82 | 83 | override open func touchesBegan(_ touches: Set, with event: UIEvent?) { 84 | if let touch = touches.first, relative { 85 | let loc = touch.location(in: self) 86 | let v = (size.height-loc.y) / size.height * maxValue 87 | offset = value - Float(v) 88 | } 89 | } 90 | 91 | open override func touchesEnded(_ touches: Set, with event: UIEvent?) { 92 | offset = 0 93 | } 94 | 95 | override open func touchesMoved(_ touches: Set, with event: UIEvent?) { 96 | 97 | if let touch = touches.first { 98 | let loc = touch.location(in: self) 99 | 100 | 101 | let v = ((size.height-loc.y) / size.height * maxValue) + CGFloat(offset) 102 | //print("dimmer val: \(v)") 103 | if(v < 0) { 104 | setValueInternal(value: 0) 105 | } else if (v>maxValue) { 106 | setValueInternal(value: Float(maxValue)) 107 | } else { 108 | setValueInternal(value: Float(v)) 109 | } 110 | self.setNeedsDisplay() 111 | 112 | } 113 | } 114 | 115 | override open func draw(_ rect: CGRect) { 116 | let ctx = UIGraphicsGetCurrentContext() 117 | ctx!.clear(rect) 118 | drawBackground() 119 | drawActiveBar() 120 | drawButton() 121 | } 122 | 123 | func drawButton(){ 124 | 125 | let buttonPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x, y: size.height-length, width: size.width, height: 30), cornerRadius: 6) 126 | buttonColor.setFill() 127 | buttonPath.fill() 128 | buttonStrokeColor.setStroke() 129 | buttonPath.lineWidth = 1 130 | buttonPath.stroke() 131 | 132 | let labelRect = CGRect(x: size.origin.x, y: size.height-length, width: size.width, height: 30) 133 | let labelStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle 134 | labelStyle.alignment = .center 135 | let labelFontAttributes = 136 | 137 | [//NSAttributedString.Key.font: UIFont(name: "Helvetica", size: 18), 138 | NSAttributedString.Key.foregroundColor: textForeground, 139 | NSAttributedString.Key.paragraphStyle: labelStyle] 140 | 141 | let intValue:Int = Int(value) 142 | NSString(string: "\(intValue)").draw(in: labelRect, withAttributes:labelFontAttributes) 143 | 144 | 145 | } 146 | 147 | func drawActiveBar(){ 148 | 149 | let bgBarPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x+4, y: size.height-length+15, width: size.width-8, height: length), cornerRadius: 4) 150 | activeFillColor.setFill() 151 | bgBarPath.fill() 152 | } 153 | 154 | func drawBackground(){ 155 | 156 | let bgPath = UIBezierPath(rect: viewSize) 157 | bgColor.setFill() 158 | bgPath.fill(); 159 | 160 | let bgBarPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x+4, y: size.origin.y, width: size.width-8, height: size.height), cornerRadius: 4) 161 | bgBarColor.setFill() 162 | bgBarPath.fill() 163 | 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /ControlSlider/ControlVSlider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DimSlider.swift 3 | // ControlSlider.h 4 | // 5 | // Created by Marko Seifert on 21.12.15. 6 | // 7 | // Copyright © 2015 Marko Seifert. 8 | // Licensed under the Apache License, Version 2.0 (the "License") 9 | 10 | import UIKit 11 | 12 | @IBDesignable open class ControlVSlider: UIControl { 13 | 14 | 15 | @IBInspectable open var activeFillColor: UIColor = UIColor(red: 0.232, green: 0.653, blue: 0.999, alpha: 1.000) 16 | @IBInspectable open var textForeground: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000) 17 | @IBInspectable open var buttonColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.640) 18 | @IBInspectable open var buttonStrokeColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000) 19 | @IBInspectable open var bgBarColor: UIColor = UIColor(red: 0.1647, green: 0.1647, blue: 0.1647, alpha: 1.0) 20 | @IBInspectable open var bgColor: UIColor = UIColor(red: 0.1255, green: 0.1255, blue: 0.1255, alpha: 1.0) 21 | @IBInspectable open var maxValue:CGFloat = 255 22 | open var defaultValue:Float = 0 23 | open var showLable:Bool = true 24 | fileprivate var _value: Float = 0 25 | 26 | dynamic open var value: Float { 27 | get { 28 | return _value 29 | } 30 | } 31 | var size:CGRect { 32 | get { 33 | let bounds = self.bounds 34 | let offset: CGFloat = 50.0 35 | 36 | return CGRect(x: bounds.origin.x+offset/2, y: bounds.origin.y, width: bounds.size.width-offset,height: bounds.size.height) 37 | } 38 | } 39 | var viewSize:CGRect { 40 | get { 41 | let bounds = self.bounds 42 | return CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width,height: bounds.size.height) 43 | } 44 | } 45 | 46 | var length:CGFloat{ 47 | get { 48 | return CGFloat(value) * (size.width)/maxValue 49 | } 50 | } 51 | 52 | override public init(frame: CGRect) { 53 | 54 | super.init(frame: frame) 55 | registerGesture() 56 | } 57 | 58 | required public init?(coder aDecoder: NSCoder) { 59 | 60 | super.init(coder: aDecoder) 61 | registerGesture() 62 | } 63 | 64 | fileprivate func registerGesture() { 65 | let doubleTap : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(resetToDefault)) 66 | doubleTap.numberOfTapsRequired = 2 67 | addGestureRecognizer(doubleTap) 68 | } 69 | @objc func resetToDefault(){ 70 | setValueInternal(value: defaultValue) 71 | self.setNeedsDisplay() 72 | } 73 | 74 | open func setValue(value: Float) { 75 | _value = value 76 | } 77 | 78 | fileprivate func setValueInternal(value: Float) { 79 | _value = value 80 | sendActions(for: .valueChanged) 81 | } 82 | 83 | override open func touchesBegan(_ touches: Set, with event: UIEvent?) { 84 | 85 | } 86 | override open func touchesMoved(_ touches: Set, with event: UIEvent?) { 87 | 88 | if let touch = touches.first { 89 | let loc = touch.location(in: self) 90 | 91 | 92 | let v = (loc.x) / size.width * maxValue 93 | if(v < 0) { 94 | setValueInternal(value: 0) 95 | } else if (v>maxValue) { 96 | setValueInternal(value: Float(maxValue)) 97 | } else { 98 | setValueInternal(value: Float(v)) 99 | } 100 | self.setNeedsDisplay() 101 | 102 | } 103 | } 104 | 105 | override open func draw(_ rect: CGRect) { 106 | let ctx = UIGraphicsGetCurrentContext() 107 | ctx!.clear(rect) 108 | drawBackground() 109 | drawActiveBar() 110 | drawButton() 111 | } 112 | 113 | func drawButton(){ 114 | 115 | let buttonPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x+length-20, y: size.origin.y, width: 40, height: size.height), cornerRadius: 6) 116 | buttonColor.setFill() 117 | buttonPath.fill() 118 | buttonStrokeColor.setStroke() 119 | buttonPath.lineWidth = 1 120 | buttonPath.stroke() 121 | if showLable { 122 | let labelRect = CGRect(x: size.origin.x+length-20, y: size.height-30 , width: 40, height: 30) 123 | let labelStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle 124 | labelStyle.alignment = .center 125 | let labelFontAttributes = 126 | 127 | [//NSAttributedString.Key.font: UIFont(name: "Helvetica", size: 18), 128 | NSAttributedString.Key.foregroundColor: textForeground, 129 | NSAttributedString.Key.paragraphStyle: labelStyle] 130 | 131 | let intValue:Int = Int(value) 132 | NSString(string: "\(intValue)").draw(in: labelRect, withAttributes:labelFontAttributes) 133 | } 134 | 135 | } 136 | 137 | func drawActiveBar(){ 138 | 139 | let bgBarPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x, y: size.origin.y+4, width: length, height: size.height-8), cornerRadius: 4) 140 | 141 | activeFillColor.setFill() 142 | bgBarPath.fill() 143 | } 144 | 145 | func drawBackground(){ 146 | 147 | let bgPath = UIBezierPath(rect: viewSize) 148 | bgColor.setFill() 149 | bgPath.fill(); 150 | 151 | let bgBarPath = UIBezierPath(roundedRect: CGRect(x: size.origin.x, y: size.origin.y+4, width: size.width, height: size.height-8), cornerRadius: 4) 152 | bgBarColor.setFill() 153 | bgBarPath.fill() 154 | 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /ControlSlider/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ControlSlider 2 | 3 | 4 | ## Description 5 | The ControlSlider is a custom UIControl for iOS written in Swift 2.0. 6 | 7 | 8 | ![Example 1](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/screen0_s.png) 9 | ![Example 2](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/screen1_s.png) 10 | ![Example 3](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/screen2_s.png) 11 | 12 | 13 | Features: 14 | 15 | * vertical Slider 16 | * @IBDesignable/@Inspectable for direct use within Interface Builder 17 | * use together with ReactiveCocoa 18 | 19 | License: Apache 2 License 20 | Language: Swift 2 21 | 22 | ## Requirements 23 | - iOS 8.0+ 24 | - Xcode 7 25 | 26 | ## Installation 27 | 28 | The easiest way is to use [CocoaPods](http://cocoapods.org) for using ControlSlider 29 | 30 | ```ruby 31 | use_frameworks! 32 | pod 'ControlSlider', :git => 'https://github.com/msedd/ControlSlider.git' 33 | ``` 34 | 35 | ## Usage 36 | * add a UIView to your controller in the storyboard 37 | ![add View](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/integration0.png) 38 | 39 | * select as Class and Modul *ControlSlider* 40 | ![select class](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/integration1.png) 41 | 42 | * you can adjust the color of each part from the Slider 43 | ![Customize the color](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/adjust.png) 44 | 45 | * add the UIView as @IBOutlet to your Controller class 46 | ![add Outlet](https://raw.githubusercontent.com/msedd/ControlSlider/master/screens/integration2.png) 47 | 48 | * use ControlSlider together with [ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa) 49 | ```swift 50 | override func viewDidLoad() { 51 | super.viewDidLoad() 52 | ... 53 | self.dimmer1.rac_valuesForKeyPath("value", observer: self).subscribeNext { (newVal:AnyObject!) -> Void in 54 | let value = newVal as! Float 55 | let intValue:UInt8 = UInt8(value) 56 | self.data[0]=intValue 57 | BluetoothController.sharedInstance.send(self.data) 58 | } 59 | self.dimmer2.rac_valuesForKeyPath ... 60 | ... 61 | } 62 | ``` 63 | ## License 64 | Copyright 2016 Marko Seifert 65 | ControlSlider is available under the Apache 2 License. See the LICENSE file for more info. -------------------------------------------------------------------------------- /screens/adjust.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/adjust.png -------------------------------------------------------------------------------- /screens/integration0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/integration0.png -------------------------------------------------------------------------------- /screens/integration1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/integration1.png -------------------------------------------------------------------------------- /screens/integration2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/integration2.png -------------------------------------------------------------------------------- /screens/screen0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen0.png -------------------------------------------------------------------------------- /screens/screen0_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen0_s.png -------------------------------------------------------------------------------- /screens/screen1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen1.png -------------------------------------------------------------------------------- /screens/screen1_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen1_s.png -------------------------------------------------------------------------------- /screens/screen2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen2.png -------------------------------------------------------------------------------- /screens/screen2_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msedd/ControlSlider/a8af61e1db8517d3661badd71c0a208c664716bf/screens/screen2_s.png --------------------------------------------------------------------------------