├── .gitignore ├── .travis.yml ├── Example ├── LGLBaseKit.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── LGLBaseKit-Example.xcscheme ├── LGLBaseKit.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── LGLBaseKit │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── Podfile ├── Podfile.lock ├── Pods │ ├── Local Podspecs │ │ └── LGLBaseKit.podspec.json │ ├── Manifest.lock │ ├── Pods.xcodeproj │ │ └── project.pbxproj │ └── Target Support Files │ │ ├── LGLBaseKit │ │ ├── LGLBaseKit-Info.plist │ │ ├── LGLBaseKit-dummy.m │ │ ├── LGLBaseKit-prefix.pch │ │ ├── LGLBaseKit-umbrella.h │ │ ├── LGLBaseKit.modulemap │ │ └── LGLBaseKit.xcconfig │ │ ├── Pods-LGLBaseKit_Example │ │ ├── Pods-LGLBaseKit_Example-Info.plist │ │ ├── Pods-LGLBaseKit_Example-acknowledgements.markdown │ │ ├── Pods-LGLBaseKit_Example-acknowledgements.plist │ │ ├── Pods-LGLBaseKit_Example-dummy.m │ │ ├── Pods-LGLBaseKit_Example-frameworks.sh │ │ ├── Pods-LGLBaseKit_Example-umbrella.h │ │ ├── Pods-LGLBaseKit_Example.debug.xcconfig │ │ ├── Pods-LGLBaseKit_Example.modulemap │ │ └── Pods-LGLBaseKit_Example.release.xcconfig │ │ └── Pods-LGLBaseKit_Tests │ │ ├── Pods-LGLBaseKit_Tests-Info.plist │ │ ├── Pods-LGLBaseKit_Tests-acknowledgements.markdown │ │ ├── Pods-LGLBaseKit_Tests-acknowledgements.plist │ │ ├── Pods-LGLBaseKit_Tests-dummy.m │ │ ├── Pods-LGLBaseKit_Tests-umbrella.h │ │ ├── Pods-LGLBaseKit_Tests.debug.xcconfig │ │ ├── Pods-LGLBaseKit_Tests.modulemap │ │ └── Pods-LGLBaseKit_Tests.release.xcconfig └── Tests │ ├── Info.plist │ └── Tests.swift ├── LGLBaseKit.podspec ├── LGLBaseKit ├── Assets │ └── .gitkeep └── Classes │ ├── .gitkeep │ ├── LGLAlert │ ├── LGLAlert.swift │ └── LGLShowText.swift │ ├── LGLCrypt │ ├── BaseCrypt.swift │ └── LGLCrypt.swift │ ├── LGLDeviceInfo │ ├── LGLDevice.swift │ └── LGLDeviceSystem.swift │ ├── LGLExtension │ ├── NSRegularExpression+Extension.swift │ ├── NotificationCenter+Extension.swift │ ├── String+Extension.swift │ ├── UIBarButtonItem+Extension.swift │ ├── UIButton+Extension.swift │ ├── UIColor+Extension.swift │ ├── UIImage+Extension.swift │ ├── UIImageView+Extension.swift │ ├── UILabel+Extension.swift │ ├── UINavigationController+Extension.swift │ ├── UITabBarController+Extension.swift │ ├── UITextField+Extension.swift │ └── UIView+Extension.swift │ └── LGLPublicMethod │ └── LGLMethod.swift ├── LICENSE ├── README.md └── _Pods.xcodeproj /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 26 | # Carthage/Checkouts 27 | 28 | Carthage/Build 29 | 30 | # We recommend against adding the Pods directory to your .gitignore. However 31 | # you should judge for yourself, the pros and cons are mentioned at: 32 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 33 | # 34 | # Note: if you ignore the Pods directory, make sure to uncomment 35 | # `pod install` in .travis.yml 36 | # 37 | # Pods/ 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * https://www.objc.io/issues/6-build-tools/travis-ci/ 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | osx_image: xcode7.3 6 | language: objective-c 7 | # cache: cocoapods 8 | # podfile: Example/Podfile 9 | # before_install: 10 | # - gem install cocoapods # Since Travis is not always on latest version 11 | # - pod install --project-directory=Example 12 | script: 13 | - set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/LGLBaseKit.xcworkspace -scheme LGLBaseKit-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty 14 | - pod lib lint 15 | -------------------------------------------------------------------------------- /Example/LGLBaseKit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 595950181894D9318708904D /* Pods_LGLBaseKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD652C765CEAA66B4B706C65 /* Pods_LGLBaseKit_Example.framework */; }; 11 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 12 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 13 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; 14 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 15 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 16 | 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; }; 17 | B66A92E46475CA0314E7AF21 /* Pods_LGLBaseKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EAC2AEBA89549D844860CE2 /* Pods_LGLBaseKit_Tests.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 607FACC81AFB9204008FA782 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 607FACCF1AFB9204008FA782; 26 | remoteInfo = LGLBaseKit; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 1A687A126AC95AE744A5745C /* Pods-LGLBaseKit_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGLBaseKit_Tests.debug.xcconfig"; path = "Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests.debug.xcconfig"; sourceTree = ""; }; 32 | 1E83F080006E9DA9455205B3 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 33 | 24CF234EA86D7C3C9574B820 /* Pods-LGLBaseKit_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGLBaseKit_Tests.release.xcconfig"; path = "Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests.release.xcconfig"; sourceTree = ""; }; 34 | 4EAC2AEBA89549D844860CE2 /* Pods_LGLBaseKit_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LGLBaseKit_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 607FACD01AFB9204008FA782 /* LGLBaseKit_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LGLBaseKit_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 38 | 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 39 | 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 41 | 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 42 | 607FACE51AFB9204008FA782 /* LGLBaseKit_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LGLBaseKit_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; 45 | 6F1DDD1834B79EC9DEB740C5 /* Pods-LGLBaseKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGLBaseKit_Example.release.xcconfig"; path = "Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example.release.xcconfig"; sourceTree = ""; }; 46 | 7A29A6A0C0FEFC6FA70DA46E /* Pods-LGLBaseKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGLBaseKit_Example.debug.xcconfig"; path = "Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example.debug.xcconfig"; sourceTree = ""; }; 47 | CD652C765CEAA66B4B706C65 /* Pods_LGLBaseKit_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LGLBaseKit_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | DFF88B267FE9956DF8761F59 /* LGLBaseKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LGLBaseKit.podspec; path = ../LGLBaseKit.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 49 | EEB63EB4B0A33359DB1CEB45 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | 595950181894D9318708904D /* Pods_LGLBaseKit_Example.framework in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 607FACE21AFB9204008FA782 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | B66A92E46475CA0314E7AF21 /* Pods_LGLBaseKit_Tests.framework in Frameworks */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXFrameworksBuildPhase section */ 70 | 71 | /* Begin PBXGroup section */ 72 | 607FACC71AFB9204008FA782 = { 73 | isa = PBXGroup; 74 | children = ( 75 | 607FACF51AFB993E008FA782 /* Podspec Metadata */, 76 | 607FACD21AFB9204008FA782 /* Example for LGLBaseKit */, 77 | 607FACE81AFB9204008FA782 /* Tests */, 78 | 607FACD11AFB9204008FA782 /* Products */, 79 | 63BB65452C5F5EE6722B49BA /* Pods */, 80 | 77D03356161B59BF499F6BC1 /* Frameworks */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | 607FACD11AFB9204008FA782 /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 607FACD01AFB9204008FA782 /* LGLBaseKit_Example.app */, 88 | 607FACE51AFB9204008FA782 /* LGLBaseKit_Tests.xctest */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 607FACD21AFB9204008FA782 /* Example for LGLBaseKit */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */, 97 | 607FACD71AFB9204008FA782 /* ViewController.swift */, 98 | 607FACD91AFB9204008FA782 /* Main.storyboard */, 99 | 607FACDC1AFB9204008FA782 /* Images.xcassets */, 100 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 101 | 607FACD31AFB9204008FA782 /* Supporting Files */, 102 | ); 103 | name = "Example for LGLBaseKit"; 104 | path = LGLBaseKit; 105 | sourceTree = ""; 106 | }; 107 | 607FACD31AFB9204008FA782 /* Supporting Files */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 607FACD41AFB9204008FA782 /* Info.plist */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | 607FACE81AFB9204008FA782 /* Tests */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 607FACEB1AFB9204008FA782 /* Tests.swift */, 119 | 607FACE91AFB9204008FA782 /* Supporting Files */, 120 | ); 121 | path = Tests; 122 | sourceTree = ""; 123 | }; 124 | 607FACE91AFB9204008FA782 /* Supporting Files */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 607FACEA1AFB9204008FA782 /* Info.plist */, 128 | ); 129 | name = "Supporting Files"; 130 | sourceTree = ""; 131 | }; 132 | 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | DFF88B267FE9956DF8761F59 /* LGLBaseKit.podspec */, 136 | EEB63EB4B0A33359DB1CEB45 /* README.md */, 137 | 1E83F080006E9DA9455205B3 /* LICENSE */, 138 | ); 139 | name = "Podspec Metadata"; 140 | sourceTree = ""; 141 | }; 142 | 63BB65452C5F5EE6722B49BA /* Pods */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 7A29A6A0C0FEFC6FA70DA46E /* Pods-LGLBaseKit_Example.debug.xcconfig */, 146 | 6F1DDD1834B79EC9DEB740C5 /* Pods-LGLBaseKit_Example.release.xcconfig */, 147 | 1A687A126AC95AE744A5745C /* Pods-LGLBaseKit_Tests.debug.xcconfig */, 148 | 24CF234EA86D7C3C9574B820 /* Pods-LGLBaseKit_Tests.release.xcconfig */, 149 | ); 150 | path = Pods; 151 | sourceTree = ""; 152 | }; 153 | 77D03356161B59BF499F6BC1 /* Frameworks */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | CD652C765CEAA66B4B706C65 /* Pods_LGLBaseKit_Example.framework */, 157 | 4EAC2AEBA89549D844860CE2 /* Pods_LGLBaseKit_Tests.framework */, 158 | ); 159 | name = Frameworks; 160 | sourceTree = ""; 161 | }; 162 | /* End PBXGroup section */ 163 | 164 | /* Begin PBXNativeTarget section */ 165 | 607FACCF1AFB9204008FA782 /* LGLBaseKit_Example */ = { 166 | isa = PBXNativeTarget; 167 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "LGLBaseKit_Example" */; 168 | buildPhases = ( 169 | 2218D06078B007BFBE87A48D /* [CP] Check Pods Manifest.lock */, 170 | 607FACCC1AFB9204008FA782 /* Sources */, 171 | 607FACCD1AFB9204008FA782 /* Frameworks */, 172 | 607FACCE1AFB9204008FA782 /* Resources */, 173 | 3D00903C5DAEA6B7BAE3F176 /* [CP] Embed Pods Frameworks */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | ); 179 | name = LGLBaseKit_Example; 180 | productName = LGLBaseKit; 181 | productReference = 607FACD01AFB9204008FA782 /* LGLBaseKit_Example.app */; 182 | productType = "com.apple.product-type.application"; 183 | }; 184 | 607FACE41AFB9204008FA782 /* LGLBaseKit_Tests */ = { 185 | isa = PBXNativeTarget; 186 | buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "LGLBaseKit_Tests" */; 187 | buildPhases = ( 188 | D63DEC5080B9D7A7541FB6A1 /* [CP] Check Pods Manifest.lock */, 189 | 607FACE11AFB9204008FA782 /* Sources */, 190 | 607FACE21AFB9204008FA782 /* Frameworks */, 191 | 607FACE31AFB9204008FA782 /* Resources */, 192 | ); 193 | buildRules = ( 194 | ); 195 | dependencies = ( 196 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */, 197 | ); 198 | name = LGLBaseKit_Tests; 199 | productName = Tests; 200 | productReference = 607FACE51AFB9204008FA782 /* LGLBaseKit_Tests.xctest */; 201 | productType = "com.apple.product-type.bundle.unit-test"; 202 | }; 203 | /* End PBXNativeTarget section */ 204 | 205 | /* Begin PBXProject section */ 206 | 607FACC81AFB9204008FA782 /* Project object */ = { 207 | isa = PBXProject; 208 | attributes = { 209 | LastSwiftUpdateCheck = 0830; 210 | LastUpgradeCheck = 0830; 211 | ORGANIZATIONNAME = CocoaPods; 212 | TargetAttributes = { 213 | 607FACCF1AFB9204008FA782 = { 214 | CreatedOnToolsVersion = 6.3.1; 215 | LastSwiftMigration = 0900; 216 | }; 217 | 607FACE41AFB9204008FA782 = { 218 | CreatedOnToolsVersion = 6.3.1; 219 | LastSwiftMigration = 0900; 220 | TestTargetID = 607FACCF1AFB9204008FA782; 221 | }; 222 | }; 223 | }; 224 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "LGLBaseKit" */; 225 | compatibilityVersion = "Xcode 3.2"; 226 | developmentRegion = English; 227 | hasScannedForEncodings = 0; 228 | knownRegions = ( 229 | English, 230 | en, 231 | Base, 232 | ); 233 | mainGroup = 607FACC71AFB9204008FA782; 234 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 235 | projectDirPath = ""; 236 | projectRoot = ""; 237 | targets = ( 238 | 607FACCF1AFB9204008FA782 /* LGLBaseKit_Example */, 239 | 607FACE41AFB9204008FA782 /* LGLBaseKit_Tests */, 240 | ); 241 | }; 242 | /* End PBXProject section */ 243 | 244 | /* Begin PBXResourcesBuildPhase section */ 245 | 607FACCE1AFB9204008FA782 /* Resources */ = { 246 | isa = PBXResourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 250 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 251 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | 607FACE31AFB9204008FA782 /* Resources */ = { 256 | isa = PBXResourcesBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | ); 260 | runOnlyForDeploymentPostprocessing = 0; 261 | }; 262 | /* End PBXResourcesBuildPhase section */ 263 | 264 | /* Begin PBXShellScriptBuildPhase section */ 265 | 2218D06078B007BFBE87A48D /* [CP] Check Pods Manifest.lock */ = { 266 | isa = PBXShellScriptBuildPhase; 267 | buildActionMask = 2147483647; 268 | files = ( 269 | ); 270 | inputFileListPaths = ( 271 | ); 272 | inputPaths = ( 273 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 274 | "${PODS_ROOT}/Manifest.lock", 275 | ); 276 | name = "[CP] Check Pods Manifest.lock"; 277 | outputFileListPaths = ( 278 | ); 279 | outputPaths = ( 280 | "$(DERIVED_FILE_DIR)/Pods-LGLBaseKit_Example-checkManifestLockResult.txt", 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | shellPath = /bin/sh; 284 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 285 | showEnvVarsInLog = 0; 286 | }; 287 | 3D00903C5DAEA6B7BAE3F176 /* [CP] Embed Pods Frameworks */ = { 288 | isa = PBXShellScriptBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | ); 292 | inputPaths = ( 293 | "${PODS_ROOT}/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-frameworks.sh", 294 | "${BUILT_PRODUCTS_DIR}/LGLBaseKit/LGLBaseKit.framework", 295 | ); 296 | name = "[CP] Embed Pods Frameworks"; 297 | outputPaths = ( 298 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LGLBaseKit.framework", 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | shellPath = /bin/sh; 302 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-frameworks.sh\"\n"; 303 | showEnvVarsInLog = 0; 304 | }; 305 | D63DEC5080B9D7A7541FB6A1 /* [CP] Check Pods Manifest.lock */ = { 306 | isa = PBXShellScriptBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | ); 310 | inputFileListPaths = ( 311 | ); 312 | inputPaths = ( 313 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 314 | "${PODS_ROOT}/Manifest.lock", 315 | ); 316 | name = "[CP] Check Pods Manifest.lock"; 317 | outputFileListPaths = ( 318 | ); 319 | outputPaths = ( 320 | "$(DERIVED_FILE_DIR)/Pods-LGLBaseKit_Tests-checkManifestLockResult.txt", 321 | ); 322 | runOnlyForDeploymentPostprocessing = 0; 323 | shellPath = /bin/sh; 324 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 325 | showEnvVarsInLog = 0; 326 | }; 327 | /* End PBXShellScriptBuildPhase section */ 328 | 329 | /* Begin PBXSourcesBuildPhase section */ 330 | 607FACCC1AFB9204008FA782 /* Sources */ = { 331 | isa = PBXSourcesBuildPhase; 332 | buildActionMask = 2147483647; 333 | files = ( 334 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 335 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, 336 | ); 337 | runOnlyForDeploymentPostprocessing = 0; 338 | }; 339 | 607FACE11AFB9204008FA782 /* Sources */ = { 340 | isa = PBXSourcesBuildPhase; 341 | buildActionMask = 2147483647; 342 | files = ( 343 | 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */, 344 | ); 345 | runOnlyForDeploymentPostprocessing = 0; 346 | }; 347 | /* End PBXSourcesBuildPhase section */ 348 | 349 | /* Begin PBXTargetDependency section */ 350 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */ = { 351 | isa = PBXTargetDependency; 352 | target = 607FACCF1AFB9204008FA782 /* LGLBaseKit_Example */; 353 | targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */; 354 | }; 355 | /* End PBXTargetDependency section */ 356 | 357 | /* Begin PBXVariantGroup section */ 358 | 607FACD91AFB9204008FA782 /* Main.storyboard */ = { 359 | isa = PBXVariantGroup; 360 | children = ( 361 | 607FACDA1AFB9204008FA782 /* Base */, 362 | ); 363 | name = Main.storyboard; 364 | sourceTree = ""; 365 | }; 366 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { 367 | isa = PBXVariantGroup; 368 | children = ( 369 | 607FACDF1AFB9204008FA782 /* Base */, 370 | ); 371 | name = LaunchScreen.xib; 372 | sourceTree = ""; 373 | }; 374 | /* End PBXVariantGroup section */ 375 | 376 | /* Begin XCBuildConfiguration section */ 377 | 607FACED1AFB9204008FA782 /* Debug */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | ALWAYS_SEARCH_USER_PATHS = NO; 381 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 382 | CLANG_CXX_LIBRARY = "libc++"; 383 | CLANG_ENABLE_MODULES = YES; 384 | CLANG_ENABLE_OBJC_ARC = YES; 385 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 386 | CLANG_WARN_BOOL_CONVERSION = YES; 387 | CLANG_WARN_COMMA = YES; 388 | CLANG_WARN_CONSTANT_CONVERSION = YES; 389 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 390 | CLANG_WARN_EMPTY_BODY = YES; 391 | CLANG_WARN_ENUM_CONVERSION = YES; 392 | CLANG_WARN_INFINITE_RECURSION = YES; 393 | CLANG_WARN_INT_CONVERSION = YES; 394 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 395 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 396 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 397 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 398 | CLANG_WARN_STRICT_PROTOTYPES = YES; 399 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 400 | CLANG_WARN_UNREACHABLE_CODE = YES; 401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 402 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 403 | COPY_PHASE_STRIP = NO; 404 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 405 | ENABLE_STRICT_OBJC_MSGSEND = YES; 406 | ENABLE_TESTABILITY = YES; 407 | GCC_C_LANGUAGE_STANDARD = gnu99; 408 | GCC_DYNAMIC_NO_PIC = NO; 409 | GCC_NO_COMMON_BLOCKS = YES; 410 | GCC_OPTIMIZATION_LEVEL = 0; 411 | GCC_PREPROCESSOR_DEFINITIONS = ( 412 | "DEBUG=1", 413 | "$(inherited)", 414 | ); 415 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 416 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 417 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 418 | GCC_WARN_UNDECLARED_SELECTOR = YES; 419 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 420 | GCC_WARN_UNUSED_FUNCTION = YES; 421 | GCC_WARN_UNUSED_VARIABLE = YES; 422 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 423 | MTL_ENABLE_DEBUG_INFO = YES; 424 | ONLY_ACTIVE_ARCH = YES; 425 | SDKROOT = iphoneos; 426 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 427 | }; 428 | name = Debug; 429 | }; 430 | 607FACEE1AFB9204008FA782 /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | ALWAYS_SEARCH_USER_PATHS = NO; 434 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 435 | CLANG_CXX_LIBRARY = "libc++"; 436 | CLANG_ENABLE_MODULES = YES; 437 | CLANG_ENABLE_OBJC_ARC = YES; 438 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 439 | CLANG_WARN_BOOL_CONVERSION = YES; 440 | CLANG_WARN_COMMA = YES; 441 | CLANG_WARN_CONSTANT_CONVERSION = YES; 442 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 443 | CLANG_WARN_EMPTY_BODY = YES; 444 | CLANG_WARN_ENUM_CONVERSION = YES; 445 | CLANG_WARN_INFINITE_RECURSION = YES; 446 | CLANG_WARN_INT_CONVERSION = YES; 447 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 448 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 449 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 450 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 451 | CLANG_WARN_STRICT_PROTOTYPES = YES; 452 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 453 | CLANG_WARN_UNREACHABLE_CODE = YES; 454 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 455 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 456 | COPY_PHASE_STRIP = NO; 457 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 458 | ENABLE_NS_ASSERTIONS = NO; 459 | ENABLE_STRICT_OBJC_MSGSEND = YES; 460 | GCC_C_LANGUAGE_STANDARD = gnu99; 461 | GCC_NO_COMMON_BLOCKS = YES; 462 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 463 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 464 | GCC_WARN_UNDECLARED_SELECTOR = YES; 465 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 466 | GCC_WARN_UNUSED_FUNCTION = YES; 467 | GCC_WARN_UNUSED_VARIABLE = YES; 468 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 469 | MTL_ENABLE_DEBUG_INFO = NO; 470 | SDKROOT = iphoneos; 471 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 472 | VALIDATE_PRODUCT = YES; 473 | }; 474 | name = Release; 475 | }; 476 | 607FACF01AFB9204008FA782 /* Debug */ = { 477 | isa = XCBuildConfiguration; 478 | baseConfigurationReference = 7A29A6A0C0FEFC6FA70DA46E /* Pods-LGLBaseKit_Example.debug.xcconfig */; 479 | buildSettings = { 480 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 481 | INFOPLIST_FILE = LGLBaseKit/Info.plist; 482 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 483 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 484 | MODULE_NAME = ExampleApp; 485 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 486 | PRODUCT_NAME = "$(TARGET_NAME)"; 487 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 488 | SWIFT_VERSION = 5.0; 489 | }; 490 | name = Debug; 491 | }; 492 | 607FACF11AFB9204008FA782 /* Release */ = { 493 | isa = XCBuildConfiguration; 494 | baseConfigurationReference = 6F1DDD1834B79EC9DEB740C5 /* Pods-LGLBaseKit_Example.release.xcconfig */; 495 | buildSettings = { 496 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 497 | INFOPLIST_FILE = LGLBaseKit/Info.plist; 498 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 499 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 500 | MODULE_NAME = ExampleApp; 501 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 502 | PRODUCT_NAME = "$(TARGET_NAME)"; 503 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 504 | SWIFT_VERSION = 5.0; 505 | }; 506 | name = Release; 507 | }; 508 | 607FACF31AFB9204008FA782 /* Debug */ = { 509 | isa = XCBuildConfiguration; 510 | baseConfigurationReference = 1A687A126AC95AE744A5745C /* Pods-LGLBaseKit_Tests.debug.xcconfig */; 511 | buildSettings = { 512 | FRAMEWORK_SEARCH_PATHS = ( 513 | "$(PLATFORM_DIR)/Developer/Library/Frameworks", 514 | "$(inherited)", 515 | ); 516 | GCC_PREPROCESSOR_DEFINITIONS = ( 517 | "DEBUG=1", 518 | "$(inherited)", 519 | ); 520 | INFOPLIST_FILE = Tests/Info.plist; 521 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 522 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 523 | PRODUCT_NAME = "$(TARGET_NAME)"; 524 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 525 | SWIFT_VERSION = 4.0; 526 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LGLBaseKit_Example.app/LGLBaseKit_Example"; 527 | }; 528 | name = Debug; 529 | }; 530 | 607FACF41AFB9204008FA782 /* Release */ = { 531 | isa = XCBuildConfiguration; 532 | baseConfigurationReference = 24CF234EA86D7C3C9574B820 /* Pods-LGLBaseKit_Tests.release.xcconfig */; 533 | buildSettings = { 534 | FRAMEWORK_SEARCH_PATHS = ( 535 | "$(PLATFORM_DIR)/Developer/Library/Frameworks", 536 | "$(inherited)", 537 | ); 538 | INFOPLIST_FILE = Tests/Info.plist; 539 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 540 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 541 | PRODUCT_NAME = "$(TARGET_NAME)"; 542 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 543 | SWIFT_VERSION = 4.0; 544 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LGLBaseKit_Example.app/LGLBaseKit_Example"; 545 | }; 546 | name = Release; 547 | }; 548 | /* End XCBuildConfiguration section */ 549 | 550 | /* Begin XCConfigurationList section */ 551 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "LGLBaseKit" */ = { 552 | isa = XCConfigurationList; 553 | buildConfigurations = ( 554 | 607FACED1AFB9204008FA782 /* Debug */, 555 | 607FACEE1AFB9204008FA782 /* Release */, 556 | ); 557 | defaultConfigurationIsVisible = 0; 558 | defaultConfigurationName = Release; 559 | }; 560 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "LGLBaseKit_Example" */ = { 561 | isa = XCConfigurationList; 562 | buildConfigurations = ( 563 | 607FACF01AFB9204008FA782 /* Debug */, 564 | 607FACF11AFB9204008FA782 /* Release */, 565 | ); 566 | defaultConfigurationIsVisible = 0; 567 | defaultConfigurationName = Release; 568 | }; 569 | 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "LGLBaseKit_Tests" */ = { 570 | isa = XCConfigurationList; 571 | buildConfigurations = ( 572 | 607FACF31AFB9204008FA782 /* Debug */, 573 | 607FACF41AFB9204008FA782 /* Release */, 574 | ); 575 | defaultConfigurationIsVisible = 0; 576 | defaultConfigurationName = Release; 577 | }; 578 | /* End XCConfigurationList section */ 579 | }; 580 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 581 | } 582 | -------------------------------------------------------------------------------- /Example/LGLBaseKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/LGLBaseKit.xcodeproj/xcshareddata/xcschemes/LGLBaseKit-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 48 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 80 | 82 | 88 | 89 | 90 | 91 | 92 | 93 | 99 | 101 | 107 | 108 | 109 | 110 | 112 | 113 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /Example/LGLBaseKit.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/LGLBaseKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LGLBaseKit 4 | // 5 | // Created by 185226139@qq.com on 08/21/2019. 6 | // Copyright (c) 2019 185226139@qq.com. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // 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. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/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 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/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 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Example/LGLBaseKit/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LGLBaseKit 4 | // 5 | // Created by 185226139@qq.com on 08/21/2019. 6 | // Copyright (c) 2019 185226139@qq.com. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | target 'LGLBaseKit_Example' do 4 | pod 'LGLBaseKit', :path => '../' 5 | 6 | target 'LGLBaseKit_Tests' do 7 | inherit! :search_paths 8 | 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Example/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - LGLBaseKit (0.1.0) 3 | 4 | DEPENDENCIES: 5 | - LGLBaseKit (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | LGLBaseKit: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | LGLBaseKit: 2b592a1083eaaa683368442b92b74fd0a8eea394 13 | 14 | PODFILE CHECKSUM: 68a7ac05bb75be4b0a964eef4a75995122ab6fc0 15 | 16 | COCOAPODS: 1.7.0 17 | -------------------------------------------------------------------------------- /Example/Pods/Local Podspecs/LGLBaseKit.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LGLBaseKit", 3 | "version": "0.1.0", 4 | "summary": "A short description of LGLBaseKit.", 5 | "description": "TODO: Add long description of the pod here.", 6 | "homepage": "https://github.com/185226139@qq.com/LGLBaseKit", 7 | "license": { 8 | "type": "MIT", 9 | "file": "LICENSE" 10 | }, 11 | "authors": { 12 | "185226139@qq.com": "ligl@chinamobiad.com" 13 | }, 14 | "source": { 15 | "git": "https://github.com/185226139@qq.com/LGLBaseKit.git", 16 | "tag": "0.1.0" 17 | }, 18 | "platforms": { 19 | "ios": "8.0" 20 | }, 21 | "source_files": "LGLBaseKit/Classes/**/*" 22 | } 23 | -------------------------------------------------------------------------------- /Example/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - LGLBaseKit (0.1.0) 3 | 4 | DEPENDENCIES: 5 | - LGLBaseKit (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | LGLBaseKit: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | LGLBaseKit: 2b592a1083eaaa683368442b92b74fd0a8eea394 13 | 14 | PODFILE CHECKSUM: 68a7ac05bb75be4b0a964eef4a75995122ab6fc0 15 | 16 | COCOAPODS: 1.7.0 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit-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 | 0.1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_LGLBaseKit : NSObject 3 | @end 4 | @implementation PodsDummy_LGLBaseKit 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double LGLBaseKitVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char LGLBaseKitVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit.modulemap: -------------------------------------------------------------------------------- 1 | framework module LGLBaseKit { 2 | umbrella header "LGLBaseKit-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/LGLBaseKit/LGLBaseKit.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 4 | PODS_BUILD_DIR = ${BUILD_DIR} 5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT} 7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-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.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## LGLBaseKit 5 | 6 | Copyright (c) 2019 185226139@qq.com 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | Generated by CocoaPods - https://cocoapods.org 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2019 185226139@qq.com <ligl@chinamobiad.com> 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | 37 | License 38 | MIT 39 | Title 40 | LGLBaseKit 41 | Type 42 | PSGroupSpecifier 43 | 44 | 45 | FooterText 46 | Generated by CocoaPods - https://cocoapods.org 47 | Title 48 | 49 | Type 50 | PSGroupSpecifier 51 | 52 | 53 | StringsTable 54 | Acknowledgements 55 | Title 56 | Acknowledgements 57 | 58 | 59 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_LGLBaseKit_Example : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_LGLBaseKit_Example 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -u 4 | set -o pipefail 5 | 6 | function on_error { 7 | echo "$(realpath -mq "${0}"):$1: error: Unexpected failure" 8 | } 9 | trap 'on_error $LINENO' ERR 10 | 11 | if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then 12 | # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy 13 | # frameworks to, so exit 0 (signalling the script phase was successful). 14 | exit 0 15 | fi 16 | 17 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 18 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 19 | 20 | COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}" 21 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 22 | 23 | # Used as a return value for each invocation of `strip_invalid_archs` function. 24 | STRIP_BINARY_RETVAL=0 25 | 26 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 27 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 28 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 29 | 30 | # Copies and strips a vendored framework 31 | install_framework() 32 | { 33 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 34 | local source="${BUILT_PRODUCTS_DIR}/$1" 35 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 36 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 37 | elif [ -r "$1" ]; then 38 | local source="$1" 39 | fi 40 | 41 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 42 | 43 | if [ -L "${source}" ]; then 44 | echo "Symlinked..." 45 | source="$(readlink "${source}")" 46 | fi 47 | 48 | # Use filter instead of exclude so missing patterns don't throw errors. 49 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 50 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 51 | 52 | local basename 53 | basename="$(basename -s .framework "$1")" 54 | binary="${destination}/${basename}.framework/${basename}" 55 | 56 | if ! [ -r "$binary" ]; then 57 | binary="${destination}/${basename}" 58 | elif [ -L "${binary}" ]; then 59 | echo "Destination binary is symlinked..." 60 | dirname="$(dirname "${binary}")" 61 | binary="${dirname}/$(readlink "${binary}")" 62 | fi 63 | 64 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 65 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 66 | strip_invalid_archs "$binary" 67 | fi 68 | 69 | # Resign the code if required by the build settings to avoid unstable apps 70 | code_sign_if_enabled "${destination}/$(basename "$1")" 71 | 72 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 73 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 74 | local swift_runtime_libs 75 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u) 76 | for lib in $swift_runtime_libs; do 77 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 78 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 79 | code_sign_if_enabled "${destination}/${lib}" 80 | done 81 | fi 82 | } 83 | 84 | # Copies and strips a vendored dSYM 85 | install_dsym() { 86 | local source="$1" 87 | if [ -r "$source" ]; then 88 | # Copy the dSYM into a the targets temp dir. 89 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" 90 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" 91 | 92 | local basename 93 | basename="$(basename -s .framework.dSYM "$source")" 94 | binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}" 95 | 96 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 97 | if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then 98 | strip_invalid_archs "$binary" 99 | fi 100 | 101 | if [[ $STRIP_BINARY_RETVAL == 1 ]]; then 102 | # Move the stripped file into its final destination. 103 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" 104 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}" 105 | else 106 | # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. 107 | touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM" 108 | fi 109 | fi 110 | } 111 | 112 | # Copies the bcsymbolmap files of a vendored framework 113 | install_bcsymbolmap() { 114 | local bcsymbolmap_path="$1" 115 | local destination="${BUILT_PRODUCTS_DIR}" 116 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"" 117 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}" 118 | } 119 | 120 | # Signs a framework with the provided identity 121 | code_sign_if_enabled() { 122 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 123 | # Use the current code_sign_identity 124 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 125 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'" 126 | 127 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 128 | code_sign_cmd="$code_sign_cmd &" 129 | fi 130 | echo "$code_sign_cmd" 131 | eval "$code_sign_cmd" 132 | fi 133 | } 134 | 135 | # Strip invalid architectures 136 | strip_invalid_archs() { 137 | binary="$1" 138 | # Get architectures for current target binary 139 | binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" 140 | # Intersect them with the architectures we are building for 141 | intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" 142 | # If there are no archs supported by this binary then warn the user 143 | if [[ -z "$intersected_archs" ]]; then 144 | echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." 145 | STRIP_BINARY_RETVAL=0 146 | return 147 | fi 148 | stripped="" 149 | for arch in $binary_archs; do 150 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 151 | # Strip non-valid architectures in-place 152 | lipo -remove "$arch" -output "$binary" "$binary" 153 | stripped="$stripped $arch" 154 | fi 155 | done 156 | if [[ "$stripped" ]]; then 157 | echo "Stripped $binary of architectures:$stripped" 158 | fi 159 | STRIP_BINARY_RETVAL=1 160 | } 161 | 162 | 163 | if [[ "$CONFIGURATION" == "Debug" ]]; then 164 | install_framework "${BUILT_PRODUCTS_DIR}/LGLBaseKit/LGLBaseKit.framework" 165 | fi 166 | if [[ "$CONFIGURATION" == "Release" ]]; then 167 | install_framework "${BUILT_PRODUCTS_DIR}/LGLBaseKit/LGLBaseKit.framework" 168 | fi 169 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 170 | wait 171 | fi 172 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_LGLBaseKit_ExampleVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_LGLBaseKit_ExampleVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit/LGLBaseKit.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "LGLBaseKit" 7 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_LGLBaseKit_Example { 2 | umbrella header "Pods-LGLBaseKit_Example-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Example/Pods-LGLBaseKit_Example.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit/LGLBaseKit.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "LGLBaseKit" 7 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests-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.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Generated by CocoaPods - https://cocoapods.org 18 | Title 19 | 20 | Type 21 | PSGroupSpecifier 22 | 23 | 24 | StringsTable 25 | Acknowledgements 26 | Title 27 | Acknowledgements 28 | 29 | 30 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_LGLBaseKit_Tests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_LGLBaseKit_Tests 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_LGLBaseKit_TestsVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_LGLBaseKit_TestsVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit/LGLBaseKit.framework/Headers" 4 | OTHER_LDFLAGS = $(inherited) -framework "LGLBaseKit" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_LGLBaseKit_Tests { 2 | umbrella header "Pods-LGLBaseKit_Tests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-LGLBaseKit_Tests/Pods-LGLBaseKit_Tests.release.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/LGLBaseKit/LGLBaseKit.framework/Headers" 4 | OTHER_LDFLAGS = $(inherited) -framework "LGLBaseKit" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Example/Tests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/Tests/Tests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import LGLBaseKit 3 | 4 | class Tests: XCTestCase { 5 | 6 | override func setUp() { 7 | super.setUp() 8 | // Put setup code here. This method is called before the invocation of each test method in the class. 9 | } 10 | 11 | override func tearDown() { 12 | // Put teardown code here. This method is called after the invocation of each test method in the class. 13 | super.tearDown() 14 | } 15 | 16 | func testExample() { 17 | // This is an example of a functional test case. 18 | XCTAssert(true, "Pass") 19 | } 20 | 21 | func testPerformanceExample() { 22 | // This is an example of a performance test case. 23 | self.measure() { 24 | // Put the code you want to measure the time of here. 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /LGLBaseKit.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint LGLBaseKit.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'LGLBaseKit' 11 | s.version = '0.1.2' 12 | s.summary = 'LGLBaseKit is a convenient library' 13 | 14 | # This description is used to generate tags and improve search results. 15 | # * Think: What does it do? Why did you write it? What is the focus? 16 | # * Try to keep it short, snappy and to the point. 17 | # * Write the description between the DESC delimiters below. 18 | # * Finally, don't worry about the indent, CocoaPods strips it! 19 | 20 | s.description = <<-DESC 21 | TODO: A convenient library that encapsulates common UI controls and methods 22 | DESC 23 | 24 | s.homepage = 'https://github.com/liguoliangiOS/LGLBaseKit.git' 25 | # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' 26 | s.license = { :type => 'MIT', :file => 'LICENSE' } 27 | s.author = 'ligl@chinamobiad.com' 28 | s.source = { :git => 'https://github.com/liguoliangiOS/LGLBaseKit.git', :tag => s.version.to_s } 29 | # s.social_media_url = 'https://twitter.com/' 30 | 31 | s.ios.deployment_target = '9.0' 32 | s.swift_version = '5.0' 33 | # s.source_files = 'LGLBaseKit/Classes/**/*' 34 | 35 | # s.resource_bundles = { 36 | # 'LGLBaseKit' => ['LGLBaseKit/Assets/*.png'] 37 | # } 38 | 39 | # s.public_header_files = 'Pod/Classes/**/*.h' 40 | # s.frameworks = 'UIKit', 'MapKit' 41 | # s.dependency 'AFNetworking', '~> 2.3' 42 | 43 | s.subspec 'LGLExtension' do |ss| 44 | ss.source_files = 'LGLBaseKit/Classes/LGLExtension' 45 | end 46 | 47 | s.subspec 'LGLCrypt' do |ss| 48 | ss.source_files = 'LGLBaseKit/Classes/LGLCrypt' 49 | end 50 | 51 | s.subspec 'LGLDeviceInfo' do |ss| 52 | ss.source_files = 'LGLBaseKit/Classes/LGLDeviceInfo' 53 | end 54 | 55 | s.subspec 'LGLAlert' do |ss| 56 | ss.source_files = 'LGLBaseKit/Classes/LGLAlert' 57 | end 58 | 59 | s.subspec 'LGLPublicMethod' do |ss| 60 | ss.source_files = 'LGLBaseKit/Classes/LGLPublicMethod' 61 | end 62 | 63 | s.subspec 'LGLBaseUIKit' do |ss| 64 | ss.dependency 'LGLBaseKit/LGLExtension' 65 | ss.dependency 'LGLBaseKit/LGLDeviceInfo' 66 | ss.dependency 'LGLBaseKit/LGLAlert' 67 | end 68 | 69 | end 70 | -------------------------------------------------------------------------------- /LGLBaseKit/Assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liguoliangiOS/LGLBaseKit/a83c6daee82596bfebc3fba481de740100a980ee/LGLBaseKit/Assets/.gitkeep -------------------------------------------------------------------------------- /LGLBaseKit/Classes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liguoliangiOS/LGLBaseKit/a83c6daee82596bfebc3fba481de740100a980ee/LGLBaseKit/Classes/.gitkeep -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLAlert/LGLAlert.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLAlert.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public class LGLAlert { 11 | 12 | ///aler提示框 13 | public static func lgl_alert(_ title: String, _ message: String, _ showTime: TimeInterval = 1.0) { 14 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) 15 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 16 | lgl_basekit_dissMissAlert(alertVC, showTime) 17 | } 18 | 19 | ///单个按钮的alert提示框 20 | public static func lgl_alert(_ title: String, _ message: String, _ actionTitle:String, _ actionStyle:UIAlertAction.Style = .default, handler:((UIAlertAction) -> Void)? = nil) { 21 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) 22 | let action = UIAlertAction(title: actionTitle, style: actionStyle, handler: handler) 23 | alertVC.addAction(action) 24 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 25 | } 26 | 27 | ///两个按钮的alert提示框 28 | public static func lgl_alert(_ title: String, _ message: String, _ cancelTitle:String, cancelHandler:((UIAlertAction) -> Void)? = nil, _ confirmTitle:String, confirmHandler:((UIAlertAction) -> Void)? = nil) { 29 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) 30 | let cancel = UIAlertAction(title: cancelTitle, style: .cancel, handler: cancelHandler) 31 | alertVC.addAction(cancel) 32 | let confirm = UIAlertAction(title: confirmTitle, style: .default, handler: confirmHandler) 33 | alertVC.addAction(confirm) 34 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 35 | } 36 | 37 | ///ationSheet 提示框 38 | public static func lgl_ationSheet(_ title: String, _ message: String, _ showTime: TimeInterval = 1.0) { 39 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) 40 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 41 | lgl_basekit_dissMissAlert(alertVC, showTime) 42 | } 43 | 44 | ///单个按钮的ationSheet提示框 45 | public static func lgl_ationSheet(_ title: String, _ message: String, _ actionTitle:String, _ actionStyle:UIAlertAction.Style = .default, handler:((UIAlertAction) -> Void)? = nil) { 46 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) 47 | let action = UIAlertAction(title: actionTitle, style: actionStyle, handler: handler) 48 | alertVC.addAction(action) 49 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 50 | } 51 | 52 | ///两个按钮的ationSheet提示框 53 | public static func lgl_ationSheet(_ title: String, _ message: String, _ cancelTitle:String, cancelHandler:((UIAlertAction) -> Void)? = nil, _ confirmTitle:String, confirmHandler:((UIAlertAction) -> Void)? = nil) { 54 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) 55 | let cancel = UIAlertAction(title: cancelTitle, style: .cancel, handler: cancelHandler) 56 | alertVC.addAction(cancel) 57 | let confirm = UIAlertAction(title: confirmTitle, style: .default, handler: confirmHandler) 58 | alertVC.addAction(confirm) 59 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 60 | } 61 | 62 | ///一个按钮的filed弹窗 63 | public static func lgl_field(_ title: String, _ message: String, _ buttonTitle: String, _ fieldHolder:String = "", handler:@escaping ((_ filedValue: String?) -> Void)) { 64 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) 65 | let cancel = UIAlertAction(title: buttonTitle, style: .default) { (action) in 66 | let alertStr = alertVC.textFields![0].text 67 | handler(alertStr) 68 | } 69 | alertVC.addAction(cancel) 70 | alertVC.addTextField { (textField) in 71 | textField.placeholder = fieldHolder 72 | } 73 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 74 | } 75 | 76 | ///两个按钮的filed弹窗 77 | public static func lgl_field(_ title: String, _ message: String,_ cancelTitle:String,_ fieldHolder:String = "", cancelHandler:((UIAlertAction) -> Void)? = nil, _ buttonTitle: String, confirmHandler:@escaping ((_ filedValue: String?) -> Void)) { 78 | let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) 79 | let cancel = UIAlertAction(title: cancelTitle, style: .cancel, handler: cancelHandler) 80 | alertVC.addAction(cancel) 81 | let okAction = UIAlertAction(title: buttonTitle, style: .default) { (action) in 82 | let alertStr = alertVC.textFields![0].text 83 | confirmHandler(alertStr) 84 | } 85 | alertVC.addAction(okAction) 86 | alertVC.addTextField { (textField) in 87 | textField.placeholder = fieldHolder 88 | } 89 | lgl_basekit_AlertCurrentVC()?.present(alertVC, animated: true, completion: nil) 90 | } 91 | } 92 | 93 | 94 | 95 | private extension LGLAlert { 96 | 97 | private class func lgl_basekit_dissMissAlert(_ alertVC: UIAlertController, _ showTime: TimeInterval) { 98 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + showTime, execute: { 99 | alertVC.dismiss(animated: true, completion: nil) 100 | }) 101 | } 102 | 103 | /// 根据控制器,返回当前控制器 104 | private class func lgl_basekit_AlertCurrentVC() -> UIViewController? { 105 | guard let rootVC = UIApplication.shared.keyWindow?.rootViewController else { 106 | return nil 107 | } 108 | return lgl_basekit_AlertMapCurrentVC(rootVC: rootVC) 109 | } 110 | 111 | /// 递归找最上面的控制器 112 | private class func lgl_basekit_AlertMapCurrentVC(rootVC :UIViewController) -> UIViewController? { 113 | var currentVC: UIViewController? 114 | if rootVC.presentedViewController != nil { 115 | currentVC = rootVC.presentedViewController 116 | } else if rootVC.isKind(of: UITabBarController.self) == true { 117 | currentVC = lgl_basekit_AlertMapCurrentVC(rootVC: (rootVC as! UITabBarController).selectedViewController!) 118 | } else if rootVC.isKind(of: UINavigationController.self) == true { 119 | currentVC = lgl_basekit_AlertMapCurrentVC(rootVC: (rootVC as! UINavigationController).visibleViewController!) 120 | } else { 121 | currentVC = rootVC 122 | } 123 | return currentVC 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLAlert/LGLShowText.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLShowText.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/11/4. 6 | // 7 | 8 | import UIKit 9 | 10 | fileprivate let Screen_W:CGFloat = UIScreen.main.bounds.width 11 | fileprivate let Screen_H:CGFloat = UIScreen.main.bounds.height 12 | 13 | 14 | public class LGLShowText: UIView { 15 | 16 | public class func showTextView(_ message: String?) { 17 | if message != nil { 18 | DispatchQueue.main.async { 19 | let erroView = LGLShowText(frame: UIScreen.main.bounds, error: message!, textFont: UIFont.systemFont(ofSize: 15)) 20 | let window:UIWindow = UIApplication.shared.windows[0] 21 | window.addSubview(erroView) 22 | } 23 | } 24 | } 25 | 26 | public class func showTextView(_ message: String?, _ textFont: UIFont) { 27 | if message != nil { 28 | DispatchQueue.main.async { 29 | let erroView = LGLShowText(frame: UIScreen.main.bounds, error: message!, textFont: textFont) 30 | let window:UIWindow = UIApplication.shared.windows[0] 31 | window.addSubview(erroView) 32 | } 33 | } 34 | } 35 | 36 | convenience init(frame: CGRect, error: String, textFont: UIFont) { 37 | self.init(frame: frame) 38 | lgl_basekit_setTextSubViews(error, textFont) 39 | } 40 | 41 | override init(frame: CGRect) { 42 | super.init(frame: frame) 43 | } 44 | 45 | required init?(coder aDecoder: NSCoder) { 46 | fatalError("init(coder:) has not been implemented") 47 | } 48 | 49 | } 50 | 51 | 52 | private extension LGLShowText { 53 | 54 | func lgl_basekit_setTextSubViews(_ showText: String, _ textFont: UIFont) { 55 | 56 | let marginX:CGFloat = 20 57 | let valibleW:CGFloat = Screen_W - marginX * 2 58 | 59 | let paddingX:CGFloat = 30 60 | let paddingY:CGFloat = 20 61 | 62 | let size:CGSize = lgl_basekit_strSize(showText, textFont, valibleW) 63 | 64 | var totalW:CGFloat = size.width + paddingX 65 | let totalH:CGFloat = size.height + paddingY 66 | 67 | if totalW > valibleW { 68 | totalW = valibleW 69 | } 70 | let totalY:CGFloat = (Screen_H / 2 - totalH) 71 | let totalX:CGFloat = (Screen_W - totalW) / 2 72 | 73 | let textLabel = UILabel(frame: CGRect(x: totalX, y: totalY, width: totalW, height: totalH)) 74 | textLabel.text = showText 75 | textLabel.textColor = .white 76 | textLabel.font = textFont 77 | textLabel.numberOfLines = 0 78 | textLabel.backgroundColor = lgl_basekit_color() 79 | textLabel.textAlignment = .center 80 | textLabel.layer.masksToBounds = true 81 | textLabel.layer.cornerRadius = 4 82 | self.addSubview(textLabel) 83 | 84 | lgl_basekit_hidddenErrorView(textLabel) 85 | } 86 | 87 | private func lgl_basekit_hidddenErrorView(_ label: UILabel) { 88 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5, execute: { 89 | self.removeFromSuperview() 90 | label.removeFromSuperview() 91 | }) 92 | } 93 | 94 | ///获取某一段文字的CGSize 95 | private func lgl_basekit_strSize(_ text:String, _ font: UIFont, _ maxWidth: CGFloat) -> CGSize { 96 | let attrs = [NSAttributedString.Key.font: font] 97 | let showText = text as NSString 98 | let textRect:CGRect = showText.boundingRect(with: CGSize(width: maxWidth, height: CGFloat(MAXFLOAT)), options:[.usesLineFragmentOrigin, .truncatesLastVisibleLine, .usesFontLeading], attributes: attrs, context: nil) 99 | return textRect.size 100 | } 101 | 102 | private func lgl_basekit_color() -> UIColor { 103 | let red = CGFloat(85)/255.0 104 | let green = CGFloat(85)/255.0 105 | let blue = CGFloat(85)/255.0 106 | return UIColor(red: red, green: green, blue: blue, alpha: 1.0) 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLCrypt/LGLCrypt.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLCrypt.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/21. 6 | // 7 | 8 | import UIKit 9 | 10 | ///RSA加密钥匙串私钥使用的key 11 | public let LGL_RSA_PRIVATE_KEY:String = "LGL_RSAUtil_PrivKey" 12 | ///RSA加密钥匙串公钥使用的key 13 | public let LGL_RSA_PUBLIC_KEY:String = "LGL_RSAUtil_PubKey" 14 | 15 | //MARK: ---- MD5加密 ---- 16 | public class LGLCrypt { 17 | ///MD5加密 18 | public static func lgl_md5Encrypt(_ text: String ) -> String { 19 | return text.md5Encrypt() 20 | } 21 | } 22 | 23 | //MARK: ---- AES 加解密 ---- 24 | public extension LGLCrypt { 25 | 26 | ///AES加密([UInt8]c形式的key和iv) 27 | static func lgl_aesEncrypt(_ text: String, _ key:[UInt8], _ iv:[UInt8]) -> String? { 28 | guard let result = text.aesCBCEncrypt(String(data: Data.init(key), encoding: .utf8)!, iv: String(data: Data.init(iv), encoding: .utf8)!) else { return nil } 29 | let encryptedDataText = result.base64EncodedString(options: NSData.Base64EncodingOptions()) 30 | return encryptedDataText 31 | } 32 | 33 | ///AES解密([UInt8]c形式的key和iv) 34 | static func lgl_aesDecrypt(_ aesText: String, _ key:[UInt8], _ iv:[UInt8]) -> String? { 35 | guard let deResult = aesText.aesCBCDecryptFromBase64(String(data: Data.init(key), encoding: .utf8)!, iv: String(data: Data.init(iv), encoding: .utf8)!) else { return nil } 36 | return deResult 37 | } 38 | 39 | ///AES加密(字符串形式的key和iv) 40 | static func lgl_aesEncryptStr(_ text: String, _ key:String, _ iv:String) -> String? { 41 | let result = text.aesCBCEncrypt(key, iv: iv) 42 | let encryptedDataText = result!.base64EncodedString(options: NSData.Base64EncodingOptions()) 43 | return encryptedDataText 44 | } 45 | 46 | ///AES解密(字符串形式的key和iv) 47 | static func lgl_aesDecryptStr(_ aesText: String, _ key:String, _ iv:String) -> String? { 48 | guard let deResult = aesText.aesCBCDecryptFromBase64(key, iv: iv) else { return nil } 49 | return deResult 50 | } 51 | } 52 | 53 | 54 | //MARK: ---- RSA 加解密 ---- 55 | 56 | public extension LGLCrypt { 57 | 58 | /// RSA签名 59 | static func lgl_rsaSignWithSHA1(_ text: String, _ privateKey: String, _ privateKeychainTag:String = LGL_RSA_PRIVATE_KEY) -> String? { 60 | guard let textData = text.data(using: String.Encoding.utf8) else { return nil } 61 | let siginData = RSACrypt.siginWithRsaSHA1(textData, privateKey, privateKeychainTag) 62 | if siginData != nil { 63 | let encryptedDataText = siginData!.base64EncodedString(options: NSData.Base64EncodingOptions()) 64 | return encryptedDataText 65 | } else { 66 | print("Error while sigining") 67 | return nil 68 | } 69 | } 70 | 71 | 72 | /// RSA验签 73 | static func lgl_rsaSignVerifyWithSHA1(_ originalStr: String, _ siginStr: String, _ publicKey: String, _ privateKeychainTag:String = LGL_RSA_PRIVATE_KEY) -> Bool { 74 | return RSACrypt.verifySigin(originalStr, siginStr, publicKey, privateKeychainTag) 75 | } 76 | 77 | /// RSA公钥加密 78 | static func lgl_rsaEncrypt(_ text: String, _ publicKey: String, _ publicKeychainTag:String = LGL_RSA_PUBLIC_KEY) -> String? { 79 | guard let textData = text.data(using: String.Encoding.utf8) else { return nil } 80 | let encryptedData = RSACrypt.encryptWithRSAPublicKey(textData, pubkeyBase64: publicKey, keychainTag: publicKeychainTag) 81 | if ( encryptedData == nil ) { 82 | print("Error while encrypting") 83 | return nil 84 | } else { 85 | let encryptedDataText = encryptedData!.base64EncodedString(options: NSData.Base64EncodingOptions()) 86 | return encryptedDataText 87 | } 88 | } 89 | 90 | /// RSA私钥解密 91 | static func lgl_rsaDecrypt(_ encryptData: String, _ privateKey: String, _ privateKeychainTag:String = LGL_RSA_PRIVATE_KEY) -> String? { 92 | guard let baseDecodeData = Data(base64Encoded: encryptData, options: NSData.Base64DecodingOptions()) else { return nil } 93 | let decryptedInfo = RSACrypt.decryptWithRSAPrivateKey(baseDecodeData, privkeyBase64: privateKey, keychainTag: privateKeychainTag) 94 | if ( decryptedInfo != nil ) { 95 | let result = String(data: decryptedInfo!, encoding: .utf8) 96 | return result 97 | } else { 98 | print("Error while decrypting") 99 | return nil 100 | } 101 | } 102 | 103 | /// RSA公钥解密 104 | static func lgl_rsaDecryptPublic(_ encryptData: String, _ publicKey: String, _ publicKeychainTag:String = LGL_RSA_PUBLIC_KEY) -> String? { 105 | 106 | guard let baseDecodeData = Data(base64Encoded: encryptData, options: NSData.Base64DecodingOptions()) else { return nil } 107 | let decryptedInfo = RSACrypt.decryptWithRSAPublicKey(baseDecodeData, pubkeyBase64: publicKey, keychainTag: publicKeychainTag) 108 | if ( decryptedInfo != nil ) { 109 | let result = String(data: decryptedInfo!, encoding: .utf8) 110 | return result 111 | } else { 112 | print("Error while decrypting") 113 | return nil 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLDeviceInfo/LGLDevice.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLDevice.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/22. 6 | // 7 | 8 | import UIKit 9 | import AdSupport 10 | 11 | public class LGLDevice { 12 | 13 | ///设备整个屏幕的大小 14 | public static var screenBounds: CGRect { 15 | return UIScreen.main.bounds 16 | } 17 | 18 | ///设备屏幕的宽 19 | public static var screenWidth: CGFloat { 20 | return UIScreen.main.bounds.width 21 | } 22 | 23 | ///设备屏幕的高 24 | public static var screenHeight: CGFloat { 25 | return UIScreen.main.bounds.height 26 | } 27 | 28 | ///设备屏幕的倍数 @2x @3x 29 | public static var screenScale: CGFloat { 30 | return UIScreen.main.scale 31 | } 32 | 33 | ///导航栏高度 34 | public static var navigationHeight: CGFloat { 35 | return iPhoneXType ? 88.0 : 64.0 36 | } 37 | 38 | /// 状态栏的高度 39 | public static var statusBarHeight: CGFloat { 40 | return iPhoneXType ? 44.0 : 20.0 41 | } 42 | 43 | /// navigationBar的高度 44 | public static var navigationBarHeight: CGFloat { 45 | return 44.0 46 | } 47 | 48 | /// Tabbar的高度 49 | public static var tabBarHeight: CGFloat { 50 | return iPhoneXType ? 83.0 : 49.0 51 | } 52 | 53 | ///底部安全域的高度 54 | public static var bottomSafeAreaHeight: CGFloat { 55 | return iPhoneXType ? 34.0 : 0.0 56 | } 57 | 58 | ///屏幕横向适配系数 以iphone6 为基准 59 | public static var widthRatio: CGFloat { 60 | return screenWidth / 375.0 61 | } 62 | 63 | /// 屏幕纵向适配系数 以iphone6 为基准 64 | public static var heightRatio: CGFloat { 65 | if iPhoneXType || iPhoneInch55 { 66 | return 1.0 67 | } else { 68 | return (screenHeight / 667.0) 69 | } 70 | } 71 | 72 | ///屏幕横向适配系数 以iphone6 为基准 默认屏幕宽度比例大于1(X:1.104)的默认乘以1.02 73 | public class func wRatio(ratio: CGFloat = 1.02) -> CGFloat { 74 | let wdr = screenWidth / 375.0 75 | if wdr > 1 { 76 | return 1.02 77 | } 78 | return wdr 79 | } 80 | 81 | /// 屏幕纵向适配系数 以iphone6 为基准 默认屏幕高度比例大于1的 乘以1.02 82 | public class func hRatio(ratio: CGFloat = 1.02) -> CGFloat { 83 | let htr = screenHeight / 375.0 84 | if htr > 1 { 85 | if iPhoneInch58 { 86 | return 1.00 87 | } 88 | return 1.02 89 | } else { 90 | return htr 91 | } 92 | } 93 | 94 | ///获取当前设备分辨率 95 | public static var phoneModelSize: CGSize { 96 | return lgl_basekit_currentPhoneModelSize() 97 | } 98 | 99 | ///比较两个设备的分辨率(跟当前的设备比较) 100 | @discardableResult 101 | public class func phoneEqualTo(_ size: CGSize) -> Bool { 102 | return lgl_basekit_phoneEqualTo(size) 103 | } 104 | 105 | ///判断IPad 106 | public static var iPadType: Bool { 107 | return lgl_basekit_isIPadType() 108 | } 109 | 110 | ///判断是否是齐刘海设备系列 111 | public static var iPhoneXType: Bool { 112 | return lgl_basekit_isPhoneXType() 113 | } 114 | 115 | ///判断6.5Inch iPhone XS Max 116 | public static var iPhoneInch65: Bool { 117 | return lgl_basekit_iPhoneInch65() 118 | } 119 | 120 | ///判断6.1Inch iPhone XR 121 | public static var iPhoneInch61: Bool { 122 | return lgl_basekit_iPhoneInch61() 123 | } 124 | 125 | ///判断5.8Inch iPhone XS/ iPhone X 126 | public static var iPhoneInch58: Bool { 127 | return lgl_basekit_iPhoneInch58() 128 | } 129 | 130 | ///判断5.5Inch iPhone 6/6s/7/8 Plus 131 | public static var iPhoneInch55: Bool { 132 | return lgl_basekit_iPhoneInch55() 133 | } 134 | 135 | ///判断4.7Inch iPhone 6/6s/7/8 136 | public static var iPhoneInch47: Bool { 137 | return lgl_basekit_iPhoneInch47() 138 | } 139 | 140 | ///判断4Inch iPhone SE 141 | public static var iPhoneInch4: Bool { 142 | return lgl_basekit_iPhoneInch4() 143 | } 144 | 145 | //MARK: ------- 系统配置信息 146 | 147 | ///获取系统版本 148 | public static var systemVersion: String { 149 | return LGLDeviceSystem.systemVersion 150 | } 151 | 152 | ///获取系统名称 153 | public static var systemName: String { 154 | return LGLDeviceSystem.systemName 155 | } 156 | 157 | ///获取系统名称 iPhone", "iPod touch" 158 | public static var deviceModel: String { 159 | return LGLDeviceSystem.deviceModel 160 | } 161 | 162 | ///获取系统名称 localized version of model 163 | public static var deviceLocalizedModel: String { 164 | return LGLDeviceSystem.deviceLocalizedModel 165 | } 166 | 167 | ///获取设备名称 如 XXX的iphone 168 | public static var deviceUserName: String { 169 | return LGLDeviceSystem.deviceUserName 170 | } 171 | ///获取总的内存 172 | public static var deviceDiskTotalSize: String { 173 | return LGLDeviceSystem.deviceDiskTotalSize 174 | } 175 | 176 | ///获取可用的内存 177 | public static var deviceAvalibleDiskSize: String { 178 | return LGLDeviceSystem.deviceAvalibleDiskSize 179 | } 180 | 181 | ///获取运营商 182 | public static var supplier: String { 183 | return LGLDeviceSystem.supplier 184 | } 185 | 186 | /// 获取当前设备IP 187 | public static var deviceIP: String { 188 | return LGLDeviceSystem.deviceIP 189 | } 190 | 191 | ///获取cpu核数 192 | public static var deviceCpuCount: Int { 193 | return LGLDeviceSystem.deviceCpuCount 194 | } 195 | 196 | ///获取cpu类型 197 | public static var deviceCpuType: String { 198 | return LGLDeviceSystem.deviceCpuType 199 | } 200 | 201 | ///获取设备名称 202 | public static var deviceName: String { 203 | return LGLDeviceSystem.deviceName 204 | } 205 | 206 | // MARK: ------- APP信息 207 | 208 | ///App名称 iOS13 需要添加 info.plist里面添加 Bundle display name 获取失败则返回空字符串 209 | public static var appName: String { 210 | return lgl_basekit_appName() 211 | } 212 | 213 | /// App包名 获取失败则返回空字符串 214 | public static var appBundleId: String { 215 | if let identifier = Bundle.main.bundleIdentifier { 216 | return identifier 217 | } 218 | return "" 219 | } 220 | 221 | /// App版本号 获取失败则返回空字符串 222 | public static var appVersion: String { 223 | if let bundleDic = Bundle.main.infoDictionary, let varsion = bundleDic["CFBundleShortVersionString"] { 224 | return (varsion as! String) 225 | } 226 | return "" 227 | } 228 | 229 | /// AppIdfa 用户关闭,则返回空字符串 230 | public static var appIdfa: String { 231 | if ASIdentifierManager.shared().isAdvertisingTrackingEnabled { 232 | return ASIdentifierManager.shared().advertisingIdentifier.uuidString 233 | } 234 | return "" 235 | } 236 | 237 | /// AppIdfv 获取失败则返回空字符串 238 | public static var appIdfv: String { 239 | if let idForVendor = UIDevice.current.identifierForVendor { 240 | return idForVendor.uuidString 241 | } 242 | return "" 243 | } 244 | 245 | ///app工程名称 获取失败则返回空字符串 246 | public static var appBundleName: String { 247 | return lgl_basekit_appBundleName() 248 | } 249 | } 250 | 251 | 252 | 253 | 254 | private extension LGLDevice { 255 | 256 | // MARK: --------------------------- 设备系统信息 --------------------- 257 | 258 | ///App名称 获取失败则返回空字符串 259 | private class func lgl_basekit_appName() -> String { 260 | if let bundleDic = Bundle.main.infoDictionary, let name = bundleDic["CFBundleDisplayName"] { 261 | return (name as! String) 262 | } 263 | return "" 264 | } 265 | 266 | /// App包名 获取失败则返回空字符串 267 | private class func lgl_basekit_appBundleId() -> String { 268 | if let identifier = Bundle.main.bundleIdentifier { 269 | return identifier 270 | } 271 | return "" 272 | } 273 | 274 | /// App版本号 获取失败则返回空字符串 275 | private class func lgl_basekit_appVersion() -> String { 276 | if let bundleDic = Bundle.main.infoDictionary, let varsion = bundleDic["CFBundleShortVersionString"] { 277 | return (varsion as! String) 278 | } 279 | return "" 280 | } 281 | 282 | /// AppIdfa 用户关闭,则返回空字符串 283 | private class func lgl_basekit_appIdfa() -> String { 284 | if ASIdentifierManager.shared().isAdvertisingTrackingEnabled { 285 | return ASIdentifierManager.shared().advertisingIdentifier.uuidString 286 | } 287 | return "" 288 | } 289 | 290 | /// AppIdfv 获取失败则返回空字符串 291 | private class func lgl_basekit_appIdfv() -> String { 292 | if let idForVendor = UIDevice.current.identifierForVendor { 293 | return idForVendor.uuidString 294 | } 295 | return "" 296 | } 297 | 298 | ///app工程名称 获取失败则返回空字符串 299 | private class func lgl_basekit_appBundleName() -> String { 300 | if let bundleDic = Bundle.main.infoDictionary, let bundleName = bundleDic["CFBundleName"] { 301 | return (bundleName as! String) 302 | } 303 | return "" 304 | } 305 | 306 | 307 | //MARK: ---- 获取当前设备分辨率 ---- 308 | 309 | private class func lgl_basekit_currentPhoneModelSize() -> CGSize { 310 | if let phoneSize = UIScreen.main.currentMode?.size { 311 | return phoneSize 312 | } 313 | return CGSize.zero 314 | } 315 | 316 | //MARK: ---- 比较两个设备的分辨率(跟当前的设备比较) ---- 317 | 318 | private class func lgl_basekit_phoneEqualTo(_ size: CGSize) -> Bool { 319 | return lgl_basekit_currentPhoneModelSize().equalTo(size) 320 | } 321 | 322 | //MARK: ---- 判断IPad ---- 323 | 324 | private class func lgl_basekit_isIPadType() -> Bool { 325 | let faceIdiom = UIDevice.current.userInterfaceIdiom 326 | if faceIdiom == .pad { 327 | return true 328 | } 329 | return false 330 | } 331 | 332 | //MARK: ---- 判断是否是齐刘海设备系列 ---- 333 | 334 | private class func lgl_basekit_isPhoneXType() -> Bool { 335 | if (lgl_basekit_iPhoneInch65() || lgl_basekit_iPhoneInch58() || lgl_basekit_iPhoneInch61()) { 336 | return true 337 | } 338 | return false 339 | } 340 | 341 | //MARK: ---- 判断iPhone6.5 iPhone XS Max ---- 342 | 343 | private class func lgl_basekit_iPhoneInch65() -> Bool { 344 | guard (lgl_basekit_isIPadType() == false) else { return false } 345 | return lgl_basekit_phoneEqualTo(CGSize(width: 1242.0, height: 2688.0)) 346 | } 347 | 348 | //MARK: ---- 判断iPhone6.1 iPhone XR ---- 349 | private class func lgl_basekit_iPhoneInch61() -> Bool { 350 | guard (lgl_basekit_isIPadType() == false) else { return false } 351 | return lgl_basekit_phoneEqualTo(CGSize(width: 828.0, height: 1792.0)) 352 | } 353 | 354 | //MARK: ---- 判断iPhone5.8 iPhone XS/ iPhone X ---- 355 | 356 | private class func lgl_basekit_iPhoneInch58() -> Bool { 357 | guard (lgl_basekit_isIPadType() == false) else { return false } 358 | return lgl_basekit_phoneEqualTo(CGSize(width: 1125.0, height: 2436.0)) 359 | } 360 | 361 | //MARK: ---- 判断iPhone5.5 iPhone 8 Plus/ iPhone X ---- 362 | 363 | private class func lgl_basekit_iPhoneInch55() -> Bool { 364 | guard (lgl_basekit_isIPadType() == false) else { return false } 365 | return lgl_basekit_phoneEqualTo(CGSize(width: 1242.0, height: 2208.0)) 366 | } 367 | 368 | //MARK: ---- 判断iPhone4.7 iPhone 6/6s/7/8 ---- 369 | 370 | private class func lgl_basekit_iPhoneInch47() -> Bool { 371 | guard (lgl_basekit_isIPadType() == false) else { return false } 372 | return lgl_basekit_phoneEqualTo(CGSize(width: 750.0, height: 1334.0)) 373 | } 374 | 375 | //MARK: ---- 判断iPhone4 iPhone SE ---- 376 | 377 | private class func lgl_basekit_iPhoneInch4() -> Bool { 378 | guard (lgl_basekit_isIPadType() == false) else { return false } 379 | return lgl_basekit_phoneEqualTo(CGSize(width: 640.0, height: 1136.0)) 380 | } 381 | } 382 | 383 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLDeviceInfo/LGLDeviceSystem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLDeviceSystem.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/22. 6 | // 7 | 8 | import UIKit 9 | import CoreTelephony 10 | 11 | internal class LGLDeviceSystem { 12 | 13 | ///获取系统版本 14 | static var systemVersion: String { 15 | return UIDevice.current.systemVersion 16 | } 17 | 18 | ///获取系统名称 19 | static var systemName: String { 20 | return UIDevice.current.systemName 21 | } 22 | 23 | ///获取系统名称 iPhone", "iPod touch" 24 | static var deviceModel: String { 25 | return UIDevice.current.model 26 | } 27 | 28 | ///获取系统名称 localized version of model 29 | static var deviceLocalizedModel: String { 30 | return UIDevice.current.localizedModel 31 | } 32 | 33 | ///获取设备名称 如 XXX的iphone 34 | static var deviceUserName: String { 35 | return UIDevice.current.name 36 | } 37 | ///获取总的内存 38 | static var deviceDiskTotalSize: String { 39 | return lgl_basekit_fileSizeToString(fileSize: lgl_basekit_getTotalDiskSize()) 40 | } 41 | 42 | ///获取可用的内存 43 | static var deviceAvalibleDiskSize: String { 44 | return lgl_basekit_fileSizeToString(fileSize: lgl_basekit_getAvailableDiskSize()) 45 | } 46 | 47 | ///获取运营商 48 | static var supplier: String { 49 | return lgl_basekit_deviceSupplier() 50 | } 51 | 52 | /// 获取当前设备IP 53 | static var deviceIP: String { 54 | return lgl_basekit_deviceIP() 55 | } 56 | 57 | ///获取cpu核数 58 | static var deviceCpuCount: Int { 59 | return lgl_basekit_deviceCpuCount() 60 | } 61 | 62 | ///获取cpu类型 63 | static var deviceCpuType: String { 64 | return lgl_basekit_deviceCpuType() 65 | } 66 | 67 | ///获取设备名称 68 | static var deviceName: String { 69 | return lgl_basekit_deviceName() 70 | } 71 | } 72 | 73 | //MARK: ---------------------------------- 内部具体实现方法 ---------------------------------------- 74 | 75 | 76 | private extension LGLDeviceSystem { 77 | 78 | //MARK: --- 获取运营商 79 | 80 | private class func lgl_basekit_deviceSupplier() -> String { 81 | let info = CTTelephonyNetworkInfo() 82 | var supplier:String = "" 83 | if #available(iOS 12.0, *) { 84 | if let carriers = info.serviceSubscriberCellularProviders { 85 | if carriers.keys.count == 0 { 86 | return "无手机卡" 87 | } else { //获取运营商信息 88 | for (index, carrier) in carriers.values.enumerated() { 89 | guard carrier.carrierName != nil else { return "无手机卡" } 90 | //查看运营商信息 通过CTCarrier类 91 | if index == 0 { 92 | supplier = carrier.carrierName! 93 | } else { 94 | supplier = supplier + "," + carrier.carrierName! 95 | } 96 | } 97 | return supplier 98 | } 99 | } else{ 100 | return "无手机卡" 101 | } 102 | } else { 103 | if let carrier = info.subscriberCellularProvider { 104 | guard carrier.carrierName != nil else { return "无手机卡" } 105 | return carrier.carrierName! 106 | } else{ 107 | return "无手机卡" 108 | } 109 | } 110 | } 111 | 112 | //MARK: --- 获取当前设备IP 113 | 114 | private class func lgl_basekit_deviceIP() -> String { 115 | var addresses = [String]() 116 | var ifaddr : UnsafeMutablePointer? = nil 117 | if getifaddrs(&ifaddr) == 0 { 118 | var ptr = ifaddr 119 | while (ptr != nil) { 120 | let flags = Int32(ptr!.pointee.ifa_flags) 121 | var addr = ptr!.pointee.ifa_addr.pointee 122 | if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) { 123 | if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) { 124 | var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) 125 | if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count),nil, socklen_t(0), NI_NUMERICHOST) == 0) { 126 | if let address = String(validatingUTF8:hostname) { 127 | addresses.append(address) 128 | } 129 | } 130 | } 131 | } 132 | ptr = ptr!.pointee.ifa_next 133 | } 134 | freeifaddrs(ifaddr) 135 | } 136 | if let ipStr = addresses.first { 137 | return ipStr 138 | } else { 139 | return "" 140 | } 141 | } 142 | 143 | //MARK: --- 获取cpu核数类型 144 | 145 | private class func lgl_basekit_deviceCpuCount() -> Int { 146 | var ncpu: UInt = UInt(0) 147 | var len: size_t = MemoryLayout.size(ofValue: ncpu) 148 | sysctlbyname("hw.ncpu", &ncpu, &len, nil, 0) 149 | return Int(ncpu) 150 | } 151 | 152 | //MARK: --- 获取cpu类型 153 | 154 | private class func lgl_basekit_deviceCpuType() -> String { 155 | 156 | let HOST_BASIC_INFO_COUNT = MemoryLayout.stride/MemoryLayout.stride 157 | var size = mach_msg_type_number_t(HOST_BASIC_INFO_COUNT) 158 | var hostInfo = host_basic_info() 159 | _ = withUnsafeMutablePointer(to: &hostInfo) { 160 | $0.withMemoryRebound(to: integer_t.self, capacity:Int(size)){ 161 | host_info(mach_host_self(), Int32(HOST_BASIC_INFO), $0, &size) 162 | } 163 | } 164 | switch hostInfo.cpu_type { 165 | case CPU_TYPE_ARM: 166 | return "CPU_TYPE_ARM" 167 | case CPU_TYPE_ARM64: 168 | return "CPU_TYPE_ARM64" 169 | case CPU_TYPE_ARM64_32: 170 | return"CPU_TYPE_ARM64_32" 171 | case CPU_TYPE_X86: 172 | return "CPU_TYPE_X86" 173 | case CPU_TYPE_X86_64: 174 | return"CPU_TYPE_X86_64" 175 | case CPU_TYPE_ANY: 176 | return"CPU_TYPE_ANY" 177 | case CPU_TYPE_VAX: 178 | return"CPU_TYPE_VAX" 179 | case CPU_TYPE_MC680x0: 180 | return"CPU_TYPE_MC680x0" 181 | case CPU_TYPE_I386: 182 | return"CPU_TYPE_I386" 183 | case CPU_TYPE_MC98000: 184 | return"CPU_TYPE_MC98000" 185 | case CPU_TYPE_HPPA: 186 | return"CPU_TYPE_HPPA" 187 | case CPU_TYPE_MC88000: 188 | return"CPU_TYPE_MC88000" 189 | case CPU_TYPE_SPARC: 190 | return"CPU_TYPE_SPARC" 191 | case CPU_TYPE_I860: 192 | return"CPU_TYPE_I860" 193 | case CPU_TYPE_POWERPC: 194 | return"CPU_TYPE_POWERPC" 195 | case CPU_TYPE_POWERPC64: 196 | return"CPU_TYPE_POWERPC64" 197 | default: 198 | return "" 199 | } 200 | } 201 | 202 | 203 | //MARK: --- 获取设备名称 204 | 205 | private class func lgl_basekit_deviceName() -> String { 206 | var systemInfo = utsname() 207 | uname(&systemInfo) 208 | let machineMirror = Mirror(reflecting: systemInfo.machine) 209 | let identifier = machineMirror.children.reduce("") { identifier, element in 210 | guard let value = element.value as? Int8, value != 0 else { return identifier } 211 | return identifier + String(UnicodeScalar(UInt8(value))) 212 | } 213 | 214 | switch identifier { 215 | 216 | case "iPod1,1": return "iPod touch" 217 | case "iPod2,1": return "iPod touch (2nd generation)" 218 | case "iPod3,1": return "iPod touch (3rd generation)" 219 | case "iPod4,1": return "iPod touch (4th generation)" 220 | case "iPod5,1": return "iPod touch (5th generation)" 221 | case "iPod7,1": return "iPod touch (6th generation)" 222 | case "iPod9,1": return "iPod touch (7th generation)" 223 | 224 | ///iphone 225 | case "iPhone1,1": return "iPhone 1G" 226 | case "iPhone1,2": return "iPhone 3G" 227 | case "iPhone2,1": return "iPhone 3GS" 228 | case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4" 229 | case "iPhone4,1": return "iPhone 4S" 230 | case "iPhone5,1", "iPhone5,2": return "iPhone 5" 231 | case "iPhone5,3","iPhone5,4": return "iPhone 5C" 232 | case "iPhone6,1", "iPhone6,2": return "iPhone 5S" 233 | case "iPhone7,1": return "iPhone 6 Plus" 234 | case "iPhone7,2": return "iPhone 6" 235 | case "iPhone8,1": return "iPhone 6s" 236 | case "iPhone8,2": return "iPhone 6s Plus" 237 | case "iPhone8,4": return "iPhone SE" 238 | case "iPhone9,1","iPhone9,3": return "iPhone 7" 239 | case "iPhone9,2","iPhone9,4": return "iPhone 7 Plus" 240 | case "iPhone10,1","iPhone10,4": return "iPhone 8" 241 | case "iPhone10,2","iPhone10,5": return "iPhone 8 Plus" 242 | case "iPhone10,3","iPhone10,6": return "iPhone X" 243 | case "iPhone11,8": return "iPhone XR" 244 | case "iPhone11,2": return "iPhone XS" 245 | case "iPhone11,6": return "iPhone XS Max" 246 | case "iPhone12,1": return "iPhone 11" 247 | 248 | case "iPhone12,3": return "iPhone 11 Pro" 249 | case "iPhone12,5": return "iPhone 11 Pro Max" 250 | case "iPhone12,8": return "iPhone SE (2nd generation)" 251 | 252 | ///iPad 253 | case "iPad1,1": return "iPad" 254 | case "iPad1,2": return "iPad 3G" 255 | case "iPad2,1": return "iPad 2 (WiFi)" 256 | case "iPad2,2": return "iPad 2" 257 | case "iPad2,3": return "iPad 2 (CDMA)" 258 | case "iPad2,4": return "iPad 2" 259 | case "iPad2,5": return "iPad Mini (WiFi)" 260 | case "iPad2,6": return "iPad Mini" 261 | case "iPad2,7": return "iPad Mini (GSM+CDMA)" 262 | case "iPad3,1": return "iPad 3 (WiFi)" 263 | case "iPad3,2": return "iPad 3 (GSM+CDMA)" 264 | case "iPad3,3": return "iPad 3" 265 | case "iPad3,4": return "iPad 4 (WiFi)" 266 | case "iPad3,5": return "iPad 4" 267 | case "iPad3,6": return "iPad 4 (GSM+CDMA)" 268 | case "iPad4,1": return "iPad Air (WiFi)" 269 | case "iPad4,2", "iPad4,3": return "iPad Air (Cellular)" 270 | case "iPad4,4": return "iPad Mini 2 (WiFi)" 271 | case "iPad4,5": return "iPad Mini 2 (Cellular)" 272 | case "iPad4,6": return "iPad Mini 2" 273 | case "iPad4,7": return "iPad Mini 3" 274 | case "iPad4,8": return "iPad Mini 3" 275 | case "iPad4,9": return "iPad Mini 3" 276 | case "iPad5,1": return "iPad Mini 4 (WiFi)" 277 | case "iPad5,2": return "iPad Mini 4 (LTE)" 278 | case "iPad5,3": return "iPad Air 2" 279 | case "iPad5,4": return "iPad Air 2" 280 | case "iPad6,3": return "iPad Pro 9.7" 281 | case "iPad6,4": return "iPad Pro 9.7" 282 | case "iPad6,7": return "iPad Pro 12.9" 283 | case "iPad6,8": return "iPad Pro 12.9" 284 | case "iPad6,11": return "iPad 5 (WiFi)" 285 | case "iPad6,12": return "iPad 5 (Cellular)" 286 | case "iPad7,1": return "iPad Pro 12.9 inch 2nd gen (WiFi)" 287 | case "iPad7,2": return "iPad Pro 12.9 inch 2nd gen (Cellular)" 288 | case "iPad7,3": return "iPad Pro 10.5 inch (WiFi)" 289 | case "iPad7,4": return "iPad Pro 10.5 inch (Cellular)" 290 | case "iPad7,5","iPad7,6": return "iPad (6th generation)" 291 | case "iPad7,11", "iPad7,12": return "iPad (7th generation)" 292 | case "iPad8,1","iPad8,2","iPad8,3","iPad8,4": return "iPad Pro (11-inch)" 293 | case "iPad8,5","iPad8,6","iPad8,7","iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)" 294 | 295 | case "iPad8,9","iPad8,10": return "iPad Pro (11-inch) (2nd generation)" 296 | case "iPad8,11","iPad8,12": return "iPad Pro (12.9-inch) (4th generation)" 297 | 298 | case "iPad11,1","iPad11,2": return "iPad mini (5th generation)" 299 | case "iPad11,3","iPad11,4": return "iPad Air (3rd generation)" 300 | 301 | //Apple Watch 302 | case "Watch1,1","Watch1,2": return "Apple Watch (1st generation)" 303 | case "Watch2,6","Watch2,7": return "Apple Watch Series 1" 304 | case "Watch2,3","Watch2,4": return "Apple Watch Series 2" 305 | case "Watch4,1","Watch4,2","Watch4,3","Watch4,4": return "Apple Watch Series 4" 306 | case "Watch3,1","Watch3,2","Watch3,3","Watch3,4": return "Apple Watch Series 3" 307 | 308 | 309 | ///AppleTV 310 | case "AppleTV2,1": return "Apple TV 2" 311 | case "AppleTV3,1": return "Apple TV 3" 312 | case "AppleTV3,2": return "Apple TV 3" 313 | case "AppleTV5,3": return "Apple TV 4" 314 | case "AppleTV6,2": return "Apple TV 4K" 315 | 316 | ///AirPods 317 | case "AirPods1,1": return "AirPods (1st generation)" 318 | case "AirPods2,1": return "AirPods (2nd generation)" 319 | case "iProd8,1": return "AirPods Pro" 320 | 321 | ///HomePod 322 | case "AudioAccessory1,1", "AudioAccessory1,2": return "HomePod" 323 | ///Simulator 324 | case "i386": return "Simulator" 325 | case "x86_64": return "Simulator" 326 | default: return identifier 327 | } 328 | } 329 | 330 | private class func lgl_basekit_blankof(type:T.Type) -> T { 331 | let ptr = UnsafeMutablePointer.allocate(capacity: MemoryLayout.size) 332 | let val = ptr.pointee 333 | return val 334 | } 335 | 336 | //MARK: --- 磁盘总大小 337 | 338 | private class func lgl_basekit_getTotalDiskSize() -> Int64 { 339 | var fs = lgl_basekit_blankof(type: statfs.self) 340 | if statfs("/var",&fs) >= 0{ 341 | return Int64(UInt64(fs.f_bsize) * fs.f_blocks) 342 | } 343 | return -1 344 | } 345 | 346 | //MARK: --- 磁盘可用大小 347 | 348 | private class func lgl_basekit_getAvailableDiskSize() -> Int64 { 349 | var fs = lgl_basekit_blankof(type: statfs.self) 350 | if statfs("/var",&fs) >= 0{ 351 | return Int64(UInt64(fs.f_bsize) * fs.f_bavail) 352 | } 353 | return -1 354 | } 355 | 356 | //MARK: --- 将大小转换成字符串用以显示 357 | 358 | private class func lgl_basekit_fileSizeToString(fileSize:Int64) -> String { 359 | 360 | let fileSize1 = CGFloat(fileSize) 361 | 362 | let KB:CGFloat = 1024 363 | let MB:CGFloat = KB*KB 364 | let GB:CGFloat = MB*KB 365 | 366 | if fileSize < 10 { 367 | return "0 B" 368 | 369 | } else if fileSize1 < KB { 370 | return "< 1 KB" 371 | } else if fileSize1 < MB { 372 | return String(format: "%.1f KB", CGFloat(fileSize1)/KB) 373 | } else if fileSize1 < GB { 374 | return String(format: "%.1f MB", CGFloat(fileSize1)/MB) 375 | } else { 376 | return String(format: "%.1f GB", CGFloat(fileSize1)/GB) 377 | } 378 | } 379 | } 380 | 381 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/NSRegularExpression+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSRegularExpression+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | // MARK: 匹配 - Matching 11 | public extension NSRegularExpression { 12 | 13 | class func lgl_isMatch(string: String, pattern: String) -> Bool { 14 | return lgl_isMatch(string: string, pattern: pattern, ignoreCase: false) 15 | } 16 | 17 | class func lgl_isMatch(string: String, pattern: String, ignoreCase: Bool) -> Bool { 18 | var isMatch = false 19 | do { 20 | // 正则匹配选项 21 | let options: NSRegularExpression.Options = ignoreCase ? [NSRegularExpression.Options.caseInsensitive] : [] 22 | let regular = try NSRegularExpression(pattern: pattern, options: options) 23 | let range = NSRange(location: 0, length: string.count) 24 | let numbers = regular.numberOfMatches(in: string, options: [], range: range) 25 | isMatch = numbers > 0 ? true : false 26 | } catch { 27 | isMatch = false 28 | print(error) 29 | } 30 | return isMatch 31 | } 32 | } 33 | 34 | // MARK: 替换 - Replacement 35 | public extension NSRegularExpression { 36 | class func lgl_replacement(string: String, replace: String, pattern: String) -> String { 37 | var value = string 38 | do { 39 | let regular = try NSRegularExpression(pattern: pattern, options: []) 40 | let range = NSRange(location: 0, length: string.count) 41 | value = regular.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: replace) 42 | } catch { 43 | print(error) 44 | } 45 | return value 46 | } 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/NotificationCenter+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NotificationCenter+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension NotificationCenter { 11 | 12 | static func lgl_addObserver(name: String, object: Any?, queue: OperationQueue?, using: @escaping (Notification) -> Void) { 13 | self.default.addObserver(forName: NSNotification.Name.init(rawValue: name), object: object, queue: queue, using: using) 14 | } 15 | 16 | static func lgl_addObserver(_ observer: Any, _ selector: Selector, _ name: String, object anObject: Any?) { 17 | self.default.addObserver(observer, selector: selector, name: NSNotification.Name.init(rawValue: name), object: anObject) 18 | } 19 | 20 | static func lgl_post(_ notification: Notification) { 21 | self.default.post(notification) 22 | } 23 | 24 | static func lgl_post(_ name: String, _ object: Any?) { 25 | self.default.post(name: NSNotification.Name.init(rawValue: name), object: object) 26 | } 27 | 28 | static func lgl_post(_ name: String, _ object: Any?, _ userInfo: [AnyHashable : Any]? = nil) { 29 | self.default.post(name: NSNotification.Name.init(rawValue: name), object: object, userInfo: userInfo) 30 | } 31 | 32 | static func lgl_removeObserver(_ observer: Any) { 33 | self.default.removeObserver(observer) 34 | } 35 | 36 | static func lgl_removeObserver(_ observer: Any, name: String, object: Any?) { 37 | self.default.removeObserver(observer, name: NSNotification.Name.init(rawValue: name), object: object) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/String+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public enum XLRegularString: String { 11 | /// 手机号格式 - 只允许数字,示例:13512345678 12 | case phoneNumber = "^(1)(\\d{10})$" 13 | 14 | /// 固定电话格式 - 只允许数字,示例:075511223344 或 02011223344 15 | case telephoneNumber = "^(0)(\\d{2,3})(\\d{7,8})$" 16 | 17 | /// 验证码格式 - 只允许数字,示例:1234 或 123456 (4位或6位的验证码) 18 | case verificationCode = "^(\\d{4}|\\d{6})$" 19 | 20 | /// 邮箱格式 - 只允许英文字母、数字、下划线、英文句号、以及中划线组成 y-30@qq.com 21 | case email = "^([\\w-]+)(@)([A-Za-z\\d]+)(\\.)([A-Za-z\\d]+)$" 22 | 23 | /// 用户名格式 - 只允许使用字母、数字、下滑线、横杠,3~20位 24 | case username = "^[\\w-]{3,20}$" 25 | 26 | /// 密码格式 - 0.字母和数字组合的字符串 1.至少包含一个字母;2.至少包含一个数字;3,长度为6~20位 27 | // case password = "^(?![0-9]+$)(?![A-Za-z]+$)[A-Za-z0-9]{6,20}$" 28 | case password = "^(?=.*[\\d]+)(?=.*[A-Za-z]+)([A-Za-z\\d]{6,20})$" 29 | 30 | /// 邮政编码格式 - 必须由6位数字组成 31 | case postalCode = "^\\d{6}$" 32 | 33 | /// 身份证号格式 - 15位或18位的身份证号 34 | case idCardNumber = "^(\\d{14}|\\d{17})([\\dxX])$" 35 | 36 | /// 数字 - 包含数字 37 | case hasNumber = "[\\d]+" 38 | 39 | /// 数字 - 只包含数字 40 | case allNumber = "^[\\d]+$" 41 | 42 | /// 小写字母 - 包含小写字母 43 | case hasLowerCase = "[a-z]+" 44 | 45 | /// 小写字母 - 只包含小写字母 46 | case allLowerCase = "^[a-z]+$" 47 | 48 | /// 大写字母 - 包含大写字母 49 | case hasUpperCase = "[A-Z]+" 50 | 51 | /// 大写字母 - 只包含大写字母 52 | case allUpperCase = "^[A-Z]+$" 53 | 54 | /// 字母 - 包含字母 55 | case hasLetter = "[A-Za-z]+" 56 | 57 | /// 字母 - 只包含字母 58 | case allLetter = "^[A-Za-z]+$" 59 | 60 | /// 数字和字母 - 包含数字或字母 61 | case hasNumberLetter = "[A-Za-z\\d]+" 62 | 63 | /// 数字和字母 - 同时包含数字和密码 64 | case bothNumberLetter = "^(?![0-9]+$)(?![A-Za-z]+$)[A-Za-z0-9]{2,}$" 65 | 66 | /// 表情符 - 包含表情符 67 | case hasEmoji = "[\\ud83c\\udc00-\\ud83c\\udfff]|[\\ud83d\\udc00-\\ud83d\\udfff]|[\\u2600-\\u27ff]+" 68 | 69 | /// 表情符 - 只包含表情符 70 | case allEmoji = "^[\\ud83c\\udc00-\\ud83c\\udfff]|[\\ud83d\\udc00-\\ud83d\\udfff]|[\\u2600-\\u27ff]+$" 71 | 72 | /// 中文 - 包含中文 73 | case hasChinese = "[\\u4E00-\\u9FA5]+" 74 | /// 中文 - 只包含中文 75 | case allChinese = "^[\\u4E00-\\u9FA5]+$" 76 | 77 | /// 限制输入: 只允许输入数字、字母、中文字符、九宫格输入法(➋➌➍➎➏➐➑➒)、·•、限制 1-30,应用场景:用户名 78 | case limitInput1 = "^[·•➋➌➍➎➏➐➑➒A-Za-z0-9\\u4E00-\\u9FA5]{1,30}$" 79 | 80 | /// 限制输入: 只允许输入 0-9和xX的字符,应用场景:身份证号 81 | case limitInput2 = "^[0-9xX]+$" 82 | } 83 | 84 | public extension String { 85 | ///限制只能输入数字格式 86 | var lgl_limitNumber: Bool { 87 | let str = "0123456789\n" 88 | return lgl_basekit_judgeCharacterSetWithStr(str, self) 89 | } 90 | 91 | ///限制只能输入邮箱格式 92 | var lgl_limitEmial: Bool { 93 | let str = "[a-zA-Z0-9@.]*" 94 | return lgl_basekit_judgeCharacterSetWithStr(str, self) 95 | } 96 | 97 | ///限制固定电话输入格式 98 | var lgl_limitTelephone: Bool { 99 | let str = "^(0[0-9]{2,3})?([2-9][0-9]{6,7})" 100 | return lgl_basekit_judgeCharacterSetWithStr(str, self) 101 | } 102 | 103 | ///限制输入数字、字母、中文字符格式 104 | var lgl_limitOutSpecial: Bool { 105 | let str = "[a-zA-Z0-9\\u4E00-\\u9FA5]+" 106 | return lgl_basekit_judgeCharacterSetWithStr(str, self) 107 | } 108 | 109 | ///限制输入姓名格式为 中文数字英文和·• maxLimit最大位数 110 | func lgl_limitChineseName(_ maxLimit: Int) -> Bool { 111 | if self.count == 0 { 112 | return true 113 | } 114 | let regextestStr: String = "[·•➋➌➍➎➏➐➑➒a-zA-Z0-9\\u4e00-\\u9fa5]{0,\(maxLimit)}" 115 | return lgl_basekit_judgeCharacterSetWithStr(regextestStr, self) 116 | } 117 | ///限制身份证能输入的格式 118 | var lgl_limitIdCarNumber: Bool { 119 | return lgl_basekit_judgeCharacterSetWithStr("0123456789xX", self) 120 | } 121 | /////限制能输入大小写字母和数字的格式 122 | var lgl_limitLetterNumber: Bool { 123 | let str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 124 | return lgl_basekit_judgeCharacterSetWithStr(str, self) 125 | } 126 | } 127 | 128 | public extension String { 129 | 130 | /// 字符串参数 131 | func lgl_isMatch(regularString: String) -> Bool { 132 | return NSRegularExpression.lgl_isMatch(string: self, pattern: regularString) 133 | } 134 | 135 | // 枚举值参数 136 | func lgl_isMatch(regularString: XLRegularString) -> Bool { 137 | return NSRegularExpression.lgl_isMatch(string: self, pattern: regularString.rawValue) 138 | } 139 | 140 | /// 判断手机号 141 | func lgl_isPhoneNumber() -> Bool { 142 | return lgl_isMatch(regularString: .phoneNumber) 143 | } 144 | 145 | /// 判断固定电话 146 | func lgl_isTelePhoneNumber() -> Bool { 147 | return lgl_isMatch(regularString: .telephoneNumber) 148 | } 149 | 150 | /// 是否匹配验证码格式 151 | func lgl_isVericationCode() -> Bool { 152 | return lgl_isMatch(regularString: .verificationCode) 153 | } 154 | 155 | /// 判断是否匹配邮箱格式 156 | func lgl_isEmail() -> Bool { 157 | return lgl_isMatch(regularString: .email) 158 | } 159 | 160 | /// 判断用户名 161 | func lgl_isUsername() -> Bool { 162 | return lgl_isMatch(regularString: .username) 163 | } 164 | 165 | /// 判断密码 166 | func lgl_isPassword() -> Bool { 167 | return lgl_isMatch(regularString: .password) 168 | } 169 | 170 | /// 判断邮政编码 171 | func lgl_isPostalCode() -> Bool { 172 | return lgl_isMatch(regularString: .postalCode) 173 | } 174 | 175 | /// 判断身份证号 176 | func lgl_isIDCardNumber() -> Bool { 177 | return lgl_isMatch(regularString: .idCardNumber) 178 | } 179 | 180 | /// 是否包含数字的字符串 181 | func lgl_hasNumber() -> Bool { 182 | return lgl_isMatch(regularString: .hasNumber) 183 | } 184 | 185 | /// 是否纯数字字符串 186 | func lgl_allNumber() -> Bool { 187 | return lgl_isMatch(regularString: .allNumber) 188 | } 189 | 190 | /// 是否包含小写字母的字符串 191 | func lgl_hasLowerCase() -> Bool { 192 | return lgl_isMatch(regularString: .hasLowerCase) 193 | } 194 | 195 | /// 是否纯小写字母字符串 196 | func lgl_allLowerCase() -> Bool { 197 | return lgl_isMatch(regularString: .allLowerCase) 198 | } 199 | 200 | /// 是否包含大写字母的字符串 201 | func lgl_hasUpperCase() -> Bool { 202 | return lgl_isMatch(regularString: .hasUpperCase) 203 | } 204 | 205 | /// 是否纯大写字母字符串 206 | func lgl_allUpperCase() -> Bool { 207 | return lgl_isMatch(regularString: .allUpperCase) 208 | } 209 | 210 | /// 是否包含字母的字符串 211 | func lgl_hasLetter() -> Bool { 212 | return lgl_isMatch(regularString: .hasLetter) 213 | } 214 | 215 | /// 是否纯字母字符串 216 | func lgl_allLetter() -> Bool { 217 | return lgl_isMatch(regularString: .allLetter) 218 | } 219 | 220 | /// 是否包含数字或字母的字符串 221 | func lgl_hasNumberOrLetter() -> Bool { 222 | return lgl_isMatch(regularString: .hasNumberLetter) 223 | } 224 | 225 | /// 是否同时包含数字和密码的字符串 226 | func lgl_bothNumberAndLetter() -> Bool { 227 | return lgl_isMatch(regularString: .bothNumberLetter) 228 | } 229 | 230 | /// 是否包含表情符 231 | func lgl_hasEmoji() -> Bool { 232 | return lgl_isMatch(regularString: .hasEmoji) 233 | } 234 | /// 是否包含中文字符 235 | func lgl_hasChinese() -> Bool { 236 | return lgl_isMatch(regularString: .hasChinese) 237 | } 238 | } 239 | 240 | // MARK: 给字符串添加下标索引存取功能 241 | 242 | public extension String { 243 | subscript(index: Int) -> String { 244 | get { 245 | return String(self[self.index(self.startIndex, offsetBy: index)]) 246 | } 247 | 248 | set { 249 | let tmp = self 250 | self = "" 251 | for (idx, item) in tmp.enumerated() { 252 | if idx == index { 253 | self += "\(newValue)" 254 | }else{ 255 | self += "\(item)" 256 | } 257 | } 258 | } 259 | } 260 | 261 | /// 根据开始位置和长度截取字符串 262 | func subString(start: Int, length: Int = -1) -> String { 263 | var len = length 264 | if len == -1 { 265 | len = self.count - start 266 | } 267 | let st = self.index(startIndex, offsetBy: start) 268 | let en = self.index(st, offsetBy: len) 269 | return String(self[st ..< en]) 270 | } 271 | } 272 | 273 | 274 | // MARK: --------------- NSAttributedString 275 | 276 | public extension String { 277 | 278 | 279 | ///获取某一段文字的CGSize 280 | func lgl_getStrSize(_ font: UIFont, _ maxWidth: CGFloat) -> CGSize { 281 | return lgl_basekit_getStrSize(font, maxWidth) 282 | } 283 | 284 | ///修改指定文字的字体大小 和 颜色 285 | func lgl_modifyRangeText(_ changeText: String, _ changeColor: UIColor, _ changeFont: UIFont) -> NSAttributedString { 286 | return lgl_basekit_modifyRangeText(changeText, changeColor, changeFont) 287 | } 288 | 289 | ///设置行间距 290 | func lgl_modifyLineHeight(_ lineHeight: CGFloat, _ alignment: NSTextAlignment) -> NSAttributedString { 291 | return lgl_basekit_modifyLineHeight(lineHeight, alignment) 292 | } 293 | 294 | ///设置指定范围内文字的颜色 295 | func lgl_modifyRangeTextColor(_ range: NSRange, _ changeColor: UIColor) -> NSAttributedString { 296 | return lgl_basekit_modifyRangeTextColor(range, changeColor) 297 | } 298 | 299 | ///设置指定范围内文字的下划线 颜色 300 | func lgl_modifyRangeUnderLine( _ range: NSRange, _ rangeColor: UIColor, _ lineColor:UIColor) -> NSAttributedString { 301 | return lgl_basekit_modifyRangeUnderLine(range, rangeColor, lineColor) 302 | } 303 | 304 | ///设置行间距 和 首行缩进缩进两个字符 305 | func lgl_setHeadIndent(_ lineHeight: CGFloat, _ font: UIFont) -> NSAttributedString { 306 | return lgl_basekit_setHeadIndent(lineHeight, font) 307 | } 308 | 309 | ///设置一条文字中间的线 310 | func lgl_setThroughLine(_ range: NSRange, _ lineColor: UIColor) -> NSAttributedString { 311 | return lgl_basekit_setThroughLine(range, lineColor) 312 | } 313 | 314 | ///获取设置行高以后的字符串的Size(高) 315 | func lgl_getLineHeightSize(_ lineHeight: CGFloat, _ font: UIFont, _ maxW: CGFloat) -> CGSize { 316 | return lgl_basekit_getLineHeightWithSize(lineHeight, font, maxW) 317 | } 318 | 319 | ///文字用*号替换处理(eg:15118999 -> 151*****99) 320 | func lgl_replaceWithAsterisk(_ range: NSRange) -> String { 321 | return lgl_basekit_replaceWithAsterisk(range) 322 | } 323 | } 324 | 325 | 326 | fileprivate extension String { 327 | ///判断文字的格式是否满足 328 | func lgl_basekit_judgeCharacterSetWithStr(_ characterStr: String, _ judgeText: String) -> Bool { 329 | let characterSet = NSCharacterSet(charactersIn: characterStr).inverted 330 | let filterArr:[String] = judgeText.components(separatedBy: characterSet) 331 | let filterstr:String = filterArr.joined(separator: "") 332 | let result:Bool = judgeText == filterstr 333 | if result { 334 | return true 335 | } 336 | return false 337 | } 338 | 339 | ///文字用*号替换处理 340 | func lgl_basekit_replaceWithAsterisk(_ range: NSRange) -> String { 341 | if self.count == 0 { 342 | return "" 343 | } 344 | var reultStr = NSString(string: self) 345 | var satrtLoctaion = range.location 346 | for _ in 0 ..< range.length { 347 | let replaceRange = NSRange(location: satrtLoctaion, length: 1) 348 | reultStr = reultStr.replacingCharacters(in: replaceRange, with: "*") as NSString 349 | satrtLoctaion = satrtLoctaion + 1 350 | } 351 | return reultStr as String 352 | } 353 | 354 | 355 | ///获取某一段文字的CGSize 356 | func lgl_basekit_getStrSize(_ font: UIFont, _ maxWidth: CGFloat) -> CGSize { 357 | let attrs = [NSAttributedString.Key.font: font] 358 | let showText = self as NSString 359 | let textRect:CGRect = showText.boundingRect(with: CGSize(width: maxWidth, height: CGFloat(MAXFLOAT)), options:[.usesLineFragmentOrigin, .truncatesLastVisibleLine, .usesFontLeading], attributes: attrs, context: nil) 360 | return textRect.size 361 | } 362 | 363 | ///修改指定文字的字体大小 和 颜色 364 | func lgl_basekit_modifyRangeText(_ changeText: String, _ changeColor: UIColor, _ changeFont: UIFont) -> NSAttributedString { 365 | let attributStr = NSMutableAttributedString(string: self) 366 | let textStr = self as NSString 367 | let range = textStr.range(of: changeText) 368 | attributStr.addAttribute(NSAttributedString.Key.font, value: changeFont, range: range) 369 | attributStr.addAttribute(NSAttributedString.Key.foregroundColor, value: changeColor, range: range) 370 | return attributStr 371 | } 372 | 373 | ///设置行间距 374 | func lgl_basekit_modifyLineHeight(_ lineHeight: CGFloat, _ alignment: NSTextAlignment) -> NSAttributedString { 375 | let attributStr = NSMutableAttributedString(string: self) 376 | let paragraphStyle = NSMutableParagraphStyle() 377 | paragraphStyle.lineSpacing = lineHeight 378 | paragraphStyle.alignment = alignment;//文本对齐方式 379 | attributStr.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: self.count)) 380 | return attributStr 381 | } 382 | 383 | ///设置指定范围内文字的颜色 384 | func lgl_basekit_modifyRangeTextColor(_ range: NSRange, _ changeColor: UIColor) -> NSAttributedString { 385 | let attributStr = NSMutableAttributedString(string: self) 386 | attributStr.addAttribute(NSAttributedString.Key.foregroundColor, value: changeColor, range: range) 387 | return attributStr 388 | } 389 | 390 | 391 | ///设置指定范围内文字的下划线 颜色 392 | func lgl_basekit_modifyRangeUnderLine( _ range: NSRange, _ rangeColor: UIColor, _ lineColor:UIColor) -> NSAttributedString { 393 | let attributStr = NSMutableAttributedString(string: self) 394 | attributStr.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range) 395 | attributStr.addAttribute(NSAttributedString.Key.foregroundColor, value: rangeColor, range: range) 396 | attributStr.addAttribute(NSAttributedString.Key.underlineColor, value: lineColor, range: range) 397 | return attributStr 398 | } 399 | 400 | ///设置行间距 和 首行缩进缩进两个字符 401 | func lgl_basekit_setHeadIndent(_ lineHeight: CGFloat, _ font: UIFont) -> NSAttributedString { 402 | let attributStr = NSMutableAttributedString(string: self) 403 | let paragraphStyle = NSMutableParagraphStyle() 404 | paragraphStyle.lineSpacing = lineHeight 405 | paragraphStyle.alignment = .justified// 对齐方式 406 | paragraphStyle.firstLineHeadIndent = font.pointSize * 2 // 首行缩进 407 | paragraphStyle.headIndent = 0.0 // 头部缩进 408 | paragraphStyle.tailIndent = 0.0 // 尾部缩进 409 | attributStr.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: self.count)) 410 | return attributStr 411 | } 412 | ///设置一条文字中间的线 413 | func lgl_basekit_setThroughLine(_ range: NSRange, _ lineColor: UIColor) -> NSAttributedString { 414 | let attributeStr = NSMutableAttributedString(string: self) 415 | attributeStr.addAttributes([NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue, NSAttributedString.Key.strikethroughColor: lineColor], range: range) 416 | return attributeStr 417 | } 418 | 419 | ///获取设置行高以后的字符串的高度 420 | func lgl_basekit_getLineHeightWithSize(_ lineHeight: CGFloat, _ font: UIFont, _ maxW: CGFloat) -> CGSize { 421 | let paragraphStyle = NSMutableParagraphStyle() 422 | paragraphStyle.lineSpacing = lineHeight 423 | let text = self as NSString 424 | let textRect = text.boundingRect(with: CGSize(width: maxW, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.paragraphStyle:paragraphStyle ], context: nil) 425 | return textRect.size 426 | } 427 | } 428 | 429 | 430 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIBarButtonItem+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UIBarButtonItem { 11 | 12 | ///设置图片item 里面已处理保持原图 13 | static func lgl_item(_ image: UIImage, _ style: UIBarButtonItem.Style = .plain, _ target: Any?, _ action: Selector?) -> UIBarButtonItem { 14 | let originalImage = image.withRenderingMode(.alwaysOriginal) 15 | return UIBarButtonItem(image: originalImage, style: style, target: target, action: action) 16 | } 17 | 18 | ///设置item 标题 19 | static func lgl_item(_ title: String, _ style: UIBarButtonItem.Style = .plain, _ target: Any?, _ action: Selector?) -> UIBarButtonItem { 20 | return UIBarButtonItem(title: title, style: style, target: target, action: action) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIButton+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UIButton { 11 | 12 | ////初始化button 设置 标题文字、文字颜色、文字大小 13 | class func lgl_button(_ title:String, _ titleColor:UIColor, _ backgroundColor: UIColor, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 14 | return lgl_basekit_button(title, titleColor, backgroundColor, font, target, action) 15 | } 16 | 17 | ////初始化button 设置 标题文字、文字颜色、文字大小 18 | class func lgl_button(_ title:String, _ titleColor:UIColor, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 19 | return lgl_basekit_button(title, titleColor, font, target, action) 20 | } 21 | 22 | ////初始化button 设置 标题文字、文字颜色、文字大小、图片 23 | class func lgl_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 24 | return lgl_basekit_button(title, titleColor, imageName, font, target, action) 25 | } 26 | 27 | ////初始化button 设置 标题文字、文字颜色、文字大小、背景图片 28 | class func lgl_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 29 | return lgl_basekit_button(title, titleColor, backgroundImage, font, target, action) 30 | } 31 | 32 | ////初始化button 没有点击 设置 标题文字、文字颜色、文字大小、图片 33 | class func lgl_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont) -> Self { 34 | return lgl_basekit_button(title, titleColor, imageName, font) 35 | } 36 | 37 | ////初始化button 设置 标题文字、文字颜色、文字大小、选中和未选中图片 38 | class func lgl_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ selectedImageName: String, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 39 | return lgl_basekit_button(title, titleColor, imageName, selectedImageName, font, target, action) 40 | } 41 | 42 | ////初始化button 设置 标题文字、文字颜色、文字大小、选中和未选中背景图片 43 | class func lgl_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ selectedBackgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 44 | return lgl_basekit_button(title, titleColor, backgroundImage, selectedBackgroundImage, font, target, action) 45 | } 46 | 47 | //MARK: ---- 实例方法 48 | 49 | ////设置button 标题文字、文字颜色、文字大小 50 | func lgl_button(_ title:String, _ titleColor:UIColor, _ backgroundColor: UIColor, _ font:UIFont, _ target:Any, _ action:Selector) { 51 | lgl_basekit_button(title, titleColor, backgroundColor, font, target, action) 52 | } 53 | 54 | ////设置button 标题文字、文字颜色、文字大小 55 | func lgl_button(_ title:String, _ titleColor:UIColor, _ font:UIFont, _ target:Any, _ action:Selector) { 56 | lgl_basekit_button(title, titleColor, font, target, action) 57 | } 58 | 59 | ////设置button 标题文字、文字颜色、文字大小、图片 60 | func lgl_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont, _ target:Any, _ action:Selector) { 61 | lgl_basekit_button(title, titleColor, imageName, font, target, action) 62 | } 63 | 64 | ////设置button 标题文字、文字颜色、文字大小、背景图片 65 | func lgl_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) { 66 | lgl_basekit_button(title, titleColor, backgroundImage, font, target, action) 67 | } 68 | 69 | ////设置button 没有点击 标题文字、文字颜色、文字大小、图片 70 | func lgl_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont) { 71 | lgl_basekit_button(title, titleColor, imageName, font) 72 | } 73 | 74 | ///设置图片 75 | func lgl_buttonImage(_ normalImageName: String, _ selectImageName: String) { 76 | lgl_basekit_buttonImage(normalImageName, selectImageName) 77 | } 78 | 79 | ///设置背景图片 80 | func lgl_buttonBackgroundImage(_ normalImageName: String, _ selectImageName: String) { 81 | lgl_basekit_buttonBackgroundImage(normalImageName, selectImageName) 82 | } 83 | 84 | ///设置圆角 85 | func lgl_buttonRadius(_ cornerRadius: CGFloat) { 86 | lgl_basekit_buttonRadius(cornerRadius) 87 | } 88 | 89 | ///设置边框颜色、边框宽度 90 | func lgl_buttonBorder(_ borderColor: UIColor, _ borderWidth: CGFloat) { 91 | lgl_basekit_buttonBorder(borderColor, borderWidth) 92 | } 93 | 94 | ///设置边框颜色、边框宽度、圆角 95 | func lgl_buttonBorder(_ borderColor: UIColor, _ borderWidth: CGFloat, _ cornerRadius: CGFloat) { 96 | lgl_basekit_buttonBorder(borderColor, borderWidth, cornerRadius) 97 | } 98 | } 99 | 100 | 101 | fileprivate extension UIButton { 102 | 103 | ////初始化button 设置 标题文字、文字颜色、文字大小 104 | class func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ backgroundColor: UIColor, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 105 | let button = self.init(type: .custom) 106 | button.setTitle(title, for: .normal) 107 | button.setTitleColor(titleColor, for: .normal) 108 | button.titleLabel?.font = font 109 | button.backgroundColor = backgroundColor 110 | button.addTarget(target, action:action, for: .touchUpInside) 111 | return button 112 | } 113 | 114 | ////初始化button 设置 标题文字、文字颜色、文字大小 115 | class func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 116 | return lgl_basekit_button(title, titleColor, .clear, font, target, action) 117 | } 118 | 119 | ////初始化button 设置 标题文字、文字颜色、文字大小、图片 120 | class func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 121 | let button = lgl_basekit_button(title, titleColor, .clear, font, target, action) 122 | if let image = UIImage(named: imageName) { 123 | button.setImage(image, for: .normal) 124 | } 125 | return button 126 | } 127 | 128 | ////初始化button 设置 标题文字、文字颜色、文字大小、选中和未选中图片 129 | class func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ selectedImageName: String, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 130 | let button = lgl_basekit_button(title, titleColor, .clear, font, target, action) 131 | button.lgl_basekit_buttonImage(imageName, selectedImageName) 132 | return button 133 | } 134 | 135 | ////初始化button 设置 标题文字、文字颜色、文字大小、背景图片 136 | class func lgl_basekit_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 137 | let button = lgl_basekit_button(title, titleColor, .clear, font, target, action) 138 | button.setBackgroundImage(backgroundImage, for: .normal) 139 | return button 140 | } 141 | 142 | ////初始化button 设置 标题文字、文字颜色、文字大小、选中和未选中背景图片 143 | class func lgl_basekit_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ selectedBackgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) -> Self { 144 | let button = lgl_basekit_button(title, titleColor, .clear, font, target, action) 145 | button.setBackgroundImage(backgroundImage, for: .normal) 146 | button.setBackgroundImage(selectedBackgroundImage, for: .selected) 147 | return button 148 | } 149 | 150 | ////初始化button 没有点击 设置 标题文字、文字颜色、文字大小、图片 151 | class func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont) -> Self { 152 | let button = self.init(type: .custom) 153 | button.setTitle(title, for: .normal) 154 | button.setTitleColor(titleColor, for: .normal) 155 | button.titleLabel?.font = font 156 | if let image = UIImage(named: imageName) { 157 | button.setImage(image, for: .normal) 158 | } 159 | return button 160 | } 161 | 162 | //MARK: ---- 实例方法 163 | 164 | ////设置button 标题文字、文字颜色、文字大小 165 | func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ backgroundColor: UIColor, _ font:UIFont, _ target:Any, _ action:Selector) { 166 | self.setTitle(title, for: .normal) 167 | self.setTitleColor(titleColor, for: .normal) 168 | self.titleLabel?.font = font 169 | self.backgroundColor = backgroundColor 170 | self.addTarget(target, action:action, for: .touchUpInside) 171 | } 172 | 173 | ////设置button 标题文字、文字颜色、文字大小 174 | func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ font:UIFont, _ target:Any, _ action:Selector) { 175 | lgl_basekit_button(title, titleColor, .clear, font, target, action) 176 | } 177 | 178 | ////设置button 标题文字、文字颜色、文字大小、图片 179 | func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont, _ target:Any, _ action:Selector) { 180 | lgl_basekit_button(title, titleColor, .clear, font, target, action) 181 | if let image = UIImage(named: imageName) { 182 | self.setImage(image, for: .normal) 183 | } 184 | } 185 | 186 | ////设置button 标题文字、文字颜色、文字大小、背景图片 187 | func lgl_basekit_button(_ title:String, _ titleColor: UIColor, _ backgroundImage:UIImage, _ font:UIFont, _ target:Any, _ action:Selector) { 188 | lgl_basekit_button(title, titleColor, .clear, font, target, action) 189 | self.setBackgroundImage(backgroundImage, for: .normal) 190 | } 191 | 192 | ////设置button 没有点击 标题文字、文字颜色、文字大小、图片 193 | func lgl_basekit_button(_ title:String, _ titleColor:UIColor, _ imageName: String, _ font:UIFont) { 194 | self.setTitle(title, for: .normal) 195 | self.setTitleColor(titleColor, for: .normal) 196 | self.titleLabel?.font = font 197 | if let image = UIImage(named: imageName) { 198 | self.setImage(image, for: .normal) 199 | } 200 | } 201 | 202 | ///设置图片 203 | func lgl_basekit_buttonImage(_ normalImageName: String, _ selectImageName: String) { 204 | if let normalImage = UIImage(named: normalImageName) { 205 | self.setImage(normalImage, for: .normal) 206 | } 207 | if let selectImage = UIImage(named: selectImageName) { 208 | self.setImage(selectImage, for: .selected) 209 | } 210 | } 211 | 212 | ///设置背景图片 213 | func lgl_basekit_buttonBackgroundImage(_ normalImageName: String, _ selectImageName: String) { 214 | if let normalImage = UIImage(named: normalImageName) { 215 | self.setBackgroundImage(normalImage, for: .normal) 216 | } 217 | if let selectImage = UIImage(named: selectImageName) { 218 | self.setBackgroundImage(selectImage, for: .selected) 219 | } 220 | } 221 | 222 | ///设置圆角 223 | func lgl_basekit_buttonRadius(_ cornerRadius: CGFloat) { 224 | self.layer.masksToBounds = true 225 | self.layer.cornerRadius = cornerRadius 226 | } 227 | 228 | ///设置边框颜色、边框宽度 229 | func lgl_basekit_buttonBorder(_ borderColor: UIColor, _ borderWidth: CGFloat) { 230 | self.layer.borderWidth = borderWidth 231 | self.layer.borderColor = borderColor.cgColor 232 | } 233 | 234 | ///设置边框颜色、边框宽度、圆角 235 | func lgl_basekit_buttonBorder(_ borderColor: UIColor, _ borderWidth: CGFloat, _ cornerRadius: CGFloat) { 236 | self.layer.masksToBounds = true 237 | self.layer.cornerRadius = cornerRadius 238 | self.layer.borderWidth = borderWidth 239 | self.layer.borderColor = borderColor.cgColor 240 | } 241 | } 242 | 243 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIColor+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UIColor { 11 | 12 | convenience init(_ hex: UInt) { 13 | self.init( 14 | red: CGFloat((hex & 0xFF0000) >> 16) / 255.0, 15 | green: CGFloat((hex & 0x00FF00) >> 8) / 255.0, 16 | blue: CGFloat(hex & 0x0000FF) / 255.0, 17 | alpha: CGFloat(1.0) 18 | ) 19 | } 20 | ///十六进制字符串形式颜色值 21 | class func lgl_color(_ hex: String) -> UIColor { 22 | return lgl_basekit_hexColor(hex) 23 | } 24 | 25 | static var lgl_randomColor: UIColor { 26 | let red = CGFloat(arc4random()%256)/255.0 27 | let green = CGFloat(arc4random()%256)/255.0 28 | let blue = CGFloat(arc4random()%256)/255.0 29 | return UIColor(red: red, green: green, blue: blue, alpha: 1.0) 30 | } 31 | 32 | ///适配暗黑模式设置颜色 dark -- 暗黑模式下的颜色 light -- 其他模式下的颜色 33 | class func lgl_traitColor(_ dark:UIColor = .white, _ light:UIColor) -> UIColor { 34 | if #available(iOS 13.0, *) { 35 | let color = UIColor{ (traitCollection) -> UIColor in 36 | if traitCollection.userInterfaceStyle == .dark { 37 | return dark 38 | } else { 39 | return light 40 | } 41 | } 42 | return color 43 | } else { 44 | return light 45 | } 46 | } 47 | } 48 | 49 | /// 定义16进制值颜色 50 | fileprivate extension UIColor { 51 | 52 | private class func lgl_basekit_hexColor(_ hex: String) -> UIColor { 53 | var cstr = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased() as NSString; 54 | if(cstr.length < 6){ 55 | return UIColor.clear; 56 | } 57 | if(cstr.hasPrefix("0X")){ 58 | cstr = cstr.substring(from: 2) as NSString 59 | } 60 | if(cstr.hasPrefix("#")){ 61 | cstr = cstr.substring(from: 1) as NSString 62 | } 63 | if(cstr.length != 6){ 64 | return UIColor.clear; 65 | } 66 | var range = NSRange.init() 67 | range.location = 0 68 | range.length = 2 69 | //r 70 | let rStr = cstr.substring(with: range); 71 | //g 72 | range.location = 2; 73 | let gStr = cstr.substring(with: range) 74 | //b 75 | range.location = 4; 76 | let bStr = cstr.substring(with: range) 77 | var r :UInt32 = 0x0; 78 | var g :UInt32 = 0x0; 79 | var b :UInt32 = 0x0; 80 | Scanner.init(string: rStr).scanHexInt32(&r); 81 | Scanner.init(string: gStr).scanHexInt32(&g); 82 | Scanner.init(string: bStr).scanHexInt32(&b); 83 | return 84 | UIColor.init(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: 1.0); 85 | } 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIImage+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UIImage { 11 | ///根据颜色和尺寸生成图片 12 | convenience init(color: UIColor, size: CGSize) { 13 | UIGraphicsBeginImageContextWithOptions(size, false, 1) 14 | defer { // 当前代码执行退出后被调用,一般会被用来做资源释放或者销毁 15 | UIGraphicsEndImageContext() 16 | } 17 | color.setFill() 18 | UIRectFill(CGRect(origin: .zero, size: size)) 19 | guard let aCgImage = UIGraphicsGetImageFromCurrentImageContext()?.cgImage else { 20 | self.init() 21 | return 22 | } 23 | self.init(cgImage: aCgImage) 24 | } 25 | 26 | ///图片旋转90度 27 | func lgl_imageRotate90() -> UIImage { 28 | return UIImage(cgImage:self.cgImage!, 29 | scale:self.scale, 30 | orientation: .down) 31 | } 32 | 33 | ///返回原始图片 34 | func lgl_imageOriginal() -> UIImage { 35 | return self.withRenderingMode(.alwaysOriginal) 36 | } 37 | 38 | /**图片拉伸 指定 39 | edgeInset 指定不被拉伸的区域 40 | imageName 图片名称 41 | resizeMode UIImageResizingModeTile,//进行区域复制模式拉伸 【-】 -> 【-】【-】【-】 42 | resizeMode UIImageResizingModeStretch,//进行渐变复制模式拉伸 连续的 【-】 -> 【-----】 43 | */ 44 | func lgl_stretchImage(_ edgeInset:UIEdgeInsets, _ resizeMode: UIImage.ResizingMode) -> UIImage { 45 | return self.resizableImage(withCapInsets:edgeInset, resizingMode: resizeMode) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIImageView+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UIImageView { 11 | 12 | ///设置图片初始化 13 | class func lgl_imagView(_ imageName:String) -> Self { 14 | return lgl_basekit_imagView(imageName) 15 | } 16 | 17 | ///设置图片和圆角初始化 18 | class func lgl_imagView(_ imageName:String, _ cornerRadius:CGFloat) -> Self { 19 | return lgl_basekit_imagView(imageName, cornerRadius) 20 | } 21 | 22 | ///设置图片和圆角、背景色初始化 23 | class func lgl_imagView(_ imageName:String, _ backgroundColor: UIColor, _ cornerRadius:CGFloat) -> Self { 24 | return lgl_basekit_imagView(imageName, backgroundColor, cornerRadius) 25 | } 26 | 27 | 28 | 29 | ///设置图片 30 | func lgl_imagView(_ imageName:String) { 31 | lgl_basekit_imagView(imageName) 32 | } 33 | 34 | ///设置图片和圆角 35 | func lgl_imagView(_ imageName:String, _ cornerRadius:CGFloat) { 36 | lgl_basekit_imagView(imageName, cornerRadius) 37 | } 38 | 39 | ///设置图片和圆角、背景色 40 | func lgl_imagView(_ imageName:String, _ backgroundColor: UIColor, _ cornerRadius:CGFloat) { 41 | lgl_basekit_imagView(imageName, backgroundColor, cornerRadius) 42 | } 43 | 44 | } 45 | 46 | fileprivate extension UIImageView { 47 | 48 | class func lgl_basekit_imagView(_ imageName:String) -> Self { 49 | let imageView = self.init() 50 | if let image = UIImage(named: imageName) { 51 | imageView.image = image 52 | } 53 | return imageView 54 | } 55 | 56 | class func lgl_basekit_imagView(_ imageName:String, _ cornerRadius:CGFloat) -> Self { 57 | let imageView = lgl_basekit_imagView(imageName) 58 | imageView.layer.masksToBounds = true 59 | imageView.layer.cornerRadius = cornerRadius 60 | return imageView 61 | } 62 | 63 | class func lgl_basekit_imagView(_ imageName:String, _ backgroundColor: UIColor, _ cornerRadius:CGFloat) -> Self { 64 | let imageView = lgl_basekit_imagView(imageName, cornerRadius) 65 | imageView.backgroundColor = backgroundColor 66 | return imageView 67 | } 68 | 69 | /// --- 实例方法 70 | 71 | func lgl_basekit_imagView(_ imageName:String) { 72 | if let image = UIImage(named: imageName) { 73 | self.image = image 74 | } 75 | } 76 | 77 | func lgl_basekit_imagView(_ imageName:String, _ cornerRadius:CGFloat) { 78 | lgl_basekit_imagView(imageName) 79 | self.layer.masksToBounds = true 80 | self.layer.cornerRadius = cornerRadius 81 | } 82 | 83 | func lgl_basekit_imagView(_ imageName:String, _ backgroundColor: UIColor, _ cornerRadius:CGFloat) { 84 | lgl_basekit_imagView(imageName, cornerRadius) 85 | self.backgroundColor = backgroundColor 86 | } 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UILabel+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | 9 | import UIKit 10 | 11 | public extension UILabel { 12 | 13 | ///初始化label 字体、字体颜色 背景颜色、 字体大小、对齐方式、行数 14 | class func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment, _ numberOfLines: Int) -> Self { 15 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, textAlignment, numberOfLines) 16 | } 17 | 18 | ///初始化label 字体、字体颜色 字体大小、对齐方式 19 | class func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) -> Self { 20 | return lgl_basekit_classLabel(text, textColor, font, textAlignment) 21 | } 22 | 23 | ///初始化label 字体、字体颜色 字体大小、行数 24 | class func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ numberOfLines: Int) -> Self { 25 | return lgl_basekit_classLabel(text, textColor, font, numberOfLines) 26 | } 27 | 28 | ///初始化label 字体、字体颜色 字体大小 29 | class func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont) -> Self { 30 | return lgl_basekit_classLabel(text, textColor, .clear, font) 31 | } 32 | 33 | ///初始化label 字体、字体颜色、背景颜色、 字体大小、对齐方式 34 | class func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) -> Self { 35 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, textAlignment) 36 | } 37 | 38 | ///初始化label 字体、字体颜色、背景颜色、 字体大小行数 39 | class func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ numberOfLines: Int) -> Self { 40 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, numberOfLines) 41 | } 42 | 43 | ///初始化label 字体、字体颜色、背景颜色、 字体大小 44 | class func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) -> Self { 45 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font) 46 | } 47 | 48 | //MARK: ----- 实例方法 49 | 50 | ///设置label 字体、字体颜色、背景颜色、 字体大小、对齐方式、行数 51 | func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment, _ numberOfLines: Int) { 52 | lgl_basekit_label(text, textColor, backgroundColor, font, textAlignment, numberOfLines) 53 | } 54 | 55 | ///设置label 字体、字体颜色、背景颜色、 字体大小、对齐方式 56 | func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) { 57 | lgl_basekit_label(text, textColor, backgroundColor, font, textAlignment) 58 | } 59 | 60 | ///设置label 字体、字体颜色、背景颜色、 字体大小、行数 61 | func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ numberOfLines: Int) { 62 | lgl_basekit_label(text, textColor, backgroundColor, font, numberOfLines) 63 | } 64 | 65 | ///设置label 字体、字体颜色、背景颜色、 字体大小 66 | func lgl_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) { 67 | lgl_basekit_label(text, textColor, backgroundColor, font) 68 | } 69 | 70 | ///设置label 字体、字体颜色、背景颜色、 字体大小、对齐方式、行数 71 | func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) { 72 | lgl_basekit_label(text, textColor, .clear, font, textAlignment) 73 | } 74 | 75 | ///设置label 字体、字体颜色、 字体大小、行数 76 | func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ numberOfLines: Int) { 77 | lgl_basekit_label(text, textColor, font, numberOfLines) 78 | } 79 | 80 | ///设置label 字体、字体颜色、 字体大小 81 | func lgl_label(_ text: String, _ textColor: UIColor, _ font: UIFont) { 82 | lgl_basekit_label(text, textColor, font) 83 | } 84 | 85 | ///设置label 切圆角 86 | func lgl_labelRadius(_ cornerRadius: CGFloat) { 87 | lgl_basekit_labelRadius(cornerRadius) 88 | } 89 | 90 | ///设置label 边框和边框颜色 91 | func lgl_labelBorder(_ borderColor: UIColor, _ borderWidth: CGFloat) { 92 | lgl_basekit_labelBorder(borderColor, borderWidth) 93 | } 94 | 95 | ///设置label 边框、边框颜色、切圆角 96 | func lgl_labelBorder(_ borderColor: UIColor, _ borderWidth: CGFloat, _ cornerRadius: CGFloat) { 97 | lgl_basekit_labelBorder(borderColor, borderWidth, cornerRadius) 98 | } 99 | } 100 | 101 | 102 | fileprivate extension UILabel { 103 | 104 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment, _ numberOfLines: Int) -> Self { 105 | let label = self.init() 106 | label.text = text 107 | label.textColor = textColor 108 | label.font = font 109 | label.textAlignment = textAlignment 110 | label.numberOfLines = numberOfLines 111 | label.backgroundColor = backgroundColor 112 | return label 113 | } 114 | 115 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) -> Self { 116 | return lgl_basekit_classLabel(text, textColor, .clear, font, textAlignment, 1) 117 | } 118 | 119 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ font: UIFont, _ numberOfLines: Int) -> Self { 120 | return lgl_basekit_classLabel(text, textColor, .clear, font, .left, numberOfLines) 121 | } 122 | 123 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ font: UIFont) -> Self { 124 | return lgl_basekit_classLabel(text, textColor, .clear, font, .left, 1) 125 | } 126 | 127 | 128 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) -> Self { 129 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, textAlignment, 1) 130 | } 131 | 132 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ numberOfLines: Int) -> Self { 133 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, .left, numberOfLines) 134 | } 135 | 136 | class func lgl_basekit_classLabel(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) -> Self { 137 | return lgl_basekit_classLabel(text, textColor, backgroundColor, font, .left, 1) 138 | } 139 | 140 | //MARK: ----- 实例方法 141 | 142 | 143 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment, _ numberOfLines: Int) { 144 | self.text = text 145 | self.textColor = textColor 146 | self.font = font 147 | self.textAlignment = textAlignment 148 | self.numberOfLines = numberOfLines 149 | self.backgroundColor = backgroundColor 150 | } 151 | 152 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) { 153 | lgl_basekit_label(text, textColor, backgroundColor, font, textAlignment, 1) 154 | } 155 | 156 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ numberOfLines: Int) { 157 | lgl_basekit_label(text, textColor, backgroundColor, font, .left, numberOfLines) 158 | } 159 | 160 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) { 161 | lgl_basekit_label(text, textColor, backgroundColor, font, .left, 1) 162 | } 163 | 164 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ textAlignment: NSTextAlignment) { 165 | lgl_basekit_label(text, textColor, .clear, font, textAlignment, 1) 166 | } 167 | 168 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ font: UIFont, _ numberOfLines: Int) { 169 | lgl_basekit_label(text, textColor, .clear, font, .left, numberOfLines) 170 | } 171 | 172 | func lgl_basekit_label(_ text: String, _ textColor: UIColor, _ font: UIFont) { 173 | lgl_basekit_label(text, textColor, .clear, font, .left, 1) 174 | } 175 | 176 | 177 | func lgl_basekit_labelRadius(_ cornerRadius: CGFloat) { 178 | self.layer.masksToBounds = true 179 | self.layer.cornerRadius = cornerRadius 180 | } 181 | 182 | func lgl_basekit_labelBorder(_ borderColor: UIColor, _ borderWidth: CGFloat) { 183 | self.layer.borderWidth = borderWidth 184 | self.layer.borderColor = borderColor.cgColor 185 | } 186 | 187 | func lgl_basekit_labelBorder(_ borderColor: UIColor, _ borderWidth: CGFloat, _ cornerRadius: CGFloat) { 188 | self.layer.masksToBounds = true 189 | self.layer.cornerRadius = cornerRadius 190 | self.layer.borderWidth = borderWidth 191 | self.layer.borderColor = borderColor.cgColor 192 | } 193 | 194 | } 195 | 196 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UINavigationController+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationController+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UINavigationController { 11 | 12 | ///设置导航栏标题的字体颜色和大小 13 | func lgl_navigationTitle(_ color:UIColor, _ font: UIFont) { 14 | self.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: color, NSAttributedString.Key.font: font] 15 | } 16 | 17 | ///设置导航栏透明 18 | func lgl_navigationClear() { 19 | self.navigationBar.setBackgroundImage(UIImage(), for: .default) 20 | self.navigationBar.shadowImage = UIImage() 21 | } 22 | 23 | ///设置还原导航默认 24 | func lgl_navigationDefault() { 25 | self.navigationBar.setBackgroundImage(nil, for: .default) 26 | self.navigationBar.shadowImage = nil 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UITabBarController+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITabBarController+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/9/20. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UITabBarController { 11 | 12 | ///设置tabBar颜色 13 | func lgl_tabBar(color: UIColor) { 14 | self.tabBar.isTranslucent = false 15 | self.tabBar.barTintColor = color 16 | self.tabBar.shadowImage = UIImage() 17 | self.tabBar.backgroundImage = UIImage() 18 | } 19 | 20 | ///设置tabBar阴影 21 | func lgl_tabBarShadow(_ bgColor: UIColor, _ shadowColor: UIColor, _ shadowOffset: CGSize, _ shadowRadius:CGFloat, _ shadowOpacity: Float = 1.0) { 22 | lgl_tabBar(color: bgColor) 23 | self.tabBar.layer.shadowColor = shadowColor.cgColor 24 | self.tabBar.layer.shadowOffset = shadowOffset 25 | self.tabBar.layer.shadowOpacity = shadowOpacity 26 | self.tabBar.layer.shadowRadius = shadowRadius 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UITextField+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public extension UITextField { 11 | 12 | ///初始化TextField 字体大小、字体颜色、提示文字、边框样式 、背景色 13 | class func lgl_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) -> Self { 14 | return lgl_basekit_textField(textColor, backgroundColor, font, placeholder, borderStyle) 15 | } 16 | 17 | ///初始化TextField 字体大小、字体颜色、提示文字、边框样式 18 | class func lgl_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) -> Self { 19 | return lgl_basekit_textField(textColor, font, placeholder, borderStyle) 20 | } 21 | 22 | ///初始化TextField 字体大小、字体颜色、提示文字 23 | class func lgl_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String) -> Self { 24 | return lgl_basekit_textField(textColor, font, placeholder) 25 | } 26 | 27 | ///初始化TextField 字体大小、字体颜色 28 | class func lgl_textField(_ textColor: UIColor, _ font: UIFont) -> Self { 29 | return lgl_basekit_textField(textColor, font) 30 | } 31 | 32 | ///设置TextField 字体大小、字体颜色、提示文字、边框样式、背景色 33 | func lgl_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) { 34 | lgl_basekit_textField(textColor, backgroundColor, font, placeholder, borderStyle) 35 | } 36 | 37 | ///设置TextField 字体大小、字体颜色、提示文字、背景色 38 | func lgl_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String) { 39 | lgl_basekit_textField(textColor, backgroundColor, font, placeholder) 40 | } 41 | 42 | ///设置TextField 字体大小、字体颜色、背景色 43 | func lgl_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) { 44 | lgl_basekit_textField(textColor, backgroundColor, font) 45 | } 46 | 47 | ///设置TextField 字体大小、字体颜色、提示文字、边框样式 48 | func lgl_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) { 49 | lgl_basekit_textField(textColor, font, placeholder, borderStyle) 50 | } 51 | 52 | ///设置TextField 字体大小、字体颜色、提示文字 53 | func lgl_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String) { 54 | lgl_basekit_textField(textColor, font, placeholder) 55 | } 56 | 57 | ///设置TextField 字体大小、字体颜色 58 | func lgl_textField(_ textColor: UIColor, _ font: UIFont) { 59 | lgl_basekit_textField(textColor, font) 60 | } 61 | 62 | ///设置Placeholder的字体大小和颜色 63 | func lgl_textFieldPlaceholder(_ color: UIColor, _ font: UIFont) { 64 | lgl_basekit_textFieldPlaceholder(color, font) 65 | } 66 | 67 | ///设置LeftView 68 | func lgl_textFieldSetLeftView(_ leftView: UIView?) { 69 | lgl_basekit_textFieldSetLeftView(leftView) 70 | } 71 | 72 | ///设置左边距 73 | func lgl_textFieldSetLeftPadding(_ padding: CGFloat) { 74 | lgl_basekit_textFieldSetLeftPadding(padding) 75 | } 76 | 77 | ///设置RightView 78 | func lgl_textFieldSetRightView(_ rightView: UIView?) { 79 | lgl_basekit_textFieldSetRightView(rightView) 80 | } 81 | 82 | ///修改clear按钮的图片 83 | func lgl_textFieldChangeClearButton(_ imageName: String) { 84 | lgl_basekit_textFieldChangeClearButton(imageName) 85 | } 86 | 87 | ///切圆角 88 | func lgl_textFieldCornerRadius(_ cornerRadius: CGFloat) { 89 | lgl_basekit_textFieldCornerRadius(cornerRadius) 90 | } 91 | } 92 | 93 | 94 | 95 | fileprivate extension UITextField { 96 | 97 | class func lgl_basekit_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) -> Self { 98 | let textField = self.init() 99 | textField.textColor = textColor 100 | textField.font = font 101 | textField.placeholder = placeholder 102 | textField.borderStyle = borderStyle 103 | textField.backgroundColor = backgroundColor 104 | return textField 105 | } 106 | 107 | class func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) -> Self { 108 | return lgl_basekit_textField(textColor, .clear, font, placeholder, borderStyle) 109 | } 110 | 111 | class func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String) -> Self { 112 | return lgl_basekit_textField(textColor, font, placeholder, .none) 113 | } 114 | 115 | class func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont) -> Self { 116 | return lgl_basekit_textField(textColor, font, "", .none) 117 | } 118 | 119 | //MRK: ----- 实例方法 120 | 121 | func lgl_basekit_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) { 122 | self.textColor = textColor 123 | self.font = font 124 | self.placeholder = placeholder 125 | self.borderStyle = borderStyle 126 | self.backgroundColor = backgroundColor 127 | } 128 | 129 | func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String, _ borderStyle: UITextField.BorderStyle) { 130 | lgl_basekit_textField(textColor, .clear, font, placeholder, borderStyle) 131 | } 132 | 133 | func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont, _ placeholder: String) { 134 | self.textColor = textColor 135 | self.font = font 136 | self.placeholder = placeholder 137 | } 138 | 139 | func lgl_basekit_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont, _ placeholder: String) { 140 | self.textColor = textColor 141 | self.font = font 142 | self.placeholder = placeholder 143 | self.backgroundColor = backgroundColor 144 | } 145 | 146 | func lgl_basekit_textField(_ textColor: UIColor, _ font: UIFont) { 147 | self.textColor = textColor 148 | self.font = font 149 | } 150 | 151 | func lgl_basekit_textField(_ textColor: UIColor, _ backgroundColor: UIColor, _ font: UIFont) { 152 | self.textColor = textColor 153 | self.font = font 154 | self.backgroundColor = backgroundColor 155 | } 156 | 157 | func lgl_basekit_textFieldPlaceholder(_ color: UIColor, _ font: UIFont) { 158 | if #available(iOS 13.0, *) { 159 | let arrStr = NSMutableAttributedString(string: self.placeholder ?? "", attributes: [NSAttributedString.Key.foregroundColor: color, NSAttributedString.Key.font: font]) 160 | self.attributedPlaceholder = arrStr 161 | } else { 162 | self.setValue(color, forKeyPath: "_placeholderLabel.textColor") 163 | self.setValue(font, forKeyPath:"_placeholderLabel.font") 164 | } 165 | } 166 | 167 | func lgl_basekit_textFieldSetLeftView(_ leftView: UIView?) { 168 | if leftView != nil { 169 | self.leftView = leftView 170 | self.leftViewMode = .always 171 | } 172 | } 173 | 174 | func lgl_basekit_textFieldSetLeftPadding(_ padding: CGFloat) { 175 | let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: padding, height: self.frame.height)) 176 | self.leftView = paddingView 177 | self.leftViewMode = .always 178 | } 179 | 180 | func lgl_basekit_textFieldSetRightView(_ rightView: UIView?) { 181 | if rightView != nil { 182 | self.rightView = rightView 183 | self.rightViewMode = .always 184 | } 185 | } 186 | 187 | func lgl_basekit_textFieldCornerRadius(_ cornerRadius: CGFloat) { 188 | self.layer.masksToBounds = true 189 | self.layer.cornerRadius = cornerRadius 190 | } 191 | 192 | func lgl_basekit_textFieldChangeClearButton(_ imageName: String) { 193 | if let image = UIImage(named: imageName) { 194 | let cleaButton:UIButton = self.value(forKey: "_clearButton") as! UIButton 195 | cleaButton.setImage(image, for: .normal) 196 | self.clearButtonMode = .whileEditing 197 | } 198 | } 199 | } 200 | 201 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLExtension/UIView+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Extension.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | 11 | public extension UIView { 12 | 13 | ///初始化View 设置背景颜色 14 | class func lgl_view(_ backgroundColor: UIColor) -> Self { 15 | return lgl_basekit_view(backgroundColor) 16 | } 17 | 18 | ///初始化View 设置背景颜色、圆角 19 | class func lgl_view(_ backgroundColor: UIColor, _ cornerRadius: CGFloat) -> Self { 20 | return lgl_basekit_view(backgroundColor, cornerRadius) 21 | } 22 | 23 | ///设置View 背景颜色、圆角 24 | func lgl_view(_ backgroundColor: UIColor, _ cornerRadius: CGFloat) { 25 | lgl_basekit_view(backgroundColor, cornerRadius) 26 | } 27 | 28 | /// 水平渐变 29 | func lgl_horizontalGradientLayer(_ startColor: UIColor, _ endColor: UIColor, _ cornerRadius:CGFloat) { 30 | lgl_basekit_horizontalGradientLayer(startColor, endColor, cornerRadius) 31 | } 32 | 33 | /// 垂直渐变 34 | func lgl_verticalGradientLayer(_ startColor: UIColor, _ endColor: UIColor, _ cornerRadius:CGFloat) { 35 | lgl_basekit_verticalGradientLayer(startColor, endColor, cornerRadius) 36 | } 37 | 38 | ///设置多角圆角 39 | func lgl_roundingCorner(_ corners: UIRectCorner, _ radii: CGFloat) { 40 | lgl_basekit_roundingCorner(corners, radii) 41 | } 42 | 43 | ///给View添加阴影 44 | func lgl_shadow( _ shadowColor:UIColor, _ shadowOffset:CGSize, _ shadowOpacity:Float, _ shadowRadius:CGFloat, _ cornerRadius:CGFloat) { 45 | lgl_basekit_shadow(shadowColor, shadowOffset, shadowOpacity, shadowRadius, cornerRadius) 46 | } 47 | 48 | ///给View添加阴影和边框 49 | func lgl_shadowBorder( _ shadowColor:UIColor, _ shadowOffset:CGSize, _ shadowOpacity:Float, _ shadowRadius:CGFloat, _ cornerRadius:CGFloat, _ borderColor: UIColor) { 50 | lgl_basekit_shadowBorder(shadowColor, shadowOffset, shadowOpacity, shadowRadius, cornerRadius,borderColor) 51 | } 52 | 53 | ///获取当前View的控制器 54 | func lgl_viewGetcurrentVC() -> UIViewController? { 55 | return lgl_basekit_viewGetcurrentVC() 56 | } 57 | 58 | ///view转图片 59 | func lgl_viewToImage() -> UIImage { 60 | return lgl_basekit_viewToImage() 61 | } 62 | 63 | /// 点击手势(默认代理和target相同) 64 | func lgl_tapGesture(_ target: Any?,_ action: Selector,_ numberOfTapsRequired: Int = 1) { 65 | lgl_basekit_tapGesture(target, action, numberOfTapsRequired) 66 | } 67 | 68 | /// 长按手势(默认代理和target相同) 69 | func lgl_longGesture(_ target: Any?,_ action: Selector,_ minDuration: TimeInterval = 0.5) { 70 | lgl_basekit_longGesture(target, action, minDuration) 71 | } 72 | 73 | /// 部分圆角 74 | func lgl_partOfRadius(_ corners: UIRectCorner,_ radius: CGFloat) { 75 | lgl_basekit_partOfRadius(corners, radius) 76 | } 77 | 78 | /// 截图(带导航则用导航控制器的view或keywindow) 79 | func lgl_screenshotImage() -> UIImage? { 80 | return lgl_basekit_screenshotImage() 81 | } 82 | } 83 | 84 | //MARK: --- 获取值 85 | 86 | public extension UIView { 87 | var height:CGFloat { 88 | get { 89 | return frame.height 90 | } 91 | set(newValue){ 92 | var tempFrame = self.frame 93 | tempFrame.size.height = newValue 94 | self.frame = tempFrame 95 | } 96 | } 97 | 98 | var width:CGFloat { 99 | get{ 100 | return frame.width 101 | } 102 | 103 | set(newValue){ 104 | var tempFrame = frame 105 | tempFrame.size.width = newValue 106 | frame = tempFrame 107 | } 108 | } 109 | 110 | var x:CGFloat { 111 | get{ 112 | return frame.origin.x 113 | } 114 | set(newValue){ 115 | var tempFrame = frame 116 | tempFrame.origin.x = newValue 117 | frame = tempFrame 118 | } 119 | } 120 | 121 | var centerX:CGFloat { 122 | get{ 123 | return center.x 124 | } 125 | set(newValue){ 126 | var tempCenter = center 127 | tempCenter.x = newValue 128 | center = tempCenter 129 | } 130 | } 131 | 132 | var centerY:CGFloat { 133 | get{ 134 | return center.y 135 | } 136 | set(newValue){ 137 | var tempCenter = center 138 | tempCenter.y = newValue 139 | center = tempCenter 140 | } 141 | } 142 | 143 | var y:CGFloat { 144 | get{ 145 | return frame.origin.y 146 | } 147 | set(newValue){ 148 | var tempFrame = frame 149 | tempFrame.origin.y = newValue 150 | frame = tempFrame 151 | } 152 | } 153 | 154 | /// left值 155 | var left: CGFloat { 156 | get { 157 | return frame.origin.x 158 | } 159 | set { 160 | var tempFrame = frame 161 | tempFrame.origin.x = newValue 162 | frame = tempFrame 163 | } 164 | } 165 | 166 | /// top值 167 | var top: CGFloat { 168 | get { 169 | return frame.origin.y 170 | } 171 | set { 172 | var tempFrame = frame 173 | tempFrame.origin.y = newValue 174 | frame = tempFrame 175 | } 176 | } 177 | 178 | /// right值 179 | var right: CGFloat { 180 | get { 181 | return frame.origin.x + frame.size.width 182 | } 183 | set { 184 | var tempFrame = frame 185 | tempFrame.origin.x = newValue - frame.size.width 186 | frame = tempFrame 187 | } 188 | } 189 | 190 | /// bottom值 191 | var bottom: CGFloat { 192 | get { 193 | return frame.origin.y + frame.size.height 194 | } 195 | set { 196 | var tempFrame = frame 197 | tempFrame.origin.y = newValue - frame.size.height 198 | frame = tempFrame 199 | } 200 | } 201 | 202 | /// size值 203 | var size: CGSize { 204 | get { 205 | return frame.size 206 | } 207 | set { 208 | var tempFrame = frame 209 | tempFrame.size = newValue 210 | frame = tempFrame 211 | } 212 | } 213 | 214 | /// origin值 215 | var origin: CGPoint { 216 | get { 217 | return frame.origin 218 | } 219 | set { 220 | var tempFrame = frame 221 | tempFrame.origin = newValue 222 | frame = tempFrame 223 | } 224 | } 225 | } 226 | 227 | 228 | //MARK: --- 创建View 229 | 230 | fileprivate extension UIView { 231 | 232 | class func lgl_basekit_view(_ backgroundColor: UIColor) -> Self { 233 | let view = self.init() 234 | view.backgroundColor = backgroundColor 235 | return view 236 | } 237 | 238 | class func lgl_basekit_view(_ backgroundColor: UIColor, _ cornerRadius: CGFloat) -> Self { 239 | let view = lgl_basekit_view(backgroundColor) 240 | view.layer.masksToBounds = true 241 | view.layer.cornerRadius = cornerRadius 242 | return view 243 | } 244 | 245 | func lgl_basekit_view(_ backgroundColor: UIColor, _ cornerRadius: CGFloat) { 246 | self.backgroundColor = backgroundColor 247 | self.layer.masksToBounds = true 248 | self.layer.cornerRadius = cornerRadius 249 | } 250 | } 251 | 252 | 253 | 254 | //MARK: --- 常用的方法 255 | 256 | fileprivate extension UIView { 257 | 258 | /// 点击手势(默认代理和target相同) 259 | func lgl_basekit_tapGesture(_ target: Any?,_ action: Selector,_ numberOfTapsRequired: Int = 1) { 260 | let tapGesture = UITapGestureRecognizer(target: target, action: action) 261 | tapGesture.numberOfTapsRequired = numberOfTapsRequired 262 | tapGesture.delegate = target as? UIGestureRecognizerDelegate 263 | self.isUserInteractionEnabled = true 264 | self.addGestureRecognizer(tapGesture) 265 | } 266 | 267 | /// 长按手势(默认代理和target相同) 268 | func lgl_basekit_longGesture(_ target: Any?,_ action: Selector,_ minDuration: TimeInterval = 0.5) { 269 | let longGesture = UILongPressGestureRecognizer(target: target, action: action) 270 | longGesture.minimumPressDuration = minDuration 271 | longGesture.delegate = target as? UIGestureRecognizerDelegate 272 | self.isUserInteractionEnabled = true 273 | self.addGestureRecognizer(longGesture) 274 | } 275 | 276 | /// 部分圆角 277 | func lgl_basekit_partOfRadius(_ corners: UIRectCorner,_ radius: CGFloat) { 278 | let shapeLayer = CAShapeLayer() 279 | shapeLayer.frame = self.bounds 280 | shapeLayer.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)).cgPath 281 | self.layer.mask = shapeLayer 282 | } 283 | 284 | /// 截图(带导航则用导航控制器的view或keywindow) 285 | func lgl_basekit_screenshotImage() -> UIImage? { 286 | UIGraphicsBeginImageContext(self.bounds.size) 287 | if self.responds(to: #selector(UIView.drawHierarchy(in:afterScreenUpdates:))) { 288 | self.drawHierarchy(in: self.bounds, afterScreenUpdates: false) 289 | } else if self.layer.responds(to: #selector(CALayer.render(in:) )) { 290 | self.layer.render(in: UIGraphicsGetCurrentContext()!) 291 | } else { 292 | return nil 293 | } 294 | let image = UIGraphicsGetImageFromCurrentImageContext() 295 | UIGraphicsEndImageContext() 296 | return image 297 | } 298 | 299 | 300 | ///设置圆角或者边框 301 | func lgl_basekit_borderRadius(_ cornerRadius: CGFloat, _ masksToBounds: Bool, _ borderColor:UIColor = .clear, _ borderWidth: CGFloat = 0.0) { 302 | self.layer.masksToBounds = masksToBounds 303 | self.layer.cornerRadius = cornerRadius 304 | self.layer.borderColor = borderColor.cgColor 305 | self.layer.borderWidth = borderWidth 306 | } 307 | 308 | /// 水平渐变 309 | func lgl_basekit_horizontalGradientLayer(_ startColor: UIColor, _ endColor: UIColor, _ cornerRadius:CGFloat) { 310 | let gradient = CAGradientLayer() 311 | gradient.frame = self.bounds 312 | gradient.colors = [startColor.cgColor, endColor.cgColor] 313 | gradient.startPoint = CGPoint(x: 0, y: 0) 314 | gradient.endPoint = CGPoint(x: 1, y: 0) 315 | gradient.cornerRadius = cornerRadius 316 | self.layer.insertSublayer(gradient, at: 0) 317 | } 318 | 319 | /// 垂直渐变 320 | func lgl_basekit_verticalGradientLayer(_ startColor: UIColor, _ endColor: UIColor, _ cornerRadius:CGFloat) { 321 | let gradient = CAGradientLayer() 322 | gradient.frame = self.bounds 323 | gradient.colors = [startColor.cgColor, endColor.cgColor] 324 | gradient.startPoint = CGPoint(x: 0, y: 0) 325 | gradient.endPoint = CGPoint(x: 0, y: 1) 326 | gradient.cornerRadius = cornerRadius 327 | self.layer.insertSublayer(gradient, at: 0) 328 | } 329 | 330 | func lgl_basekit_roundingCorner(_ corners: UIRectCorner, _ radii: CGFloat) { 331 | let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radii, height: radii)) 332 | let maskLayer = CAShapeLayer() 333 | maskLayer.frame = self.bounds 334 | maskLayer.path = maskPath.cgPath 335 | self.layer.mask = maskLayer 336 | } 337 | 338 | ///给View添加阴影 339 | func lgl_basekit_shadow( _ shadowColor:UIColor, _ shadowOffset:CGSize, _ shadowOpacity:Float, _ shadowRadius:CGFloat, _ cornerRadius:CGFloat) { 340 | self.layer.shadowColor = shadowColor.cgColor 341 | self.layer.shadowOpacity = shadowOpacity 342 | self.layer.shadowRadius = shadowRadius 343 | self.layer.shadowOffset = shadowOffset 344 | self.layer.cornerRadius = cornerRadius 345 | } 346 | 347 | ///给View添加阴影和边框 348 | func lgl_basekit_shadowBorder( _ shadowColor:UIColor, _ shadowOffset:CGSize, _ shadowOpacity:Float, _ shadowRadius:CGFloat, _ cornerRadius:CGFloat, _ borderColor: UIColor) { 349 | self.layer.shadowColor = shadowColor.cgColor 350 | self.layer.shadowOpacity = shadowOpacity 351 | self.layer.shadowRadius = shadowRadius 352 | self.layer.shadowOffset = shadowOffset 353 | self.layer.cornerRadius = cornerRadius 354 | self.layer.borderColor = borderColor.cgColor 355 | self.layer.borderWidth = 1.0 356 | } 357 | 358 | ///获取当前View的控制器 359 | func lgl_basekit_viewGetcurrentVC() -> UIViewController? { 360 | var nextResponder: UIResponder? = self 361 | repeat { 362 | nextResponder = nextResponder?.next 363 | if let viewController = nextResponder as? UIViewController { 364 | return viewController 365 | } 366 | } while nextResponder != nil 367 | 368 | return nil 369 | } 370 | 371 | func lgl_basekit_viewToImage() -> UIImage { 372 | UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.main.scale) 373 | self.layer.render(in: UIGraphicsGetCurrentContext()!) 374 | let image = UIGraphicsGetImageFromCurrentImageContext() 375 | UIGraphicsEndImageContext() 376 | return image! 377 | } 378 | } 379 | 380 | -------------------------------------------------------------------------------- /LGLBaseKit/Classes/LGLPublicMethod/LGLMethod.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LGLMethod.swift 3 | // LGLBaseKit 4 | // 5 | // Created by Passer on 2019/8/21. 6 | // 7 | 8 | import UIKit 9 | 10 | public class LGLMethod { 11 | 12 | ///返回原始图片 13 | public class func originalImage(_ imageName: String) -> UIImage? { 14 | return lgl_basekit_originalImage(imageName) 15 | } 16 | 17 | ///等比缩放图片获取高度 18 | public class func imageHeight(_ imageW: CGFloat, _ imageH: CGFloat, _ realW: CGFloat) -> CGFloat { 19 | return lgl_basekit_imageHeight(imageW, imageH, realW) 20 | } 21 | 22 | ///根据root控制器,返回当前控制器 23 | public class func currentVC() -> UIViewController? { 24 | return lgl_basekit_currentVC() 25 | } 26 | 27 | ///根据颜色生成图片(UIImage) 28 | public class func imageWithColor(_ color: UIColor, _ size: CGSize) -> UIImage { 29 | return lgl_basekit_createImageFrom(color, size) 30 | } 31 | 32 | ///打开链接 OpenUrl 33 | @discardableResult 34 | public class func openUrl(_ url: URL) -> Bool { 35 | return lgl_basekit_openUrl(url) 36 | } 37 | 38 | ///拨打电话 39 | public class func lgl_callPhone(_ number: String) { 40 | lgl_basekit_callPhone(number) 41 | } 42 | ///拨打电话 43 | public class func callPhone(_ number: String) { 44 | lgl_basekit_callPhone(number) 45 | } 46 | 47 | /// 跳转appStore 评论 48 | public class func lgl_appStoreComment(_ appId: String) { 49 | lgl_basekit_appStoreComment(appId) 50 | } 51 | /// 跳转appStore 评论 52 | public class func appStoreComment(_ appId: String) { 53 | lgl_basekit_appStoreComment(appId) 54 | } 55 | 56 | /// 金额格式化用组分隔 prefix 自定义前缀(如 $/¥) separator 分隔符号(如,) groupingSize 分隔位数 maxFractionDigits 小数点后最多位数 57 | public class func moneyFormatter(_ money: Double, _ maxFractionDigits: Int, _ prefix:String, _ separator: String, _ groupingSize: Int) -> String 58 | { 59 | return lgl_basekit_moneyFormatter(money: money, maxFractionDigits: maxFractionDigits, prefix: prefix, separator: separator, groupingSize: groupingSize) 60 | } 61 | 62 | /// 金额格式化不用组分隔 prefix 自定义前缀(如 $/¥) maxFractionDigits 小数点后最多位数 63 | public class func amountFormatter(_ money: Double, _ maxFractionDigits: Int, _ prefix:String) -> String { 64 | return lgl_basekit_amountFormatter(money: money, maxFractionDigits: maxFractionDigits, prefix: prefix) 65 | } 66 | 67 | ///跳转Dic -> JsonStr 68 | public class func dicToJsonStr(_ dic: [String: Any]) -> String? { 69 | return lgl_basekit_dicToJsonStr(dic) 70 | } 71 | 72 | ///图片旋转90度 73 | public class func rotationImage90(_ imageName: String) -> UIImage? { 74 | return lgl_basekit_rotationImage90(imageName) 75 | } 76 | 77 | ///判断文字的格式是否满足条件 characterStr 条件 judgeText需要判断的字符串 78 | public class func characterSetWithStr(_ characterStr: String, _ judgeText: String) -> Bool { 79 | return lgl_basekit_characterSetWithStr(characterStr, judgeText) 80 | } 81 | 82 | /** 83 | * 压缩上传图片到指定字节 84 | * image 压缩的图片 85 | * maxLength 压缩后最大字节大小 86 | * size 压缩到的尺寸 87 | * return 压缩后图片的二进制 88 | */ 89 | public class func compressImage(_ image: UIImage, _ maxLength: Int, _ size:CGSize) -> Data? { 90 | return lgl_basekit_compressImage(image: image, maxLength: maxLength, size: size) 91 | } 92 | 93 | /** 94 | * 尺寸的重置 重置的size 95 | */ 96 | public class func reSetSizeImage(_ size:CGSize, _ image: UIImage) -> UIImage { 97 | return lgl_basekit_reSizeImage(reSize: size, image: image) 98 | } 99 | 100 | ///json字符串去除空格 101 | public class func jsonStrRemoveSpace(_ jsonStr: String) -> String { 102 | return lgl_basekit_jsonStrRemoveSpace(jsonStr) 103 | } 104 | 105 | ///url字符串utf-8编码 106 | public class func urlEncodingToUtf8(_ str: String) -> String { 107 | return lgl_basekit_jstrEncodingToUtf8(str) 108 | } 109 | } 110 | 111 | 112 | private extension LGLMethod { 113 | 114 | class func lgl_basekit_jstrEncodingToUtf8(_ str: String) -> String { 115 | if str.count > 0 { 116 | let userved = "!NULL,'()*+,-./:;=?@_~%#[]" 117 | let allowed = NSMutableCharacterSet(charactersIn: userved) 118 | let urlStr = str.addingPercentEncoding(withAllowedCharacters:allowed as CharacterSet) 119 | return urlStr! 120 | } 121 | return str 122 | } 123 | 124 | class func lgl_basekit_jsonStrRemoveSpace(_ jsonStr: String) -> String { 125 | var jsonStr = jsonStr 126 | jsonStr = jsonStr.replacingOccurrences(of: "\r", with: "") 127 | jsonStr = jsonStr.replacingOccurrences(of: "\n", with: "") 128 | jsonStr = jsonStr.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) 129 | return jsonStr 130 | } 131 | 132 | /** 133 | * 压缩上传图片到指定字节 134 | * image 压缩的图片 135 | * maxLength 压缩后最大字节大小 136 | * return 压缩后图片的二进制 137 | */ 138 | class func lgl_basekit_compressImage(image: UIImage, maxLength: Int, size:CGSize) -> Data? { 139 | let newImage = lgl_basekit_reSizeImage(reSize: CGSize(width: size.width, height: size.height), image: image) 140 | var compress: CGFloat = 0.9 141 | var data = newImage.jpegData(compressionQuality: compress) 142 | 143 | while data?.count ?? 0 > maxLength && compress > 0.01 { 144 | compress -= 0.02 145 | data = newImage.jpegData(compressionQuality: compress) 146 | } 147 | 148 | return data 149 | } 150 | 151 | 152 | /// 尺寸的重置 153 | class func lgl_basekit_reSizeImage(reSize:CGSize, image: UIImage) -> UIImage { 154 | UIGraphicsBeginImageContext(reSize); 155 | UIGraphicsBeginImageContextWithOptions(reSize,false,UIScreen.main.scale); 156 | image.draw(in: CGRect(x: 0, y: 0, width: reSize.width, height: reSize.height)); 157 | let reSizeImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!; 158 | UIGraphicsEndImageContext(); 159 | return reSizeImage; 160 | } 161 | 162 | 163 | ///判断文字的格式是否满足 164 | class func lgl_basekit_characterSetWithStr(_ characterStr: String, _ judgeText: String) -> Bool { 165 | let characterSet = NSCharacterSet(charactersIn: characterStr).inverted 166 | let filterArr:[String] = judgeText.components(separatedBy: characterSet) 167 | let filterstr:String = filterArr.joined(separator: "") 168 | let result:Bool = judgeText == filterstr 169 | if result { 170 | return true 171 | } 172 | return false 173 | } 174 | 175 | ///图片旋转90度 176 | class func lgl_basekit_rotationImage90(_ imageName: String) -> UIImage? { 177 | if let orgImage = UIImage(named: imageName) { 178 | return UIImage(cgImage:orgImage.cgImage!, 179 | scale:orgImage.scale, 180 | orientation: .down) 181 | } 182 | return nil 183 | } 184 | 185 | ///跳转Dic -> JsonStr 186 | class func lgl_basekit_dicToJsonStr(_ dic: [String: Any]) -> String? { 187 | do { 188 | let jsonData = try JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted) 189 | let jsonS = String(data: jsonData, encoding: .utf8) 190 | return jsonS! 191 | } catch { 192 | print(error) 193 | } 194 | return nil 195 | } 196 | 197 | ///跳转appStore评分 198 | class func lgl_basekit_appStoreComment(_ appId: String) { 199 | let urlStr = "itms-apps://itunes.apple.com/app/id\(appId)?action=write-review" 200 | if let openUrl = URL(string: urlStr) { 201 | lgl_basekit_openUrl(openUrl) 202 | } 203 | } 204 | 205 | ///拨打电话 206 | class func lgl_basekit_callPhone(_ number: String) { 207 | let urlString = "tel://\(number)" 208 | if let url = URL(string: urlString) { 209 | lgl_basekit_openUrl(url) 210 | } 211 | } 212 | 213 | ///返回原始图片 214 | class func lgl_basekit_originalImage(_ imageName: String) -> UIImage? { 215 | if let image = UIImage(named: imageName) { 216 | return image.withRenderingMode(.alwaysOriginal) 217 | } 218 | return nil 219 | } 220 | 221 | ///等比缩放图片获取高度 222 | class func lgl_basekit_imageHeight(_ imageW: CGFloat, _ imageH: CGFloat, _ realW: CGFloat) -> CGFloat { 223 | return (realW * imageH) / imageW 224 | } 225 | 226 | /// 根据控制器,返回当前控制器 227 | class func lgl_basekit_currentVC() -> UIViewController? { 228 | guard let rootVC = UIApplication.shared.keyWindow?.rootViewController else { 229 | return nil 230 | } 231 | return lgl_basekit_mapCurrentVC(rootVC: rootVC) 232 | } 233 | 234 | /// 递归找最上面的控制器 235 | class func lgl_basekit_mapCurrentVC(rootVC :UIViewController) -> UIViewController? { 236 | var currentVC: UIViewController? 237 | if rootVC.presentedViewController != nil { 238 | currentVC = rootVC.presentedViewController 239 | } else if rootVC.isKind(of: UITabBarController.self) == true { 240 | currentVC = lgl_basekit_mapCurrentVC(rootVC: (rootVC as! UITabBarController).selectedViewController!) 241 | } else if rootVC.isKind(of: UINavigationController.self) == true { 242 | currentVC = lgl_basekit_mapCurrentVC(rootVC: (rootVC as! UINavigationController).visibleViewController!) 243 | } else { 244 | currentVC = rootVC 245 | } 246 | return currentVC 247 | } 248 | 249 | class func lgl_basekit_createImageFrom(_ color: UIColor, _ size: CGSize) -> UIImage { 250 | let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) 251 | UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) 252 | let context = UIGraphicsGetCurrentContext() 253 | context?.setFillColor(color.cgColor) 254 | context?.fill(rect) 255 | let image = UIGraphicsGetImageFromCurrentImageContext() 256 | UIGraphicsEndImageContext() 257 | return image ?? UIImage() 258 | } 259 | 260 | ///打开链接 OpenUrl 261 | @discardableResult 262 | class func lgl_basekit_openUrl(_ url: URL) -> Bool { 263 | if UIApplication.shared.canOpenURL(url) { 264 | if #available(iOS 10.0, *) { 265 | UIApplication.shared.open(url, options: [:], completionHandler: nil) 266 | } else { 267 | UIApplication.shared.openURL(url) 268 | } 269 | return true 270 | } 271 | return false 272 | } 273 | 274 | /// 金额格式化用组分隔 prefix 自定义前缀(如 $/¥) separator 分隔符号(如,) groupingSize 分隔位数 maxFractionDigits 小数点后最多位数 275 | class func lgl_basekit_moneyFormatter(money: Double, maxFractionDigits: Int, prefix:String, separator: String, groupingSize: Int) -> String 276 | { 277 | let number = NSNumber(value: money) 278 | let formatter = NumberFormatter() 279 | // 设置显示样式 280 | formatter.numberStyle = .decimal 281 | // 设置小数点后最多2位 282 | formatter.maximumFractionDigits = maxFractionDigits 283 | // 设置小数点后最少2位(不足补0) 284 | formatter.minimumFractionDigits = 0 285 | // 自定义前缀 286 | formatter.positivePrefix = prefix 287 | // 设置用组分隔 288 | formatter.usesGroupingSeparator = true 289 | // 分隔符号 290 | formatter.groupingSeparator = separator 291 | // 分隔位数 292 | formatter.groupingSize = groupingSize 293 | // 格式化 294 | let format = formatter.string(from: number) 295 | return format ?? "\(prefix)0.00" 296 | } 297 | 298 | /// 金额格式化不用组分隔 prefix 自定义前缀(如 $/¥) maxFractionDigits 小数点后最多位数 299 | class func lgl_basekit_amountFormatter(money: Double, maxFractionDigits: Int, prefix:String) -> String 300 | { 301 | let number = NSNumber(value: money) 302 | let formatter = NumberFormatter() 303 | // 设置显示样式 304 | formatter.numberStyle = .decimal 305 | // 设置小数点后最多2位 306 | formatter.maximumFractionDigits = maxFractionDigits 307 | // 设置小数点后最少2位(不足补0) 308 | formatter.minimumFractionDigits = 0 309 | // 自定义前缀 310 | formatter.positivePrefix = prefix 311 | // 设置用组分隔 312 | formatter.usesGroupingSeparator = false 313 | // 格式化 314 | let format = formatter.string(from: number) 315 | return format ?? "0.00" 316 | } 317 | } 318 | 319 | 320 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 185226139@qq.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LGLBaseKit 2 | 3 | [![CI Status](https://img.shields.io/travis/185226139@qq.com/LGLBaseKit.svg?style=flat)](https://travis-ci.org/185226139@qq.com/LGLBaseKit) 4 | [![Version](https://img.shields.io/cocoapods/v/LGLBaseKit.svg?style=flat)](https://cocoapods.org/pods/LGLBaseKit) 5 | [![License](https://img.shields.io/cocoapods/l/LGLBaseKit.svg?style=flat)](https://cocoapods.org/pods/LGLBaseKit) 6 | [![Platform](https://img.shields.io/cocoapods/p/LGLBaseKit.svg?style=flat)](https://cocoapods.org/pods/LGLBaseKit) 7 | 8 | ## 前言 9 | 10 | 本库旨在方便码友便捷获取常用的设备数据、创建控件、快速的搭建应用。 码友可以把常用的方法提供给我,我会在 `LGLMethod`类里面补充。 欢迎加群 457236811 交流。 11 | 12 | ## Installation 13 | 14 | LGLBaseKit is available through [CocoaPods](https://cocoapods.org). To install 15 | it, simply add the following line to your Podfile: 16 | 17 | #### 1.全部导入 18 | 19 | ```ruby 20 | 21 | pod 'LGLBaseKit' 22 | 23 | ``` 24 | 25 | #### 2.只导入UI相关代码 26 | 27 | ```ruby 28 | 29 | //只导入与UI相关文件(LGLExtension, LGLDeviceInfo, LGLAlert) 30 | pod 'LGLBaseKit/LGLBaseUIKit' 31 | 32 | ``` 33 | #### 3.单独文件导入 34 | 35 | ```ruby 36 | 37 | //只导入LGLExtension创建和修改view的扩展方法 38 | pod 'LGLBaseKit/LGLExtension' 39 | 40 | //只导入LGLPublicMethod常用的方法 41 | pod 'LGLBaseKit/LGLExtension' 42 | 43 | //只导入LGLDeviceInfo设备的参数(包括app信息和手机系统信息) 44 | pod 'LGLBaseKit/LGLDeviceInfo' 45 | 46 | //只导入LGLAlert简单封装系统的alert和action弹窗 47 | pod 'LGLBaseKit/LGLAlert' 48 | //只导入LGLCrypt加密(Md5加密,AESAES(128+CBC+PKCS7Padding),RSA(SHA1withRSA)加签,验签,加解密等) 49 | pod 'LGLBaseKit/LGLCrypt' 50 | 51 | ``` 52 | 53 | ## 0.1.2版本更新 54 | 55 | #### 补充判断设备的Model(iPhone 11 Pro, iPhone XS Max .......) 56 | #### 新增一些实用的方法,请查看具体代码 57 | 58 | ## 0.0.8版本更新摘要 59 | 60 | 1.修复LGLMethod里面用"*"替换文字没有效果 61 | 2.LGLMethod新增新的方法。 62 | 3.增加 LGLShowText 简单的提示错误文字弹窗 63 | ``` 64 | class func showTextView(_ message: String?) 65 | class func showTextView(_ message: String?, _ textFont: UIFont) 66 | ``` 67 | 4.新增获取屏幕适配比例的方法 68 | ``` 69 | /**获取宽度比例 以iphone6 为基准 70 | 默认屏幕宽度比例大于1(X:1.104)的默认乘以1.02 */ 71 | class func wRatio(ratio: CGFloat = 1.02) -> CGFloat 72 | 73 | /** 获取高度比例 以iphone6 为基准 74 | 默认屏幕高度比例大于1的 乘以1.02 75 | (5.8的返回1.0,因为宽度比例是1所以不做高度增加处理)*/ 76 | class func hRatio(ratio: CGFloat = 1.02) -> CGFloat 77 | ``` 78 | 79 | ## 0.0.7版本更新摘要 80 | 81 | #### 新增可以只导入UI相关的方法 82 | 83 | ``` 84 | pod 'LGLBaseKit/LGLBaseUIKit' 85 | 86 | ``` 87 | 88 | ## 0.0.6版本部分重要更新摘要 89 | 90 | #### 1. 支持每个部分文件单独导入 91 | #### 2. UIColor新增用于适配`iOS13`的暗黑和其他模式的颜色设置 92 | ``` 93 | ///适配暗黑模式设置颜色 dark -- 暗黑模式下的颜色 light -- 其他模式下的颜色 94 | UIColor.lgl_traitColor(darkColor, lightColor) -> UIColor 95 | UIColor.lgl_traitColor(lightColor) -> UIColor 96 | ``` 97 | #### 3. 修复UITextField在`iOS13`用`KVC`设置`_placeholderLabel`颜色和字体大小,崩溃问题 98 | #### 4. 新增`LGLAlert`系统的提示弹框 99 | #### 5. 新增`LGLCrypt`加密工具 100 | 101 | 102 | ## How to use ? 103 | 104 | #### 一、 导入头文件 105 | 106 | ``` 107 | import LGLBaseKit 108 | ``` 109 | 110 | 111 | #### 二、 `LGLDevice`分类包含跟设备相关参数 (屏幕的宽高,设备型号判断,设备的参数, 系统参数等等) 112 | 113 | ``` LGLDevice分类使用: LGLDevice.screenBounds ``` 114 | 115 | #### 1.常用的设备的系数和机型判断 116 | 117 | | 属性/变量/方法 | 返回值类型 | 说明 | 118 | | --- | --- | --- | 119 | | screenBounds | CGRect | 设备整个屏幕的大小 | 120 | | screenWidth | CGFloat | 设备屏幕的宽 | 121 | | screenHeight | CGFloat | 设备屏幕的高 | 122 | | screenScale | CGFloat | 设备屏幕的倍数 @2x @3x | 123 | | navigationHeight | CGFloat | 导航栏高度 | 124 | | statusBarHeight | CGFloat | 状态栏的高度 | 125 | | navigationBarHeight | CGFloat | navigationBar的高度 | 126 | | tabBarHeight | CGFloat | Tabbar的高度 | 127 | | bottomSafeAreaHeight | CGFloat | 底部安全域的高度 | 128 | | widthRatio | CGFloat | 屏幕横向适配系数 以iphone6 为基准 | 129 | | heightRatio | CGFloat | 屏幕纵向适配系数 以iphone6 为基准 | 130 | | wRatio | CGFloat | 屏幕横向适配系数 参数默认ratio=1.02 | 131 | | hRatio | CGFloat | 屏幕纵向适配系数 参数默认ratio=1.02 | 132 | | phoneModelSize| CGSize | 获取当前设备分辨率 | 133 | | phoneEqualTo(_ size: CGSize) | Bool | 比较两个设备的分辨率(跟当前的设备比较) | 134 | | iPadType | Bool | 判断是否是IPad | 135 | | iPhoneXType | Bool | 判断是否是齐刘海设备系列 | 136 | | iPhoneInch65 | Bool | 判断6.5Inch (iPhone XS Max) | 137 | | iPhoneInch61 | Bool | 判断6.1Inch (iPhone XR) | 138 | | iPhoneInch58 | Bool |判断5.8Inch (iPhone XS/ iPhone X) | 139 | | iPhoneInch55 | Bool |判断5.5Inch (iPhone 6/6s/7/8 Plus) | 140 | | iPhoneInch47 | Bool |判断4.7Inch (iPhone 6/6s/7/8) | 141 | | iPhoneInch4 | Bool | 判断4Inch (iPhone SE) | 142 | 143 | #### 2.系统配置信息 144 | 145 | | 属性/变量/方法 | 返回值类型 | 说明 | 146 | | --- | --- | --- | 147 | | systemVersion | String | 获取系统版本 | 148 | | systemName | String | 获取系统名称 | 149 | | deviceModel | String | 获取系统名称 iPhone", "iPod touch" | 150 | | deviceLocalizedModel | String | 获取系统名称 localized version of model | 151 | | deviceUserName | String | 获取设备名称 如 XXX的iphone | 152 | | deviceDiskTotalSize | String | 获取总的内存 | 153 | | deviceAvalibleDiskSize | String | 获取可用的内存 | 154 | | supplier | String | 获取运营商 | 155 | | deviceIP | String | 获取当前设备IP | 156 | | deviceCpuCount | Int | 获取cpu核数 | 157 | | deviceCpuType | String | 获取cpu类型 | 158 | | deviceName | String | 获取设备名称 | 159 | 160 | #### 3.APP信息 161 | 162 | | 属性/变量/方法 | 返回值类型 | 说明 | 163 | | --- | --- | --- | 164 | | appName | String | App名称 获取失败则返回空字符串 | 165 | | appBundleId | String | App包名 获取失败则返回空字符串 | 166 | | appVersion | String | App版本号 获取失败则返回空字符串 | 167 | | appIdfa | String | AppIdfa 用户关闭,则返回空字符串 | 168 | | appIdfv | String | AppIdfv 获取失败则返回空字符串 | 169 | | appBundleName | String | app工程名称 获取失败则返回空字符串 | 170 | 171 | 172 | #### 三、UI控件(绘制阴影,渐变色,View转图片,根据View获取控制器)、颜色、字符串(富文本, 常见的正则判断等)的 Extension 173 | 174 | #### `1. UI控件,使用的时候都使用 类名或者实例 来创建或者设置,更多方法请查阅具体view的扩展方法` 175 | 176 | 177 | `UIView+Extension` 178 | 179 | ``` 180 | ///初始化View 设置背景颜色 181 | let view = UIView.lgl_view(.red) 182 | ``` 183 | 184 | ``` 185 | ///初始化View 设置背景颜色、圆角 186 | let view2 = UIView() 187 | view2.lgl_view(.red, 20) 188 | ``` 189 | 190 | ``` 191 | /// 水平渐变 192 | let view3 = UIView() 193 | view3.lgl_horizontalGradientLayer(.red, .red, 20) 194 | ``` 195 | 196 | ``` 197 | /// 垂直渐变 198 | view3.lgl_verticalGradientLayer(.red, .red, 20) 199 | ``` 200 | 201 | ``` 202 | /// 设置view的切角 203 | view3.lgl_roundingCorner([.topLeft, .topRight], _ radii: 5) 204 | ``` 205 | 206 | ``` 207 | ///给View添加阴影 208 | view3.lgl_shadow(.red, CGSize(width:0, height:3), 0.2, 10, 8) 209 | ``` 210 | 211 | ``` 212 | ///给View添加阴影和边框 213 | view3.lgl_shadowBorder(.red, CGSize(width:0, height:3), 0.2, 10, 8, .gray) 214 | ``` 215 | 216 | ``` 217 | ///获取当前View的控制器 218 | let currentVC = view3.lgl_viewGetcurrentVC() 219 | ``` 220 | 221 | ``` 222 | ///view转图片 223 | let image = view3.lgl_viewToImage() 224 | ``` 225 | 226 | `UIImageView+Extension` 227 | 228 | ``` 229 | ///设置图片初始化 230 | let imageV = UIImageView.lgl_imagView("图片名字.png") 231 | ``` 232 | 233 | ``` 234 | ///设置图片 235 | let imageV = UIImageView() 236 | imageV.lgl_imagView("图片名字.png") 237 | ``` 238 | 239 | 240 | `UILabel+Extension` 241 | 242 | ``` 243 | ///初始化label 字体、字体颜色 字体大小、对齐方式、行数 244 | let label = UILabel.lgl_label("文字", .red, UIFont.systemFont(ofSize: 14), .left, 0) 245 | ``` 246 | 247 | ``` 248 | ///设置label 字体、字体颜色、背景颜色、 字体大小、对齐方式、行数 249 | let label = UILabel() 250 | label.lgl_label("文字", .red, .white, UIFont.systemFont(ofSize: 14),.left, 0) 251 | ``` 252 | 253 | ``` 254 | ///设置label 切圆角 255 | let label = UILabel() 256 | label.lgl_labelRadius(12) 257 | ``` 258 | ``` 259 | ///设置label 边框和边框颜色 260 | let label = UILabel() 261 | label.lgl_labelBorder(.red, 1) 262 | ``` 263 | 264 | ``` 265 | ///设置label 边框、边框颜色、切圆角 266 | let label = UILabel() 267 | label.lgl_labelBorder(.red, 1, 10) 268 | 269 | ``` 270 | 271 | `UIButton+Extension` 272 | 273 | ``` 274 | ////初始化button 设置 标题文字、文字颜色、文字大小 275 | let btn = UIButton.lgl_button("标题", .red, UIFont.systemFont(ofSize: 14), self, #selector(selectBtn)) 276 | ``` 277 | 278 | ``` 279 | ////设置button 标题文字、文字颜色、文字大小 280 | let btn = UIButton(type: .custom) 281 | btn.lgl_button("标题", .red, UIFont.systemFont(ofSize: 14), self, #selector(selectBtn)) 282 | ``` 283 | ``` 284 | ///设置图片 285 | let btn = UIButton(type: .custom) 286 | btn.lgl_buttonImage("normal_image_name.png", "select_image_name.png") 287 | ``` 288 | ``` 289 | ///设置背景图片 290 | let btn = UIButton(type: .custom) 291 | btn.lgl_buttonBackgroundImage("normal_back_image_name.png", "select_back_image_name.png") 292 | ``` 293 | ``` 294 | ///设置圆角 295 | let btn = UIButton(type: .custom) 296 | btn.lgl_buttonRadius(10) 297 | ``` 298 | 299 | ``` 300 | ///设置边框颜色、边框宽度 301 | let btn = UIButton(type: .custom) 302 | btn.lgl_buttonBorder(.red, 1) 303 | ``` 304 | 305 | ``` 306 | ///设置边框颜色、边框宽度、圆角 307 | let btn = UIButton(type: .custom) 308 | btn.lgl_buttonBorder(.red, 1, 10) 309 | ``` 310 | 311 | 312 | `UITextField+Extension` 313 | 314 | ``` 315 | ///初始化TextField 字体颜色、 字体大小、提示文字、边框样式 316 | let field = UITextField.lgl_textField(.red, UIFont.systemFont(ofSize: 14), "提示文字", .none) 317 | ``` 318 | 319 | ``` 320 | ///设置TextField 字体大小、字体颜色、提示文字、边框样式 321 | let field = UITextField() 322 | field.lgl_textField(.red, UIFont.systemFont(ofSize: 14), "提示文字", _ borderStyle: .none) 323 | ``` 324 | 325 | ``` 326 | ///设置Placeholder的字体大小和颜色 327 | let field = UITextField() 328 | field.lgl_textFieldPlaceholder(.red, UIFont.systemFont(ofSize: 14)) 329 | ``` 330 | 331 | ``` 332 | ///设置LeftView 333 | let field = UITextField() 334 | let leftView = UIView() 335 | field.lgl_textFieldSetLeftView(leftView) 336 | ``` 337 | 338 | ``` 339 | ///设置RightView 340 | let field = UITextField() 341 | let rightView = UIView() 342 | field.lgl_textFieldSetRightView(rightView) 343 | ``` 344 | 345 | ``` 346 | ///修改clear按钮的图片 347 | let field = UITextField() 348 | field.lgl_textFieldChangeClearButton("clear_btn_image.png") 349 | ``` 350 | 351 | ``` 352 | ///切圆角 353 | let field = UITextField() 354 | field.lgl_textFieldCornerRadius(10) 355 | ``` 356 | 357 | `UIImage+Extension` 358 | 359 | ``` 360 | /**图片拉伸 指定 361 | edgeInset 指定不被拉伸的区域 362 | imageName 图片名称 363 | resizeMode UIImageResizingModeTile,//进行区域复制模式拉伸 【-】 -> 【-】【-】【-】 364 | resizeMode UIImageResizingModeStretch,//进行渐变复制模式拉伸 连续的 【-】 -> 【-----】 365 | */ 366 | let image = UIImage(named:"image.png") 367 | ///设置要保留的部分 368 | let uiedgeSet = UIEdgeInsets(top: 11, left:0, bottom: 11, right: 0) 369 | let resizeMode = .stretch 370 | 371 | let strechImage = image.lgl_stretchImage(uiedgeSet, resizeMode) 372 | } 373 | 374 | ``` 375 | 376 | ` 2. 颜色` 377 | 378 | ``` 379 | ///设置颜色 380 | let color = UIColor(0xefefef) 381 | let color = UIColor.lgl_color("#efefef") -> UIColor 382 | ``` 383 | 384 | ``` 385 | ///适配暗黑模式设置颜色 dark -- 暗黑模式下的颜色 light -- 其他模式下的颜色 386 | ///darkColor lightColor 387 | let color = UIColor.lgl_traitColor(.white, black) 388 | let color = UIColor.lgl_traitColor(.white) 389 | ``` 390 | 391 | `3. 字符串` 392 | 393 | /// --- 基于NSRegularExpression判断 -- 394 | 395 | | 方法 | 返回值类型 | 说明 | 396 | | --- | --- | --- | 397 | | lgl_isMatch(regularString: String) | Bool | 字符串参数(自定义正则判断) | 398 | | lgl_isMatch(regularString: XLRegularString) | Bool | 枚举值参数(自定义正则判断) | 399 | | lgl_isPhoneNumber()| Bool | 判断手机号 400 | | lgl_isTelePhoneNumber() | Bool | 判断固定电话| 401 | | lgl_isVericationCode() | Bool | 验证码格式| 402 | | lgl_isEmail() | Bool | 判断邮箱| 403 | | lgl_isUsername() | Bool | 判断用户名 | 404 | | lgl_isPassword()| Bool | 判断密码| 405 | | lgl_isPostalCode()| Bool | 判断邮政编码 | 406 | | lgl_isIDCardNumber()| Bool | 判断身份证号 | 407 | | lgl_hasNumber()| Bool | 是否包含数字的字符串| 408 | | lgl_allNumber()| Bool | 是否纯数字字符串 | 409 | | lgl_hasLowerCase()| Bool | 是否包含小写字母的字符串 | 410 | | lgl_allLowerCase()| Bool | 是否纯小写字母字符串 | 411 | | lgl_hasUpperCase()| Bool | 是否包含大写字母的字符串 | 412 | | lgl_allUpperCase()| Bool | 是否纯大写字母字符串 | 413 | | lgl_hasLetter()| Bool | 是否包含字母的字符串| 414 | | lgl_allLetter()| Bool | 是否纯字母字符串 | 415 | | lgl_hasNumberOrLetter()| Bool | 是否包含数字或字母的字符串 | 416 | | lgl_bothNumberAndLetter()| Bool | 是否同时包含数字和密码的字符串 | 417 | | lgl_hasEmoji()| Bool | 是否包含表情符| 418 | | lgl_hasChinese()| Bool | 是否包含中文字符| 419 | 420 | 421 | `NSAttributedString` 422 | 423 | ``` 424 | ///获取某一段文字的CGSize 425 | let str = "这是要获取字符串size的文字" 426 | let font = UIFont.systemFont(ofSize: 14) 427 | let maxWidth = 100 428 | let size = str.lgl_getStrSize(font, maxWidth) 429 | ``` 430 | 431 | ``` 432 | 433 | ///修改指定文字的字体大小 和 颜色 434 | let str = "这是要获取字符串size的文字" 435 | let changeText = "获取字符" 436 | let attributestr = str.lgl_modifyRangeText(changeText, .red, font) 437 | 438 | ``` 439 | ``` 440 | ///设置行间距 441 | let lineHeight = 5 442 | let alignment = .center 443 | let attributestr = str.lgl_modifyLineHeight(lineHeight, alignment) 444 | ``` 445 | 446 | ``` 447 | ///设置指定范围内文字的颜色 448 | let range = NSRange(location:1, length: 3) 449 | let attributestr = str.lgl_modifyRangeTextColor(range, .red) 450 | ``` 451 | 452 | ``` 453 | 454 | ///设置指定范围内文字的下划线 颜色 455 | let range = NSRange(location:1, length: 3) 456 | let rangeColor = .red 457 | let lineColor = .red 458 | let attributestr = str.lgl_modifyRangeUnderLine( range, rangeColor, lineColor) 459 | ``` 460 | 461 | ``` 462 | ///设置行间距 和 首行缩进缩进两个字符 463 | let lineHeight = 5 464 | let font = UIFont.systemFont(ofSize: 14) 465 | let attributestr = str.lgl_setHeadIndent(lineHeight, font) 466 | ``` 467 | 468 | ``` 469 | ///设置一条文字中间的线 470 | let range = NSRange(location:1, length: 3) 471 | let lineColor = .red 472 | let attributestr = str.lgl_setThroughLine(range, lineColor) 473 | ``` 474 | 475 | ``` 476 | ///获取设置行高以后的字符串的Size(高) 477 | let lineHeight = 5 478 | let font = UIFont.systemFont(ofSize: 14) 479 | let maxW = 100 480 | let size = str.lgl_getLineHeightSize(lineHeight, font, maxW) 481 | ``` 482 | 483 | `4. NSRegularExpression+Extension` 484 | 485 | 486 | `匹配` 487 | 488 | ``` 489 | ///匹配 490 | let res:Bool = NSRegularExpression.lgl_isMatch(string: "判断的字符串", pattern: "正则字符串") 491 | ``` 492 | `替换` 493 | 494 | ``` 495 | let str = NSRegularExpression.lgl_replacement(string: "判断的字符串", replace: "要替换的字符串", pattern: "正则字符串") 496 | ``` 497 | 498 | 499 | #### 四、一些常见的方法包含在类 `LGLMethod`(会持续补充方法) 500 | 501 | `这里只列举几个,更多的请查看具体的LGLMethod里面` 502 | 503 | ``` 504 | ///返回原始图片 505 | let oriImage = LGLMethod.originalImage("image_name.png") 506 | ``` 507 | 508 | ``` 509 | ///等比缩放图片获取高度 imageW imageH realW具体使用时候的宽度 510 | let H = LGLMethod.imageHeight(750, 300, 600) 511 | ``` 512 | 513 | ``` 514 | ///根据root控制器,返回当前控制器 515 | let currentVC = LGLMethod.currentVC() 516 | ``` 517 | 518 | ``` 519 | ///根据颜色生成图片(UIImage) 520 | let image = LGLMethod.imageWithColor(.red, CGSize(width:100, height:100)) 521 | ``` 522 | 523 | ``` 524 | ///打开链接 OpenUrl 525 | @discardableResult 526 | LGLMethod.openUrl(url) 527 | ``` 528 | 529 | ``` 530 | ///拨打电话 531 | LGLMethod.lgl_callPhone(number) 532 | ``` 533 | 534 | ``` 535 | /// 跳转appStore 评论 536 | LGLMethod.lgl_appStoreComment(appId) 537 | ``` 538 | 539 | #### 四、`LGLAlert`系统的提示弹框 540 | 541 | ``` 542 | ///aler提示框 标题 内容 展示时间(默认1s) 543 | LGLAlert.lgl_alert("提示", "提示内容", 2) 544 | ``` 545 | 546 | ``` 547 | ///ationSheet 提示框 标题 内容 展示时间(默认1s) 548 | LGLAlert.lgl_ationSheet("提示", "提示内容", 2) 549 | ``` 550 | 551 | ``` 552 | ///一个按钮的filed弹窗 标题 内容 按钮标题 提示文字 553 | LGLAlert.lgl_field("提示", "提示内容", "确定", "提示文字", handler:{(filedValue) in 554 | print(filedValue) 555 | }) 556 | ``` 557 | 558 | #### 五、`LGLCrypt`加密工具 559 | 560 | 561 | `包含 Md5加密,AESAES(128+CBC+PKCS7Padding),RSA加解密、加签和验签` 562 | 563 | `Md5` 564 | 565 | ``` 566 | let md5Str = LGLCrypt.lgl_md5Encrypt("要加密的字符串") 567 | ``` 568 | 569 | `AES加解密` 570 | 571 | ``` 572 | ///AES加密([UInt8]c形式的key和iv) 573 | let key:[UInt8] //[UInt8]类型的key 574 | let iv: [UInt8] //[UInt8]类型的iv 575 | let aesEcrypt = LGLCrypt.lgl_aesEncrypt("要加密的字符串", key, iv) 576 | 577 | ///AES解密([UInt8]c形式的key和iv) 578 | let aesDecrypt = LGLCrypt.lgl_aesDecrypt("要解密的字符串", key, iv) 579 | ``` 580 | 581 | ``` 582 | ///AES加密(字符串形式的key和iv) 583 | let key = "" 584 | let iv= "" 585 | let aesEcrypt = LGLCrypt.lgl_aesEncryptStr("要加密的字符串",key, iv) 586 | 587 | ///AES解密(字符串形式的key和iv) 588 | let aesDecrypt = LGLCrypt.lgl_aesDecryptStr("要解密的字符串", key, iv) 589 | ``` 590 | 591 | `RSA加解密、加签和验签` 592 | 593 | ``` 594 | /// RSA签名 595 | let privateKey = "" 596 | let privateKeychainTag = "" 597 | let signStr = LGLCrypt.lgl_rsaSignWithSHA1("要签名字符串", privateKey, privateKeychainTag) 598 | 599 | /// RSA验签 600 | let publicKey = "" 601 | //Bool 602 | let res = LGLCrypt.lgl_rsaSignVerifyWithSHA1("原始字符串", "签名的字符串", publicKey, privateKeychainTag) 603 | ``` 604 | 605 | ``` 606 | let publicKey = "" 607 | let privateKeychainTag = "" 608 | /// RSA公钥加密 609 | let encryptStr = LGLCrypt.lgl_rsaEncrypt("要加密的字符串", publicKey,publicKeychainTag) 610 | 611 | /// RSA私钥解密 612 | let privateKey = "" 613 | let decryptStr = LGLCrypt.lgl_rsaDecrypt("要解密的字符串", privateKey, privateKeychainTag:String) 614 | 615 | /// RSA公钥解密 616 | let decryptStr = LGLCrypt.lgl_rsaDecryptPublic("要解密的字符串", publicKey, publicKeychainTag) 617 | ``` 618 | 619 | ## Author 620 | 621 | liguoliang, yuanxinliang 622 | 623 | 欢迎加群 : 457236811 提供建议和交流 624 | 625 | ## Contributors 626 | 627 | wait for you ... 628 | 629 | 630 | ## License 631 | 632 | LGLBaseKit is available under the MIT license. See the LICENSE file for more info. 633 | -------------------------------------------------------------------------------- /_Pods.xcodeproj: -------------------------------------------------------------------------------- 1 | Example/Pods/Pods.xcodeproj --------------------------------------------------------------------------------