├── .gitignore ├── FFRuler ├── FFRuler.podspec ├── FFRuler.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── FFRuler │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Brand Assets.launchimage │ │ ├── Contents.json │ │ ├── iPhone 6 Plus.png │ │ ├── iPhone 6.png │ │ └── iPhone SE.png │ ├── Base.lproj │ └── Main.storyboard │ ├── CodeDemoViewController.h │ ├── CodeDemoViewController.m │ ├── FFRulerControl │ ├── FFRulerControl.h │ └── FFRulerControl.m │ ├── IBDemoViewController.h │ ├── IBDemoViewController.m │ ├── Info.plist │ └── main.m ├── LICENSE ├── README.md └── screenshots └── screenshots.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /FFRuler/FFRuler.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "FFRuler" 3 | s.version = "0.0.4" 4 | s.summary = "轻量级标尺控件" 5 | s.homepage = "https://github.com/liufan321/FFRuler" 6 | s.license = "MIT" 7 | s.author = { "刘凡" => "liufan321@gmail.com" } 8 | s.platform = :ios, "7.0" 9 | s.source = { :git => "https://github.com/liufan321/FFRuler.git", :tag => "#{s.version}" } 10 | s.source_files = "FFRuler", "FFRuler/FFRuler/FFRulerControl/*.{h,m}" 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /FFRuler/FFRuler.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C2E92B201D61A8E70037DE79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C2E92B1F1D61A8E70037DE79 /* main.m */; }; 11 | C2E92B231D61A8E70037DE79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C2E92B221D61A8E70037DE79 /* AppDelegate.m */; }; 12 | C2E92B291D61A8E70037DE79 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C2E92B271D61A8E70037DE79 /* Main.storyboard */; }; 13 | C2E92B2B1D61A8E70037DE79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C2E92B2A1D61A8E70037DE79 /* Assets.xcassets */; }; 14 | C2E92B5B1D61B1710037DE79 /* FFRulerControl.m in Sources */ = {isa = PBXBuildFile; fileRef = C2E92B5A1D61B1710037DE79 /* FFRulerControl.m */; }; 15 | C2E92B5E1D61BE600037DE79 /* IBDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C2E92B5D1D61BE600037DE79 /* IBDemoViewController.m */; }; 16 | C2E92B611D61BE680037DE79 /* CodeDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C2E92B601D61BE680037DE79 /* CodeDemoViewController.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | C2E92B1B1D61A8E70037DE79 /* FFRuler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FFRuler.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | C2E92B1F1D61A8E70037DE79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | C2E92B211D61A8E70037DE79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | C2E92B221D61A8E70037DE79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | C2E92B281D61A8E70037DE79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | C2E92B2A1D61A8E70037DE79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | C2E92B2F1D61A8E70037DE79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | C2E92B591D61B1710037DE79 /* FFRulerControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FFRulerControl.h; sourceTree = ""; }; 28 | C2E92B5A1D61B1710037DE79 /* FFRulerControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FFRulerControl.m; sourceTree = ""; }; 29 | C2E92B5C1D61BE600037DE79 /* IBDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IBDemoViewController.h; sourceTree = ""; }; 30 | C2E92B5D1D61BE600037DE79 /* IBDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IBDemoViewController.m; sourceTree = ""; }; 31 | C2E92B5F1D61BE680037DE79 /* CodeDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeDemoViewController.h; sourceTree = ""; }; 32 | C2E92B601D61BE680037DE79 /* CodeDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CodeDemoViewController.m; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | C2E92B181D61A8E70037DE79 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | C2E92B121D61A8E70037DE79 = { 47 | isa = PBXGroup; 48 | children = ( 49 | C2E92B1D1D61A8E70037DE79 /* FFRuler */, 50 | C2E92B1C1D61A8E70037DE79 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | C2E92B1C1D61A8E70037DE79 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | C2E92B1B1D61A8E70037DE79 /* FFRuler.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | C2E92B1D1D61A8E70037DE79 /* FFRuler */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | C2E92B351D61AF090037DE79 /* FFRulerControl */, 66 | C2E92B211D61A8E70037DE79 /* AppDelegate.h */, 67 | C2E92B221D61A8E70037DE79 /* AppDelegate.m */, 68 | C2E92B5C1D61BE600037DE79 /* IBDemoViewController.h */, 69 | C2E92B5D1D61BE600037DE79 /* IBDemoViewController.m */, 70 | C2E92B5F1D61BE680037DE79 /* CodeDemoViewController.h */, 71 | C2E92B601D61BE680037DE79 /* CodeDemoViewController.m */, 72 | C2E92B271D61A8E70037DE79 /* Main.storyboard */, 73 | C2E92B2A1D61A8E70037DE79 /* Assets.xcassets */, 74 | C2E92B2F1D61A8E70037DE79 /* Info.plist */, 75 | C2E92B1E1D61A8E70037DE79 /* Supporting Files */, 76 | ); 77 | path = FFRuler; 78 | sourceTree = ""; 79 | }; 80 | C2E92B1E1D61A8E70037DE79 /* Supporting Files */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | C2E92B1F1D61A8E70037DE79 /* main.m */, 84 | ); 85 | name = "Supporting Files"; 86 | sourceTree = ""; 87 | }; 88 | C2E92B351D61AF090037DE79 /* FFRulerControl */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | C2E92B591D61B1710037DE79 /* FFRulerControl.h */, 92 | C2E92B5A1D61B1710037DE79 /* FFRulerControl.m */, 93 | ); 94 | path = FFRulerControl; 95 | sourceTree = ""; 96 | }; 97 | /* End PBXGroup section */ 98 | 99 | /* Begin PBXNativeTarget section */ 100 | C2E92B1A1D61A8E70037DE79 /* FFRuler */ = { 101 | isa = PBXNativeTarget; 102 | buildConfigurationList = C2E92B321D61A8E70037DE79 /* Build configuration list for PBXNativeTarget "FFRuler" */; 103 | buildPhases = ( 104 | C2E92B171D61A8E70037DE79 /* Sources */, 105 | C2E92B181D61A8E70037DE79 /* Frameworks */, 106 | C2E92B191D61A8E70037DE79 /* Resources */, 107 | ); 108 | buildRules = ( 109 | ); 110 | dependencies = ( 111 | ); 112 | name = FFRuler; 113 | productName = FFRuler; 114 | productReference = C2E92B1B1D61A8E70037DE79 /* FFRuler.app */; 115 | productType = "com.apple.product-type.application"; 116 | }; 117 | /* End PBXNativeTarget section */ 118 | 119 | /* Begin PBXProject section */ 120 | C2E92B131D61A8E70037DE79 /* Project object */ = { 121 | isa = PBXProject; 122 | attributes = { 123 | LastUpgradeCheck = 0730; 124 | ORGANIZATIONNAME = joyios; 125 | TargetAttributes = { 126 | C2E92B1A1D61A8E70037DE79 = { 127 | CreatedOnToolsVersion = 7.3.1; 128 | }; 129 | }; 130 | }; 131 | buildConfigurationList = C2E92B161D61A8E70037DE79 /* Build configuration list for PBXProject "FFRuler" */; 132 | compatibilityVersion = "Xcode 3.2"; 133 | developmentRegion = English; 134 | hasScannedForEncodings = 0; 135 | knownRegions = ( 136 | en, 137 | Base, 138 | ); 139 | mainGroup = C2E92B121D61A8E70037DE79; 140 | productRefGroup = C2E92B1C1D61A8E70037DE79 /* Products */; 141 | projectDirPath = ""; 142 | projectRoot = ""; 143 | targets = ( 144 | C2E92B1A1D61A8E70037DE79 /* FFRuler */, 145 | ); 146 | }; 147 | /* End PBXProject section */ 148 | 149 | /* Begin PBXResourcesBuildPhase section */ 150 | C2E92B191D61A8E70037DE79 /* Resources */ = { 151 | isa = PBXResourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | C2E92B2B1D61A8E70037DE79 /* Assets.xcassets in Resources */, 155 | C2E92B291D61A8E70037DE79 /* Main.storyboard in Resources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXSourcesBuildPhase section */ 162 | C2E92B171D61A8E70037DE79 /* Sources */ = { 163 | isa = PBXSourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | C2E92B611D61BE680037DE79 /* CodeDemoViewController.m in Sources */, 167 | C2E92B5E1D61BE600037DE79 /* IBDemoViewController.m in Sources */, 168 | C2E92B231D61A8E70037DE79 /* AppDelegate.m in Sources */, 169 | C2E92B5B1D61B1710037DE79 /* FFRulerControl.m in Sources */, 170 | C2E92B201D61A8E70037DE79 /* main.m in Sources */, 171 | ); 172 | runOnlyForDeploymentPostprocessing = 0; 173 | }; 174 | /* End PBXSourcesBuildPhase section */ 175 | 176 | /* Begin PBXVariantGroup section */ 177 | C2E92B271D61A8E70037DE79 /* Main.storyboard */ = { 178 | isa = PBXVariantGroup; 179 | children = ( 180 | C2E92B281D61A8E70037DE79 /* Base */, 181 | ); 182 | name = Main.storyboard; 183 | sourceTree = ""; 184 | }; 185 | /* End PBXVariantGroup section */ 186 | 187 | /* Begin XCBuildConfiguration section */ 188 | C2E92B301D61A8E70037DE79 /* Debug */ = { 189 | isa = XCBuildConfiguration; 190 | buildSettings = { 191 | ALWAYS_SEARCH_USER_PATHS = NO; 192 | CLANG_ANALYZER_NONNULL = YES; 193 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 194 | CLANG_CXX_LIBRARY = "libc++"; 195 | CLANG_ENABLE_MODULES = YES; 196 | CLANG_ENABLE_OBJC_ARC = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_CONSTANT_CONVERSION = YES; 199 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 200 | CLANG_WARN_EMPTY_BODY = YES; 201 | CLANG_WARN_ENUM_CONVERSION = YES; 202 | CLANG_WARN_INT_CONVERSION = YES; 203 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 204 | CLANG_WARN_UNREACHABLE_CODE = YES; 205 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 206 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 207 | COPY_PHASE_STRIP = NO; 208 | DEBUG_INFORMATION_FORMAT = dwarf; 209 | ENABLE_STRICT_OBJC_MSGSEND = YES; 210 | ENABLE_TESTABILITY = YES; 211 | GCC_C_LANGUAGE_STANDARD = gnu99; 212 | GCC_DYNAMIC_NO_PIC = NO; 213 | GCC_NO_COMMON_BLOCKS = YES; 214 | GCC_OPTIMIZATION_LEVEL = 0; 215 | GCC_PREPROCESSOR_DEFINITIONS = ( 216 | "DEBUG=1", 217 | "$(inherited)", 218 | ); 219 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 220 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 221 | GCC_WARN_UNDECLARED_SELECTOR = YES; 222 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 223 | GCC_WARN_UNUSED_FUNCTION = YES; 224 | GCC_WARN_UNUSED_VARIABLE = YES; 225 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 226 | MTL_ENABLE_DEBUG_INFO = YES; 227 | ONLY_ACTIVE_ARCH = YES; 228 | SDKROOT = iphoneos; 229 | }; 230 | name = Debug; 231 | }; 232 | C2E92B311D61A8E70037DE79 /* Release */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | ALWAYS_SEARCH_USER_PATHS = NO; 236 | CLANG_ANALYZER_NONNULL = YES; 237 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 238 | CLANG_CXX_LIBRARY = "libc++"; 239 | CLANG_ENABLE_MODULES = YES; 240 | CLANG_ENABLE_OBJC_ARC = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_CONSTANT_CONVERSION = YES; 243 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 244 | CLANG_WARN_EMPTY_BODY = YES; 245 | CLANG_WARN_ENUM_CONVERSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 248 | CLANG_WARN_UNREACHABLE_CODE = YES; 249 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 250 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 251 | COPY_PHASE_STRIP = NO; 252 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 253 | ENABLE_NS_ASSERTIONS = NO; 254 | ENABLE_STRICT_OBJC_MSGSEND = YES; 255 | GCC_C_LANGUAGE_STANDARD = gnu99; 256 | GCC_NO_COMMON_BLOCKS = YES; 257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 259 | GCC_WARN_UNDECLARED_SELECTOR = YES; 260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 261 | GCC_WARN_UNUSED_FUNCTION = YES; 262 | GCC_WARN_UNUSED_VARIABLE = YES; 263 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 264 | MTL_ENABLE_DEBUG_INFO = NO; 265 | SDKROOT = iphoneos; 266 | VALIDATE_PRODUCT = YES; 267 | }; 268 | name = Release; 269 | }; 270 | C2E92B331D61A8E70037DE79 /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets"; 275 | INFOPLIST_FILE = FFRuler/Info.plist; 276 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 277 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 278 | PRODUCT_BUNDLE_IDENTIFIER = com.joyios.FFRuler; 279 | PRODUCT_NAME = "$(TARGET_NAME)"; 280 | }; 281 | name = Debug; 282 | }; 283 | C2E92B341D61A8E70037DE79 /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets"; 288 | INFOPLIST_FILE = FFRuler/Info.plist; 289 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = com.joyios.FFRuler; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | }; 294 | name = Release; 295 | }; 296 | /* End XCBuildConfiguration section */ 297 | 298 | /* Begin XCConfigurationList section */ 299 | C2E92B161D61A8E70037DE79 /* Build configuration list for PBXProject "FFRuler" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | C2E92B301D61A8E70037DE79 /* Debug */, 303 | C2E92B311D61A8E70037DE79 /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | C2E92B321D61A8E70037DE79 /* Build configuration list for PBXNativeTarget "FFRuler" */ = { 309 | isa = XCConfigurationList; 310 | buildConfigurations = ( 311 | C2E92B331D61A8E70037DE79 /* Debug */, 312 | C2E92B341D61A8E70037DE79 /* Release */, 313 | ); 314 | defaultConfigurationIsVisible = 0; 315 | }; 316 | /* End XCConfigurationList section */ 317 | }; 318 | rootObject = C2E92B131D61A8E70037DE79 /* Project object */; 319 | } 320 | -------------------------------------------------------------------------------- /FFRuler/FFRuler.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "extent" : "full-screen", 5 | "idiom" : "iphone", 6 | "subtype" : "736h", 7 | "filename" : "iPhone 6 Plus.png", 8 | "minimum-system-version" : "8.0", 9 | "orientation" : "portrait", 10 | "scale" : "3x" 11 | }, 12 | { 13 | "extent" : "full-screen", 14 | "idiom" : "iphone", 15 | "subtype" : "667h", 16 | "filename" : "iPhone 6.png", 17 | "minimum-system-version" : "8.0", 18 | "orientation" : "portrait", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "orientation" : "portrait", 23 | "idiom" : "iphone", 24 | "extent" : "full-screen", 25 | "minimum-system-version" : "7.0", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "extent" : "full-screen", 30 | "idiom" : "iphone", 31 | "subtype" : "retina4", 32 | "filename" : "iPhone SE.png", 33 | "minimum-system-version" : "7.0", 34 | "orientation" : "portrait", 35 | "scale" : "2x" 36 | } 37 | ], 38 | "info" : { 39 | "version" : 1, 40 | "author" : "xcode" 41 | } 42 | } -------------------------------------------------------------------------------- /FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone 6 Plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufan321/FFRuler/504a68f472aafa6112adec9dc9ca2fb73ac38b81/FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone 6 Plus.png -------------------------------------------------------------------------------- /FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone 6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufan321/FFRuler/504a68f472aafa6112adec9dc9ca2fb73ac38b81/FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone 6.png -------------------------------------------------------------------------------- /FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone SE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufan321/FFRuler/504a68f472aafa6112adec9dc9ca2fb73ac38b81/FFRuler/FFRuler/Assets.xcassets/Brand Assets.launchimage/iPhone SE.png -------------------------------------------------------------------------------- /FFRuler/FFRuler/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 85 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/CodeDemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CodeDemoViewController.h 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CodeDemoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/CodeDemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CodeDemoViewController.m 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import "CodeDemoViewController.h" 10 | #import "FFRulerControl.h" 11 | 12 | @interface CodeDemoViewController () 13 | @property (weak, nonatomic) IBOutlet UILabel *weightLabel; 14 | @end 15 | 16 | @implementation CodeDemoViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | FFRulerControl *ruler = [[FFRulerControl alloc] initWithFrame:CGRectMake(0, 0, 300, 120)]; 22 | ruler.center = self.view.center; 23 | 24 | [self.view addSubview:ruler]; 25 | 26 | ruler.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1]; 27 | 28 | // 最小值 29 | ruler.minValue = 10; 30 | // 最大值 31 | ruler.maxValue = 100; 32 | // 数值步长 33 | ruler.valueStep = 5; 34 | // 设置默认值 35 | ruler.selectedValue = 80; 36 | 37 | // 添加监听方法 38 | [ruler addTarget:self action:@selector(weightChanged:) forControlEvents:UIControlEventValueChanged]; 39 | } 40 | 41 | - (void)weightChanged:(FFRulerControl *)ruler { 42 | _weightLabel.text = [NSString stringWithFormat:@"体重: %.02f kg", ruler.selectedValue]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/FFRulerControl/FFRulerControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // FFRulerControl.h 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * 轻量级标尺控件 13 | */ 14 | IB_DESIGNABLE 15 | @interface FFRulerControl : UIControl 16 | 17 | /** 18 | * 选中的数值 19 | */ 20 | @property (nonatomic, assign) IBInspectable CGFloat selectedValue; 21 | 22 | /** 23 | * 垂直滚动,默认 NO 24 | */ 25 | @property (nonatomic, assign, getter=isVerticalScroll) IBInspectable BOOL verticalScroll; 26 | 27 | /** 28 | * 最小值 29 | */ 30 | @property (nonatomic, assign) IBInspectable NSInteger minValue; 31 | /** 32 | * 最大值 33 | */ 34 | @property (nonatomic, assign) IBInspectable NSInteger maxValue; 35 | /** 36 | * 步长 37 | */ 38 | @property (nonatomic, assign) IBInspectable NSInteger valueStep; 39 | 40 | /** 41 | * 小刻度间距,默认值 `8.0` 42 | */ 43 | @property (nonatomic, assign) IBInspectable CGFloat minorScaleSpacing; 44 | 45 | /** 46 | * 主刻度长度,默认值 `40.0` 47 | */ 48 | @property (nonatomic, assign) IBInspectable CGFloat majorScaleLength; 49 | /** 50 | * 中间刻度长度,默认值 `25.0` 51 | */ 52 | @property (nonatomic, assign) IBInspectable CGFloat middleScaleLength; 53 | /** 54 | * 小刻度长度,默认值 `10.0` 55 | */ 56 | @property (nonatomic, assign) IBInspectable CGFloat minorScaleLength; 57 | 58 | /** 59 | * 刻度尺背景颜色,默认为 `clearColor` 60 | */ 61 | @property (nonatomic, strong) IBInspectable UIColor *rulerBackgroundColor; 62 | /** 63 | * 刻度颜色,默认为 `lightGrayColor` 64 | */ 65 | @property (nonatomic, strong) IBInspectable UIColor *scaleColor; 66 | 67 | /** 68 | * 刻度字体颜色,默认为 `darkGrayColor` 69 | */ 70 | @property (nonatomic, strong) IBInspectable UIColor *scaleFontColor; 71 | /** 72 | * 刻度字体尺寸,默认为 `10.0` 73 | */ 74 | @property (nonatomic, assign) IBInspectable CGFloat scaleFontSize; 75 | 76 | /** 77 | * 指示器颜色,默认 `redColor` 78 | */ 79 | @property (nonatomic, strong) IBInspectable UIColor *indicatorColor; 80 | /** 81 | * 指示器长度,默认值为 `40.0` 82 | */ 83 | @property (nonatomic, assign) IBInspectable CGFloat indicatorLength; 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/FFRulerControl/FFRulerControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // FFRulerControl.m 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import "FFRulerControl.h" 10 | 11 | /** 12 | * 小刻度间距默认值 13 | */ 14 | #define kMinorScaleDefaultSpacing 8.0 15 | 16 | /** 17 | * 主刻度长度默认值 18 | */ 19 | #define kMajorScaleDefaultLength 40.0 20 | /** 21 | * 中间刻度长度默认值 22 | */ 23 | #define kMiddleScaleDefaultLength 25.0 24 | /** 25 | * 小刻度长度默认值 26 | */ 27 | #define kMinorScaleDefaultLength 10.0 28 | /** 29 | * 刻度尺背景颜色默认值 30 | */ 31 | #define kRulerDefaultBackgroundColor ([UIColor clearColor]) 32 | /** 33 | * 刻度颜色默认值 34 | */ 35 | #define kScaleDefaultColor ([UIColor lightGrayColor]) 36 | 37 | /** 38 | * 刻度字体颜色默认值 39 | */ 40 | #define kScaleDefaultFontColor ([UIColor darkGrayColor]) 41 | /** 42 | * 刻度字体默认值 43 | */ 44 | #define kScaleDefaultFontSize 10.0 45 | 46 | /** 47 | * 指示器默认颜色 48 | */ 49 | #define kIndicatorDefaultColor ([UIColor redColor]) 50 | /** 51 | * 指示器长度默认值 52 | */ 53 | #define kIndicatorDefaultLength 40.0 54 | 55 | @interface FFRulerControl() 56 | 57 | @end 58 | 59 | @implementation FFRulerControl { 60 | UIScrollView *_scrollView; 61 | UIImageView *_rulerImageView; 62 | UIView *_indicatorView; 63 | } 64 | 65 | #pragma mark - 构造函数 66 | - (instancetype)initWithFrame:(CGRect)frame { 67 | self = [super initWithFrame:frame]; 68 | if (self) { 69 | [self setupUI]; 70 | } 71 | return self; 72 | } 73 | 74 | - (instancetype)initWithCoder:(NSCoder *)coder { 75 | self = [super initWithCoder:coder]; 76 | if (self) { 77 | [self setupUI]; 78 | } 79 | return self; 80 | } 81 | 82 | - (void)layoutSubviews { 83 | [super layoutSubviews]; 84 | 85 | if (_rulerImageView.image == nil) { 86 | [self reloadRuler]; 87 | } 88 | 89 | CGSize size = self.bounds.size; 90 | 91 | if (_verticalScroll) { 92 | _indicatorView.frame = CGRectMake(0, size.height * 0.5, self.indicatorLength, 1); 93 | } else { 94 | _indicatorView.frame = CGRectMake(size.width * 0.5, size.height - self.indicatorLength, 1, self.indicatorLength); 95 | } 96 | 97 | // 设置滚动视图内容间距 98 | CGSize textSize = [self maxValueTextSize]; 99 | if (_verticalScroll) { 100 | CGFloat offset = size.height * 0.5 - textSize.width; 101 | 102 | _scrollView.contentInset = UIEdgeInsetsMake(offset, 0, offset, 0); 103 | } else { 104 | CGFloat offset = size.width * 0.5 - textSize.width; 105 | 106 | _scrollView.contentInset = UIEdgeInsetsMake(0, offset, 0, offset); 107 | } 108 | } 109 | 110 | #pragma mark - 设置属性 111 | - (void)setIndicatorColor:(UIColor *)indicatorColor { 112 | _indicatorView.backgroundColor = indicatorColor; 113 | } 114 | 115 | - (void)setSelectedValue:(CGFloat)selectedValue { 116 | if (selectedValue < _minValue || selectedValue > _maxValue || _valueStep <= 0) { 117 | return; 118 | } 119 | 120 | _selectedValue = selectedValue; 121 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 122 | 123 | CGFloat spacing = self.minorScaleSpacing; 124 | CGSize size = self.bounds.size; 125 | CGSize textSize = [self maxValueTextSize]; 126 | CGFloat offset = 0; 127 | 128 | // 计算偏移量 129 | CGFloat steps = [self stepsWithValue:selectedValue]; 130 | 131 | if (_verticalScroll) { 132 | offset = size.height * 0.5 - textSize.width - steps * spacing; 133 | 134 | _scrollView.contentOffset = CGPointMake(0, -offset); 135 | } else { 136 | offset = size.width * 0.5 - textSize.width - steps * spacing; 137 | 138 | _scrollView.contentOffset = CGPointMake(-offset, 0); 139 | } 140 | } 141 | 142 | #pragma mark - UIScrollViewDelegate 143 | - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 144 | 145 | CGFloat spacing = self.minorScaleSpacing; 146 | CGSize size = self.bounds.size; 147 | CGSize textSize = [self maxValueTextSize]; 148 | 149 | if (_verticalScroll) { 150 | CGFloat offset = targetContentOffset->y + size.height * 0.5 - textSize.width; 151 | NSInteger steps = (NSInteger)(offset / spacing + 0.5); 152 | 153 | targetContentOffset->y = -(size.height * 0.5 - textSize.width - steps * spacing) - 0.5; 154 | } else { 155 | CGFloat offset = targetContentOffset->x + size.width * 0.5 - textSize.width; 156 | NSInteger steps = (NSInteger)(offset / spacing + 0.5); 157 | 158 | targetContentOffset->x = -(size.width * 0.5 - textSize.width - steps * spacing) - 0.5; 159 | } 160 | } 161 | 162 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 163 | 164 | if (!(scrollView.isDragging || scrollView.isTracking || scrollView.isDecelerating)) { 165 | return; 166 | } 167 | 168 | CGFloat spacing = self.minorScaleSpacing; 169 | CGSize size = self.bounds.size; 170 | CGSize textSize = [self maxValueTextSize]; 171 | 172 | CGFloat offset = 0; 173 | if (_verticalScroll) { 174 | offset = scrollView.contentOffset.y + size.height * 0.5 - textSize.width; 175 | } else { 176 | offset = scrollView.contentOffset.x + size.width * 0.5 - textSize.width; 177 | } 178 | 179 | NSInteger steps = (NSInteger)(offset / spacing + 0.5); 180 | CGFloat value = _minValue + steps * _valueStep / 10.0; 181 | 182 | if (value != _selectedValue && (value >= _minValue && value <= _maxValue)) { 183 | _selectedValue = value; 184 | 185 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 186 | } 187 | } 188 | 189 | #pragma mark - 绘制标尺相关方法 190 | /** 191 | * 刷新标尺 192 | */ 193 | - (void)reloadRuler { 194 | UIImage *image = [self rulerImage]; 195 | 196 | if (image == nil) { 197 | return; 198 | } 199 | 200 | _rulerImageView.image = image; 201 | _rulerImageView.backgroundColor = self.rulerBackgroundColor; 202 | 203 | [_rulerImageView sizeToFit]; 204 | _scrollView.contentSize = _rulerImageView.image.size; 205 | 206 | // 水平标尺靠下对齐 207 | if (!_verticalScroll) { 208 | CGRect rect = _rulerImageView.frame; 209 | rect.origin.y = _scrollView.bounds.size.height - _rulerImageView.image.size.height; 210 | _rulerImageView.frame = rect; 211 | } 212 | 213 | // 更新初始值 214 | self.selectedValue = _selectedValue; 215 | } 216 | 217 | /** 218 | * 生成标尺图像 219 | */ 220 | - (UIImage *)rulerImage { 221 | 222 | // 1. 常数计算 223 | CGFloat steps = [self stepsWithValue:_maxValue]; 224 | if (steps == 0) { 225 | return nil; 226 | } 227 | 228 | // 水平方向绘制图像的大小 229 | CGSize textSize = [self maxValueTextSize]; 230 | CGFloat height = self.majorScaleLength + textSize.height + 2 * self.minorScaleSpacing; 231 | CGFloat startX = textSize.width; 232 | CGRect rect = CGRectMake(0, 0, steps * self.minorScaleSpacing + 2 * startX, height); 233 | 234 | // 2. 绘制图像 235 | UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); 236 | 237 | // 1> 绘制刻度线 238 | UIBezierPath *path = [UIBezierPath bezierPath]; 239 | 240 | for (NSInteger i = _minValue; i <= _maxValue; i += _valueStep) { 241 | 242 | // 绘制主刻度 243 | CGFloat x = (i - _minValue) / _valueStep * self.minorScaleSpacing * 10 + startX; 244 | [path moveToPoint:CGPointMake(x, height)]; 245 | [path addLineToPoint:CGPointMake(x, height - self.majorScaleLength)]; 246 | 247 | if (i == _maxValue) { 248 | break; 249 | } 250 | 251 | // 绘制小刻度线 252 | for (NSInteger j = 1; j < 10; j++) { 253 | CGFloat scaleX = x + j * self.minorScaleSpacing; 254 | [path moveToPoint:CGPointMake(scaleX, height)]; 255 | 256 | CGFloat scaleY = height - ((j == 5) ? self.middleScaleLength : self.minorScaleLength); 257 | [path addLineToPoint:CGPointMake(scaleX, scaleY)]; 258 | } 259 | } 260 | 261 | [self.scaleColor set]; 262 | [path stroke]; 263 | 264 | // 2> 绘制刻度值 265 | NSDictionary *strAttributes = [self scaleTextAttributes]; 266 | 267 | for (NSInteger i = _minValue; i <= _maxValue; i += _valueStep) { 268 | NSString *str = @(i).description; 269 | 270 | CGRect strRect = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) 271 | options:NSStringDrawingUsesLineFragmentOrigin 272 | attributes:strAttributes 273 | context:nil]; 274 | strRect.origin.x = (i - _minValue) / _valueStep * self.minorScaleSpacing * 10 + startX - strRect.size.width * 0.5; 275 | strRect.origin.y = 8; 276 | 277 | [str drawInRect:strRect withAttributes:strAttributes]; 278 | } 279 | 280 | UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 281 | 282 | UIGraphicsEndImageContext(); 283 | 284 | // 3. 旋转图像 285 | if (!_verticalScroll) { 286 | return result; 287 | } 288 | 289 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(rect.size.height, rect.size.width), NO, 0); 290 | CGContextRotateCTM(UIGraphicsGetCurrentContext(), M_PI_2); 291 | CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, -result.size.height); 292 | 293 | [result drawInRect:rect]; 294 | 295 | result = UIGraphicsGetImageFromCurrentImageContext(); 296 | 297 | UIGraphicsEndImageContext(); 298 | 299 | return result; 300 | } 301 | 302 | /** 303 | * 计算最小值和指定 value 之间的步长,即:绘制刻度的总数量 304 | */ 305 | - (CGFloat)stepsWithValue:(CGFloat)value { 306 | 307 | if (_minValue >= value || _valueStep <= 0) { 308 | return 0; 309 | } 310 | 311 | return (value - _minValue) / _valueStep * 10; 312 | } 313 | 314 | /** 315 | * 以水平绘制方向计算 `最大数值的文字` 尺寸 316 | */ 317 | - (CGSize)maxValueTextSize { 318 | 319 | NSString *scaleText = @(self.maxValue).description; 320 | 321 | CGSize size = [scaleText boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) 322 | options:NSStringDrawingUsesLineFragmentOrigin 323 | attributes:[self scaleTextAttributes] 324 | context:nil].size; 325 | 326 | return CGSizeMake(floor(size.width), floor(size.height)); 327 | } 328 | 329 | /** 330 | * 文本属性字典 331 | */ 332 | - (NSDictionary *)scaleTextAttributes { 333 | 334 | CGFloat fontSize = self.scaleFontSize * [UIScreen mainScreen].scale * 0.5; 335 | 336 | return @{NSForegroundColorAttributeName: self.scaleFontColor, 337 | NSFontAttributeName: [UIFont boldSystemFontOfSize:fontSize]}; 338 | } 339 | 340 | #pragma mark - 设置界面 341 | - (void)setupUI { 342 | // 默认水平方向滚动 343 | _verticalScroll = NO; 344 | 345 | // 滚动视图 346 | _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; 347 | 348 | _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 349 | _scrollView.showsVerticalScrollIndicator = NO; 350 | _scrollView.showsHorizontalScrollIndicator = NO; 351 | 352 | _scrollView.delegate = self; 353 | 354 | [self addSubview:_scrollView]; 355 | 356 | // 标尺图像 357 | _rulerImageView = [[UIImageView alloc] init]; 358 | 359 | [_scrollView addSubview:_rulerImageView]; 360 | 361 | // 指示器视图 362 | _indicatorView = [[UIView alloc] init]; 363 | _indicatorView.backgroundColor = self.indicatorColor; 364 | 365 | [self addSubview:_indicatorView]; 366 | } 367 | 368 | #pragma mark - 属性默认值 369 | - (CGFloat)minorScaleSpacing { 370 | if (_minorScaleSpacing <= 0) { 371 | _minorScaleSpacing = kMinorScaleDefaultSpacing; 372 | } 373 | return _minorScaleSpacing; 374 | } 375 | 376 | - (CGFloat)majorScaleLength { 377 | if (_majorScaleLength <= 0) { 378 | _majorScaleLength = kMajorScaleDefaultLength; 379 | } 380 | return _majorScaleLength; 381 | } 382 | 383 | - (CGFloat)middleScaleLength { 384 | if (_middleScaleLength <= 0) { 385 | _middleScaleLength = kMiddleScaleDefaultLength; 386 | } 387 | return _middleScaleLength; 388 | } 389 | 390 | - (CGFloat)minorScaleLength { 391 | if (_minorScaleLength <= 0) { 392 | _minorScaleLength = kMinorScaleDefaultLength; 393 | } 394 | return _minorScaleLength; 395 | } 396 | 397 | - (UIColor *)rulerBackgroundColor { 398 | if (_rulerBackgroundColor == nil) { 399 | _rulerBackgroundColor = kRulerDefaultBackgroundColor; 400 | } 401 | return _rulerBackgroundColor; 402 | } 403 | 404 | - (UIColor *)scaleColor { 405 | if (_scaleColor == nil) { 406 | _scaleColor = kScaleDefaultColor; 407 | } 408 | return _scaleColor; 409 | } 410 | 411 | - (UIColor *)scaleFontColor { 412 | if (_scaleFontColor == nil) { 413 | _scaleFontColor = kScaleDefaultFontColor; 414 | } 415 | return _scaleFontColor; 416 | } 417 | 418 | - (CGFloat)scaleFontSize { 419 | if (_scaleFontSize <= 0) { 420 | _scaleFontSize = kScaleDefaultFontSize; 421 | } 422 | return _scaleFontSize; 423 | } 424 | 425 | - (UIColor *)indicatorColor { 426 | if (_indicatorView.backgroundColor == nil) { 427 | _indicatorView.backgroundColor = kIndicatorDefaultColor; 428 | } 429 | return _indicatorView.backgroundColor; 430 | } 431 | 432 | - (CGFloat)indicatorLength { 433 | if (_indicatorLength <= 0) { 434 | _indicatorLength = kIndicatorDefaultLength; 435 | } 436 | return _indicatorLength; 437 | } 438 | 439 | @end 440 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/IBDemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // IBDemoViewController.h 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface IBDemoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/IBDemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // IBDemoViewController.m 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import "IBDemoViewController.h" 10 | #import "FFRulerControl.h" 11 | 12 | @interface IBDemoViewController () 13 | @property (weak, nonatomic) IBOutlet UILabel *heightLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *weightLabel; 15 | @end 16 | 17 | @implementation IBDemoViewController 18 | 19 | - (IBAction)heightChanged:(FFRulerControl *)sender { 20 | _heightLabel.text = [NSString stringWithFormat:@"身高: %.02f cm", sender.selectedValue]; 21 | } 22 | 23 | - (IBAction)weightChanged:(FFRulerControl *)sender { 24 | _weightLabel.text = [NSString stringWithFormat:@"体重: %.02f kg", sender.selectedValue]; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /FFRuler/FFRuler/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // FFRuler 4 | // 5 | // Created by 刘凡 on 2016/8/15. 6 | // Copyright © 2016年 joyios. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 刘凡 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FFRuler 2 | 3 | 轻量级刻度尺控件 4 | 5 | ## 功能 6 | 7 | * 简单/灵活/小巧的刻度尺控件 8 | 9 | ## 屏幕截图 10 | 11 | ![](https://github.com/liufan321/FFRuler/blob/master/screenshots/screenshots.gif?raw=true">) 12 | 13 | ## 系统支持 14 | 15 | * iOS 7.0+ 16 | * Xcode 7.0 17 | 18 | ## 安装 19 | 20 | ### CocoaPods 21 | 22 | * 进入终端,`cd` 到项目目录,输入以下命令,建立 `Podfile` 23 | 24 | ```bash 25 | $ pod init 26 | ``` 27 | 28 | * 在 Podfile 中输入以下内容: 29 | 30 | ``` 31 | platform :ios, '7.0' 32 | use_frameworks! 33 | 34 | target 'FFRulerDemo' do 35 | pod 'FFRuler' 36 | end 37 | ``` 38 | 39 | * 在终端中输入以下命令,安装或升级 Pod 40 | 41 | ```bash 42 | # 安装 Pod,第一次使用 43 | $ pod install 44 | 45 | # 升级 Pod,后续使用 46 | $ pod update 47 | ``` 48 | 49 | ## 使用 50 | 51 | * 代码示例 52 | 53 | ```objc 54 | #import "FFRulerControl.h" 55 | 56 | @interface CodeDemoViewController () 57 | @property (weak, nonatomic) IBOutlet UILabel *weightLabel; 58 | @end 59 | 60 | @implementation CodeDemoViewController 61 | 62 | - (void)viewDidLoad { 63 | [super viewDidLoad]; 64 | 65 | FFRulerControl *ruler = [[FFRulerControl alloc] initWithFrame:CGRectMake(0, 0, 300, 120)]; 66 | ruler.center = self.view.center; 67 | 68 | [self.view addSubview:ruler]; 69 | 70 | ruler.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1]; 71 | 72 | // 最小值 73 | ruler.minValue = 10; 74 | // 最大值 75 | ruler.maxValue = 100; 76 | // 数值步长 77 | ruler.valueStep = 5; 78 | // 设置默认值 79 | ruler.selectedValue = 80; 80 | 81 | // 添加监听方法 82 | [ruler addTarget:self action:@selector(weightChanged:) forControlEvents:UIControlEventValueChanged]; 83 | } 84 | 85 | - (void)weightChanged:(FFRulerControl *)ruler { 86 | _weightLabel.text = [NSString stringWithFormat:@"体重: %.02f kg", ruler.selectedValue]; 87 | } 88 | 89 | @end 90 | ``` 91 | 92 | * 也可以直接使用 Interface Builder 设置所有属性,并且连接 `IBAction` 93 | 94 | ```objc 95 | - (IBAction)weightChanged:(FFRulerControl *)sender { 96 | _weightLabel.text = [NSString stringWithFormat:@"体重: %.02f kg", sender.selectedValue]; 97 | } 98 | ``` 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /screenshots/screenshots.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufan321/FFRuler/504a68f472aafa6112adec9dc9ca2fb73ac38b81/screenshots/screenshots.gif --------------------------------------------------------------------------------