├── DSAlert-Swift.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── boai.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ ├── cj.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── luxiaofeng.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── boai.xcuserdatad │ └── xcschemes │ │ ├── DSAlert-Swift.xcscheme │ │ └── xcschememanagement.plist │ ├── cj.xcuserdatad │ └── xcschemes │ │ ├── DSAlert-Swift.xcscheme │ │ └── xcschememanagement.plist │ └── luxiaofeng.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── DSAlert-Swift.xcscheme │ └── xcschememanagement.plist ├── DSAlert-Swift ├── 123.png ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── DSActionSheet │ ├── DSActionSheet.swift │ ├── DSTableCell.swift │ └── DSTableCell.xib ├── DSAlert │ ├── DSAlert.swift │ ├── DSAlertImageEffects.swift │ └── MyAnimation.swift ├── Info.plist ├── ViewController.swift ├── ViewController2.swift ├── 美女.jpg └── 背景.jpg ├── LICENSE └── README.md /DSAlert-Swift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 610E28331D77056B007E16B1 /* DSActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 610E28321D77056B007E16B1 /* DSActionSheet.swift */; }; 11 | 610E28351D77087D007E16B1 /* DSAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 610E28341D77087D007E16B1 /* DSAlert.swift */; }; 12 | 6199631E1D77C67100C886C4 /* MyAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6199631D1D77C67100C886C4 /* MyAnimation.swift */; }; 13 | 619963201D77CEBF00C886C4 /* DSAlertImageEffects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6199631F1D77CEBF00C886C4 /* DSAlertImageEffects.swift */; }; 14 | 619963221D78150700C886C4 /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 619963211D78150700C886C4 /* ViewController2.swift */; }; 15 | 61E6F4111D7721B000B106BB /* DSTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E6F40F1D7721B000B106BB /* DSTableCell.swift */; }; 16 | 61E6F4121D7721B000B106BB /* DSTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 61E6F4101D7721B000B106BB /* DSTableCell.xib */; }; 17 | 61E6F4161D7725BE00B106BB /* 123.png in Resources */ = {isa = PBXBuildFile; fileRef = 61E6F4131D7725BE00B106BB /* 123.png */; }; 18 | 61E6F4171D7725BE00B106BB /* 背景.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 61E6F4141D7725BE00B106BB /* 背景.jpg */; }; 19 | 61E6F4181D7725BE00B106BB /* 美女.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 61E6F4151D7725BE00B106BB /* 美女.jpg */; }; 20 | 61ECADAA1D76D7EC00944CD7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ECADA91D76D7EC00944CD7 /* AppDelegate.swift */; }; 21 | 61ECADAC1D76D7EC00944CD7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ECADAB1D76D7EC00944CD7 /* ViewController.swift */; }; 22 | 61ECADAF1D76D7EC00944CD7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61ECADAD1D76D7EC00944CD7 /* Main.storyboard */; }; 23 | 61ECADB11D76D7EC00944CD7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 61ECADB01D76D7EC00944CD7 /* Assets.xcassets */; }; 24 | 61ECADB41D76D7EC00944CD7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61ECADB21D76D7EC00944CD7 /* LaunchScreen.storyboard */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 610E28321D77056B007E16B1 /* DSActionSheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSActionSheet.swift; sourceTree = ""; }; 29 | 610E28341D77087D007E16B1 /* DSAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSAlert.swift; sourceTree = ""; }; 30 | 6199631D1D77C67100C886C4 /* MyAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyAnimation.swift; sourceTree = ""; }; 31 | 6199631F1D77CEBF00C886C4 /* DSAlertImageEffects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSAlertImageEffects.swift; sourceTree = ""; }; 32 | 619963211D78150700C886C4 /* ViewController2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = ""; }; 33 | 61E6F40F1D7721B000B106BB /* DSTableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSTableCell.swift; sourceTree = ""; }; 34 | 61E6F4101D7721B000B106BB /* DSTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DSTableCell.xib; sourceTree = ""; }; 35 | 61E6F4131D7725BE00B106BB /* 123.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 123.png; sourceTree = ""; }; 36 | 61E6F4141D7725BE00B106BB /* 背景.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "背景.jpg"; sourceTree = ""; }; 37 | 61E6F4151D7725BE00B106BB /* 美女.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "美女.jpg"; sourceTree = ""; }; 38 | 61ECADA61D76D7EC00944CD7 /* DSAlert-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DSAlert-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 61ECADA91D76D7EC00944CD7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 40 | 61ECADAB1D76D7EC00944CD7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 41 | 61ECADAE1D76D7EC00944CD7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 61ECADB01D76D7EC00944CD7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 43 | 61ECADB31D76D7EC00944CD7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 44 | 61ECADB51D76D7EC00944CD7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 61ECADA31D76D7EC00944CD7 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 61ECAD9D1D76D7EC00944CD7 = { 59 | isa = PBXGroup; 60 | children = ( 61 | 61ECADA81D76D7EC00944CD7 /* DSAlert-Swift */, 62 | 61ECADA71D76D7EC00944CD7 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 61ECADA71D76D7EC00944CD7 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 61ECADA61D76D7EC00944CD7 /* DSAlert-Swift.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 61ECADA81D76D7EC00944CD7 /* DSAlert-Swift */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 61ECADBB1D76D89900944CD7 /* DSActionSheet */, 78 | 61ECADBC1D76D89900944CD7 /* DSAlert */, 79 | 61ECADA91D76D7EC00944CD7 /* AppDelegate.swift */, 80 | 61ECADAB1D76D7EC00944CD7 /* ViewController.swift */, 81 | 619963211D78150700C886C4 /* ViewController2.swift */, 82 | 61ECADAD1D76D7EC00944CD7 /* Main.storyboard */, 83 | 61E6F4131D7725BE00B106BB /* 123.png */, 84 | 61E6F4141D7725BE00B106BB /* 背景.jpg */, 85 | 61E6F4151D7725BE00B106BB /* 美女.jpg */, 86 | 61ECADB01D76D7EC00944CD7 /* Assets.xcassets */, 87 | 61ECADB21D76D7EC00944CD7 /* LaunchScreen.storyboard */, 88 | 61ECADB51D76D7EC00944CD7 /* Info.plist */, 89 | ); 90 | path = "DSAlert-Swift"; 91 | sourceTree = ""; 92 | }; 93 | 61ECADBB1D76D89900944CD7 /* DSActionSheet */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 610E28321D77056B007E16B1 /* DSActionSheet.swift */, 97 | 61E6F40F1D7721B000B106BB /* DSTableCell.swift */, 98 | 61E6F4101D7721B000B106BB /* DSTableCell.xib */, 99 | ); 100 | path = DSActionSheet; 101 | sourceTree = ""; 102 | }; 103 | 61ECADBC1D76D89900944CD7 /* DSAlert */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 610E28341D77087D007E16B1 /* DSAlert.swift */, 107 | 6199631D1D77C67100C886C4 /* MyAnimation.swift */, 108 | 6199631F1D77CEBF00C886C4 /* DSAlertImageEffects.swift */, 109 | ); 110 | path = DSAlert; 111 | sourceTree = ""; 112 | }; 113 | /* End PBXGroup section */ 114 | 115 | /* Begin PBXNativeTarget section */ 116 | 61ECADA51D76D7EC00944CD7 /* DSAlert-Swift */ = { 117 | isa = PBXNativeTarget; 118 | buildConfigurationList = 61ECADB81D76D7EC00944CD7 /* Build configuration list for PBXNativeTarget "DSAlert-Swift" */; 119 | buildPhases = ( 120 | 61ECADA21D76D7EC00944CD7 /* Sources */, 121 | 61ECADA31D76D7EC00944CD7 /* Frameworks */, 122 | 61ECADA41D76D7EC00944CD7 /* Resources */, 123 | ); 124 | buildRules = ( 125 | ); 126 | dependencies = ( 127 | ); 128 | name = "DSAlert-Swift"; 129 | productName = "DSAlert-Swift"; 130 | productReference = 61ECADA61D76D7EC00944CD7 /* DSAlert-Swift.app */; 131 | productType = "com.apple.product-type.application"; 132 | }; 133 | /* End PBXNativeTarget section */ 134 | 135 | /* Begin PBXProject section */ 136 | 61ECAD9E1D76D7EC00944CD7 /* Project object */ = { 137 | isa = PBXProject; 138 | attributes = { 139 | LastSwiftUpdateCheck = 0730; 140 | LastUpgradeCheck = 0730; 141 | ORGANIZATIONNAME = zeroLu; 142 | TargetAttributes = { 143 | 61ECADA51D76D7EC00944CD7 = { 144 | CreatedOnToolsVersion = 7.3.1; 145 | }; 146 | }; 147 | }; 148 | buildConfigurationList = 61ECADA11D76D7EC00944CD7 /* Build configuration list for PBXProject "DSAlert-Swift" */; 149 | compatibilityVersion = "Xcode 3.2"; 150 | developmentRegion = English; 151 | hasScannedForEncodings = 0; 152 | knownRegions = ( 153 | en, 154 | Base, 155 | ); 156 | mainGroup = 61ECAD9D1D76D7EC00944CD7; 157 | productRefGroup = 61ECADA71D76D7EC00944CD7 /* Products */; 158 | projectDirPath = ""; 159 | projectRoot = ""; 160 | targets = ( 161 | 61ECADA51D76D7EC00944CD7 /* DSAlert-Swift */, 162 | ); 163 | }; 164 | /* End PBXProject section */ 165 | 166 | /* Begin PBXResourcesBuildPhase section */ 167 | 61ECADA41D76D7EC00944CD7 /* Resources */ = { 168 | isa = PBXResourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | 61E6F4171D7725BE00B106BB /* 背景.jpg in Resources */, 172 | 61ECADB41D76D7EC00944CD7 /* LaunchScreen.storyboard in Resources */, 173 | 61E6F4181D7725BE00B106BB /* 美女.jpg in Resources */, 174 | 61ECADB11D76D7EC00944CD7 /* Assets.xcassets in Resources */, 175 | 61ECADAF1D76D7EC00944CD7 /* Main.storyboard in Resources */, 176 | 61E6F4121D7721B000B106BB /* DSTableCell.xib in Resources */, 177 | 61E6F4161D7725BE00B106BB /* 123.png in Resources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXResourcesBuildPhase section */ 182 | 183 | /* Begin PBXSourcesBuildPhase section */ 184 | 61ECADA21D76D7EC00944CD7 /* Sources */ = { 185 | isa = PBXSourcesBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | 610E28331D77056B007E16B1 /* DSActionSheet.swift in Sources */, 189 | 619963221D78150700C886C4 /* ViewController2.swift in Sources */, 190 | 619963201D77CEBF00C886C4 /* DSAlertImageEffects.swift in Sources */, 191 | 61ECADAC1D76D7EC00944CD7 /* ViewController.swift in Sources */, 192 | 6199631E1D77C67100C886C4 /* MyAnimation.swift in Sources */, 193 | 61E6F4111D7721B000B106BB /* DSTableCell.swift in Sources */, 194 | 61ECADAA1D76D7EC00944CD7 /* AppDelegate.swift in Sources */, 195 | 610E28351D77087D007E16B1 /* DSAlert.swift in Sources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | /* End PBXSourcesBuildPhase section */ 200 | 201 | /* Begin PBXVariantGroup section */ 202 | 61ECADAD1D76D7EC00944CD7 /* Main.storyboard */ = { 203 | isa = PBXVariantGroup; 204 | children = ( 205 | 61ECADAE1D76D7EC00944CD7 /* Base */, 206 | ); 207 | name = Main.storyboard; 208 | sourceTree = ""; 209 | }; 210 | 61ECADB21D76D7EC00944CD7 /* LaunchScreen.storyboard */ = { 211 | isa = PBXVariantGroup; 212 | children = ( 213 | 61ECADB31D76D7EC00944CD7 /* Base */, 214 | ); 215 | name = LaunchScreen.storyboard; 216 | sourceTree = ""; 217 | }; 218 | /* End PBXVariantGroup section */ 219 | 220 | /* Begin XCBuildConfiguration section */ 221 | 61ECADB61D76D7EC00944CD7 /* Debug */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_ANALYZER_NONNULL = YES; 226 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 227 | CLANG_CXX_LIBRARY = "libc++"; 228 | CLANG_ENABLE_MODULES = YES; 229 | CLANG_ENABLE_OBJC_ARC = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_UNREACHABLE_CODE = YES; 238 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 239 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 240 | COPY_PHASE_STRIP = NO; 241 | DEBUG_INFORMATION_FORMAT = dwarf; 242 | ENABLE_STRICT_OBJC_MSGSEND = YES; 243 | ENABLE_TESTABILITY = YES; 244 | GCC_C_LANGUAGE_STANDARD = gnu99; 245 | GCC_DYNAMIC_NO_PIC = NO; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_OPTIMIZATION_LEVEL = 0; 248 | GCC_PREPROCESSOR_DEFINITIONS = ( 249 | "DEBUG=1", 250 | "$(inherited)", 251 | ); 252 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 253 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 254 | GCC_WARN_UNDECLARED_SELECTOR = YES; 255 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 256 | GCC_WARN_UNUSED_FUNCTION = YES; 257 | GCC_WARN_UNUSED_VARIABLE = YES; 258 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 259 | MTL_ENABLE_DEBUG_INFO = YES; 260 | ONLY_ACTIVE_ARCH = YES; 261 | SDKROOT = iphoneos; 262 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 263 | TARGETED_DEVICE_FAMILY = "1,2"; 264 | }; 265 | name = Debug; 266 | }; 267 | 61ECADB71D76D7EC00944CD7 /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | ALWAYS_SEARCH_USER_PATHS = NO; 271 | CLANG_ANALYZER_NONNULL = YES; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu99; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 299 | MTL_ENABLE_DEBUG_INFO = NO; 300 | SDKROOT = iphoneos; 301 | TARGETED_DEVICE_FAMILY = "1,2"; 302 | VALIDATE_PRODUCT = YES; 303 | }; 304 | name = Release; 305 | }; 306 | 61ECADB91D76D7EC00944CD7 /* Debug */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | INFOPLIST_FILE = "DSAlert-Swift/Info.plist"; 311 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 312 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 313 | PRODUCT_BUNDLE_IDENTIFIER = com.smartboche.alertSwift; 314 | PRODUCT_NAME = "$(TARGET_NAME)"; 315 | }; 316 | name = Debug; 317 | }; 318 | 61ECADBA1D76D7EC00944CD7 /* Release */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 322 | INFOPLIST_FILE = "DSAlert-Swift/Info.plist"; 323 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 324 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 325 | PRODUCT_BUNDLE_IDENTIFIER = com.smartboche.alertSwift; 326 | PRODUCT_NAME = "$(TARGET_NAME)"; 327 | }; 328 | name = Release; 329 | }; 330 | /* End XCBuildConfiguration section */ 331 | 332 | /* Begin XCConfigurationList section */ 333 | 61ECADA11D76D7EC00944CD7 /* Build configuration list for PBXProject "DSAlert-Swift" */ = { 334 | isa = XCConfigurationList; 335 | buildConfigurations = ( 336 | 61ECADB61D76D7EC00944CD7 /* Debug */, 337 | 61ECADB71D76D7EC00944CD7 /* Release */, 338 | ); 339 | defaultConfigurationIsVisible = 0; 340 | defaultConfigurationName = Release; 341 | }; 342 | 61ECADB81D76D7EC00944CD7 /* Build configuration list for PBXNativeTarget "DSAlert-Swift" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 61ECADB91D76D7EC00944CD7 /* Debug */, 346 | 61ECADBA1D76D7EC00944CD7 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | /* End XCConfigurationList section */ 352 | }; 353 | rootObject = 61ECAD9E1D76D7EC00944CD7 /* Project object */; 354 | } 355 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/boai.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/boai.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/cj.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/cj.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/luxiaofeng.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift.xcodeproj/project.xcworkspace/xcuserdata/luxiaofeng.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/boai.xcuserdatad/xcschemes/DSAlert-Swift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/boai.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DSAlert-Swift.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 61ECADA51D76D7EC00944CD7 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/cj.xcuserdatad/xcschemes/DSAlert-Swift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/cj.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DSAlert-Swift.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 61ECADA51D76D7EC00944CD7 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/luxiaofeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/luxiaofeng.xcuserdatad/xcschemes/DSAlert-Swift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DSAlert-Swift.xcodeproj/xcuserdata/luxiaofeng.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DSAlert-Swift.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 61ECADA51D76D7EC00944CD7 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DSAlert-Swift/123.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift/123.png -------------------------------------------------------------------------------- /DSAlert-Swift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/8/31. 6 | // Copyright © 2016年 zeroLu. 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: [NSObject: AnyObject]?) -> 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 | var SCREENWIDTH = UIScreen.mainScreen().applicationFrame.size.width 48 | var SCREENHEIGHT = UIScreen.mainScreen().applicationFrame.size.height 49 | -------------------------------------------------------------------------------- /DSAlert-Swift/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /DSAlert-Swift/Base.lproj/LaunchScreen.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 | -------------------------------------------------------------------------------- /DSAlert-Swift/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /DSAlert-Swift/DSActionSheet/DSActionSheet.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DSActionSheet.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/8/31. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public enum DSCustomActionSheetStyle : Int { 12 | 13 | /*! 14 | * 普通样式 15 | */ 16 | case DSCustomActionSheetStyleNormal 17 | /*! 18 | * 带标题样式 19 | */ 20 | case DSCustomActionSheetStyleTitle 21 | /*! 22 | * 带图片和标题样式 23 | */ 24 | case DSCustomActionSheetStyleImageAndTitle 25 | /*! 26 | * 带图片样式 27 | */ 28 | case DSCustomActionSheetStyleImage 29 | } 30 | 31 | class DSActionSheet: UIView,UITableViewDelegate,UITableViewDataSource { 32 | 33 | //MARK: - property 34 | /*! 数据源 */ 35 | var dataArray = [String]() 36 | /*! 图片数组 */ 37 | var imageArray = [UIImage]?() 38 | /*! 标记颜色是红色的那行 */ 39 | var specialIndex : Int = 0 40 | /*! 标题 */ 41 | var headerTitle = String?() 42 | /*! 点击事件回调 */ 43 | var callback:Int -> Void = {_ in } 44 | /*! 自定义样式 */ 45 | var viewStyle : DSCustomActionSheetStyle = .DSCustomActionSheetStyleNormal 46 | 47 | var viewWidth : CGFloat { 48 | get { 49 | return CGRectGetWidth(UIScreen.mainScreen().bounds) 50 | } 51 | } 52 | 53 | var viewHeight : CGFloat { 54 | get { 55 | return CGRectGetHeight(UIScreen.mainScreen().bounds) 56 | } 57 | } 58 | 59 | static func shareActionSheet() -> DSActionSheet { 60 | 61 | let actionSheet = DSActionSheet() 62 | 63 | let autoresizing : UIViewAutoresizing = [.FlexibleBottomMargin , .FlexibleLeftMargin , .FlexibleRightMargin, .FlexibleWidth] 64 | 65 | actionSheet.autoresizingMask = autoresizing 66 | 67 | actionSheet.imageArray = nil 68 | 69 | actionSheet.specialIndex = -1 70 | 71 | actionSheet.headerTitle = nil 72 | 73 | return actionSheet 74 | } 75 | 76 | //MARK: - 外部初始化方法 77 | static func ds_showActionSheetWithStyle(style style:DSCustomActionSheetStyle, 78 | contentArray:[String]!, 79 | imageArray:[UIImage]!, 80 | redIndex:Int, 81 | title:String?, 82 | ButtonActionBlock:(Int) -> Void) { 83 | 84 | let actionSheet = DSActionSheet.shareActionSheet() 85 | 86 | actionSheet.dataArray = contentArray 87 | actionSheet.viewStyle = style 88 | actionSheet.imageArray = imageArray 89 | actionSheet.specialIndex = redIndex 90 | actionSheet.headerTitle = title 91 | actionSheet.callback = ButtonActionBlock 92 | 93 | actionSheet.tableView.reloadData() 94 | actionSheet.show() 95 | } 96 | 97 | //MARK: - UITableViewDataSource 98 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 99 | return 2 100 | } 101 | 102 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 103 | if 0 == section 104 | { 105 | if (viewStyle == .DSCustomActionSheetStyleNormal || viewStyle == .DSCustomActionSheetStyleImage) 106 | { 107 | return dataArray.count 108 | } 109 | else 110 | { 111 | return dataArray.count + 1 112 | } 113 | } 114 | else 115 | { 116 | return 1 117 | } 118 | } 119 | 120 | func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 121 | return 0.1 122 | } 123 | 124 | func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 125 | return ( 0 == section ) ? 8.0 : 0.1 126 | } 127 | 128 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 129 | let cell = tableView.dequeueReusableCellWithIdentifier(DSASCellIdentifier, forIndexPath: indexPath) as! DSTableCell 130 | 131 | cell.selectionStyle = ( headerTitle != nil && 0 == indexPath.row ) ? UITableViewCellSelectionStyle.None : UITableViewCellSelectionStyle.Default 132 | 133 | if 0 == indexPath.section 134 | { 135 | if indexPath.row == specialIndex 136 | { 137 | cell.customTextLabel.textColor = UIColor.redColor() 138 | } 139 | 140 | if viewStyle == .DSCustomActionSheetStyleNormal 141 | { 142 | cell.customTextLabel.text = dataArray[indexPath.row] 143 | } 144 | else if viewStyle == .DSCustomActionSheetStyleTitle 145 | { 146 | cell.customTextLabel.text = ( 0 == indexPath.row ) ? headerTitle : dataArray[indexPath.row-1] 147 | } 148 | else 149 | { 150 | 151 | let index : Int = ( headerTitle == nil ) ? indexPath.row : indexPath.row - 1 152 | 153 | if index >= 0 154 | { 155 | cell.customImageView.image = imageArray![index] 156 | } 157 | 158 | cell.customTextLabel.text = ( 0 == indexPath.row ) ? headerTitle : dataArray[indexPath.row-1] 159 | } 160 | } 161 | else 162 | { 163 | cell.customTextLabel.text = "取 消" 164 | } 165 | 166 | return cell 167 | } 168 | 169 | //MARK: - UITableViewDelegate 170 | func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 171 | if 0 == indexPath.section 172 | { 173 | var index : Int = 0 174 | if ( viewStyle == .DSCustomActionSheetStyleNormal || viewStyle == .DSCustomActionSheetStyleImage ) 175 | { 176 | index = indexPath.row 177 | } 178 | else 179 | { 180 | index = indexPath.row - 1 181 | } 182 | if ( -1 == index ) 183 | { 184 | print("【 DSActionSheet 】标题不能点击!") 185 | return 186 | } 187 | self.callback(index) 188 | } 189 | else if ( 1 == indexPath.section ) 190 | { 191 | print("【 DSActionSheet 】你点击了取消按钮!") 192 | self.dismiss() 193 | } 194 | 195 | tableView.deselectRowAtIndexPath(indexPath, animated: true) 196 | } 197 | 198 | //MARK: - UpdateFrame 199 | override func layoutSubviews() { 200 | super.layoutSubviews() 201 | 202 | //这里因为转屏了要重新赋值 203 | // viewWidth = UIScreen.mainScreen().applicationFrame.size.width 204 | // 205 | // viewHeight = UIScreen.mainScreen().applicationFrame.size.height 206 | 207 | let tableViewHeight : CGFloat = min(viewHeight - 64.0, self.tableView.contentSize.height) 208 | 209 | tableView.frame = CGRect(x: 0.0, y: 0.0, width: viewWidth, height: tableViewHeight) 210 | 211 | self.frame = CGRect(x: 0.0, y: viewHeight - tableViewHeight, width: viewWidth, height: tableViewHeight) 212 | } 213 | 214 | //MARK: - Animation 215 | 216 | func fadeIn() { 217 | 218 | let tableViewHeight : CGFloat = min(viewHeight - 64.0, self.tableView.contentSize.height) 219 | 220 | tableView.frame = CGRect(x: 0.0, y: 0.0, width: viewWidth, height: tableViewHeight) 221 | 222 | frame = CGRect(x: 0.0, y: viewHeight, width: viewWidth, height: tableViewHeight) 223 | 224 | UIView.animateWithDuration(0.25) { 225 | self.frame = CGRect(x: 0.0, y: self.viewHeight - tableViewHeight, width: self.viewWidth, height: tableViewHeight) 226 | } 227 | } 228 | 229 | func fadeOut() { 230 | UIView.animateWithDuration(0.25, animations: { 231 | self.frame = CGRect(x: 0.0, y: self.viewHeight, width: self.viewWidth, height: CGRectGetHeight(self.frame)) 232 | }) { (finished) in 233 | if finished 234 | { 235 | self.overlayControl.removeFromSuperview() 236 | for view in self.subviews { 237 | view.removeFromSuperview() 238 | } 239 | self.removeFromSuperview() 240 | } 241 | } 242 | } 243 | 244 | func show() { 245 | let keyWindow = UIApplication.sharedApplication().keyWindow 246 | keyWindow?.addSubview(overlayControl) 247 | keyWindow?.addSubview(self) 248 | self.fadeIn() 249 | } 250 | 251 | func dismiss() { 252 | print("【 DSActionSheet 】你触摸了背景隐藏!") 253 | self.fadeOut() 254 | } 255 | 256 | //MARK: - lazy 257 | lazy var tableView : UITableView = { 258 | let _tableView = UITableView(frame : CGRectZero , style: UITableViewStyle.Grouped) 259 | 260 | _tableView.delegate = self 261 | _tableView.dataSource = self 262 | _tableView.scrollEnabled = false 263 | _tableView.separatorStyle = UITableViewCellSeparatorStyle.None 264 | _tableView.backgroundColor = UIColor(white: 0.9, alpha: 1.0) 265 | 266 | self.addSubview(_tableView) 267 | 268 | _tableView.registerNib(UINib.init(nibName: DSASCellIdentifier, bundle: nil), forCellReuseIdentifier: DSASCellIdentifier) 269 | 270 | let autoresizing : UIViewAutoresizing = [.FlexibleBottomMargin , .FlexibleLeftMargin , .FlexibleRightMargin , .FlexibleWidth] 271 | _tableView.autoresizingMask = autoresizing 272 | 273 | return _tableView 274 | }() 275 | 276 | lazy var overlayControl : UIControl = { 277 | 278 | var _overlayControl = UIControl(frame: UIScreen.mainScreen().bounds) 279 | 280 | _overlayControl.backgroundColor = UIColor(colorLiteralRed: 0.0, green: 0.0, blue: 0.0, alpha: 0.35) 281 | 282 | let autoresizing : UIViewAutoresizing = [.FlexibleBottomMargin , .FlexibleLeftMargin , .FlexibleRightMargin , .FlexibleWidth, .FlexibleHeight] 283 | _overlayControl.autoresizingMask = autoresizing 284 | 285 | _overlayControl.addTarget(self, action: #selector(DSActionSheet.dismiss), forControlEvents: .TouchUpInside) 286 | 287 | return _overlayControl 288 | }() 289 | } 290 | -------------------------------------------------------------------------------- /DSAlert-Swift/DSActionSheet/DSTableCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DSTableCell.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/8/31. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | let DSASCellIdentifier : String = "DSTableCell" 12 | 13 | 14 | class DSTableCell: UITableViewCell { 15 | 16 | //MARK: - IBOutlet 17 | 18 | @IBOutlet weak var customImageView: UIImageView! 19 | @IBOutlet weak var customTextLabel: UILabel! 20 | 21 | override func awakeFromNib() { 22 | super.awakeFromNib() 23 | // Initialization code 24 | } 25 | 26 | override func setSelected(selected: Bool, animated: Bool) { 27 | super.setSelected(selected, animated: animated) 28 | 29 | // Configure the view for the selected state 30 | } 31 | 32 | override func drawRect(rect: CGRect) { 33 | super.drawRect(rect) 34 | 35 | let context = UIGraphicsGetCurrentContext() 36 | 37 | CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor) 38 | 39 | CGContextFillRect(context, rect) 40 | 41 | //下分割线 42 | CGContextSetStrokeColorWithColor(context, UIColor(white: 0.8, alpha: 1).CGColor) 43 | CGContextStrokeRect(context, CGRect(x: 0.0, y: CGRectGetHeight(rect), width: CGRectGetWidth(rect), height: 0.25)) 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /DSAlert-Swift/DSActionSheet/DSTableCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /DSAlert-Swift/DSAlert/DSAlert.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DSAlert.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/8/31. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /*! 背景高斯模糊枚举 默认:1 */ 12 | enum DSAlertBlurEffectStyle : Int { 13 | /*! 较亮的白色模糊 */ 14 | case DSAlertBlurEffectStyleExtraLight = 1 15 | /*! 一般亮的白色模糊 */ 16 | case DSAlertBlurEffectStyleLight 17 | /*! 深色背景模糊 */ 18 | case DSAlertBlurEffectStyleDark 19 | /*! 背景不处理 */ 20 | case DSAlertBlurEffectStyleNone 21 | } 22 | 23 | /*! 进出场动画枚举 默认:1 */ 24 | enum DSAlertAnimatingStyle : Int { 25 | /*! 缩放显示动画 */ 26 | case DSAlertAnimatingStyleScale = 1 27 | /*! 晃动动画 */ 28 | case DSAlertAnimatingStyleShake 29 | /*! 天上掉下动画 / 上升动画 */ 30 | case DSAlertAnimatingStyleFall 31 | } 32 | 33 | private struct Property { 34 | var subView = UIView?() 35 | 36 | var title = String?() 37 | 38 | var message = String?() 39 | 40 | var image = UIImage?() 41 | 42 | var buttonTitles : [String]? = { 43 | var _buttonTitles = [String]() 44 | return _buttonTitles 45 | }() 46 | 47 | var containerView = UIImageView?() 48 | 49 | var scrollView = UIScrollView?() 50 | 51 | var titleLabel = UILabel?() 52 | 53 | var imageView = UIImageView?() 54 | 55 | var messageLabel = UILabel?() 56 | 57 | var buttons : [UIButton]? = { 58 | var _buttons = [UIButton]() 59 | return _buttons 60 | }() 61 | 62 | lazy var lines : [UIView]? = { 63 | var _lines = [UIView]() 64 | return _lines 65 | }() 66 | 67 | lazy var blurImageView : UIImageView = { 68 | var _blurImageView = UIImageView(frame: UIScreen.mainScreen().bounds) 69 | 70 | let autoresizing : UIViewAutoresizing = [.FlexibleWidth, .FlexibleHeight] 71 | _blurImageView.autoresizingMask = autoresizing 72 | _blurImageView.image = UIImage.screenShotImage() 73 | _blurImageView.contentMode = UIViewContentMode.ScaleAspectFit 74 | _blurImageView.clipsToBounds = true 75 | _blurImageView.backgroundColor = UIColor.clearColor() 76 | 77 | return _blurImageView 78 | }() 79 | 80 | var viewWidth : CGFloat { 81 | get { 82 | return CGRectGetWidth(UIScreen.mainScreen().bounds) 83 | } 84 | set { 85 | self.viewWidth = newValue 86 | } 87 | } 88 | 89 | var viewHeight : CGFloat { 90 | get { 91 | return CGRectGetHeight(UIScreen.mainScreen().bounds) 92 | } 93 | set { 94 | self.viewHeight = newValue 95 | } 96 | } 97 | 98 | var kDSAlertWidth : CGFloat { 99 | get { 100 | return self.viewWidth - 50.0 101 | } 102 | } 103 | 104 | var kDSAlertPaddingV : CGFloat { 105 | get { 106 | return 11.0 107 | } 108 | } 109 | 110 | var kDSAlertPaddingH : CGFloat { 111 | get { 112 | return 18.0 113 | } 114 | } 115 | 116 | var kDSAlertRadius : CGFloat { 117 | get { 118 | return 13.0 119 | } 120 | } 121 | 122 | var kDSAlertButtonHeight : CGFloat { 123 | get { 124 | return 40.0 125 | } 126 | } 127 | 128 | var _scrollBottom : CGFloat = 0.0 129 | 130 | var _buttonsHeight : CGFloat = 0.0 131 | 132 | var _maxContentWidth : CGFloat = 0.0 133 | 134 | var _maxAlertViewHeight : CGFloat = 0.0 135 | 136 | var DS_COLOR:(CGFloat, CGFloat, CGFloat, CGFloat) -> UIColor = { 137 | return UIColor(red: $0/255.0, green: $1/255.0, blue: $2/255.0, alpha: $3) 138 | } 139 | 140 | init () { 141 | 142 | } 143 | } 144 | 145 | class DSAlert: UIView { 146 | 147 | //MARK: - Property 148 | /*! 按钮字体颜色 默认:白色*/ 149 | var buttonTitleColor = UIColor?() 150 | 151 | /*! 是否开启边缘触摸隐藏 alert 默认:false */ 152 | var isTouchEdgeHide : Bool = false 153 | 154 | var bgColor : UIColor? = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 0.3) 155 | 156 | /*! 背景图片名字 默认:没有图片*/ 157 | var bgImageName : String? { 158 | willSet { 159 | if newValue == nil { 160 | property!.containerView?.backgroundColor = UIColor.whiteColor() 161 | property!.scrollView!.backgroundColor = UIColor.whiteColor() 162 | property!.containerView?.image = nil 163 | }else { 164 | property!.containerView?.backgroundColor = UIColor.clearColor() 165 | property!.scrollView!.backgroundColor = UIColor.clearColor() 166 | property!.containerView?.image = UIImage(named: newValue!) 167 | property!.containerView?.contentMode = .ScaleAspectFill 168 | } 169 | } 170 | } 171 | 172 | /*! 是否开启进出场动画 默认:false,如果 true ,并且同步设置进出场动画枚举为默认值:1 */ 173 | var showAnimate : Bool = false 174 | 175 | /*! 进出场动画枚举 默认:1 ,并且默认开启动画开关 */ 176 | var animatingStyle : DSAlertAnimatingStyle? = .DSAlertAnimatingStyleScale 177 | 178 | /* 动画时间,默认为0.35秒 */ 179 | var animationDuration : NSTimeInterval = 0.35 180 | 181 | /*! 182 | * 按钮点击事件回调 183 | */ 184 | var buttonActionBlock : ((index : Int) -> ())? 185 | /* 是否在执行动画 */ 186 | var animating : Bool = false 187 | 188 | /*! 背景高斯模糊枚举 默认:1 */ 189 | var blurEffectStyle : DSAlertBlurEffectStyle? { 190 | 191 | //重写set方法 192 | didSet { 193 | 194 | if (self.blurEffectStyle != nil) { 195 | if blurEffectStyle == .DSAlertBlurEffectStyleLight 196 | { 197 | property!.blurImageView.image = property!.blurImageView.image?.DSAlert_ApplyLightEffect() 198 | } 199 | else if blurEffectStyle == .DSAlertBlurEffectStyleExtraLight 200 | { 201 | property!.blurImageView.image = property!.blurImageView.image?.DSAlert_ApplyExtraLightEffect() 202 | } 203 | else if blurEffectStyle == .DSAlertBlurEffectStyleDark 204 | { 205 | property!.blurImageView.image = property!.blurImageView.image?.DSAlert_ApplyDarkEffect() 206 | }else if blurEffectStyle == .DSAlertBlurEffectStyleNone 207 | { 208 | // property!.blurImageView.image = nil 209 | } 210 | } 211 | else 212 | { 213 | self.blurEffectStyle = .DSAlertBlurEffectStyleNone 214 | } 215 | } 216 | } 217 | 218 | //MARK: - ***** 初始化视图容器 219 | func loadUI() { 220 | property!.containerView = UIImageView() 221 | property!.containerView!.userInteractionEnabled = true 222 | property!.containerView!.layer.cornerRadius = property!.kDSAlertRadius 223 | property!.containerView!.layer.masksToBounds = true 224 | property!.containerView!.backgroundColor = UIColor.whiteColor() 225 | 226 | property!.scrollView = UIScrollView() 227 | property!.scrollView!.backgroundColor = UIColor.whiteColor() 228 | property!.containerView! .addSubview(property!.scrollView!) 229 | 230 | self.addSubview(property!.containerView!) 231 | self.setupCommonUI() 232 | } 233 | 234 | //MARK: - ***** 加载自定义View 235 | func setupUI() { 236 | frame = UIScreen.mainScreen().bounds 237 | backgroundColor = self.bgColor 238 | 239 | property!.subView!.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor 240 | property!.subView!.layer.shadowOffset = CGSizeZero 241 | property!.subView!.layer.shadowOpacity = 1 242 | property!.subView!.layer.shadowRadius = 10.0 243 | property!.subView!.layer.borderWidth = 0.5 244 | property!.subView!.layer.borderColor = property!.DS_COLOR(110, 115, 120, 1).CGColor 245 | 246 | self.addSubview(property!.subView!) 247 | self.setupCommonUI() 248 | } 249 | 250 | //MARK: - ***** 公共方法 251 | func setupCommonUI() { 252 | blurEffectStyle = .DSAlertBlurEffectStyleNone 253 | 254 | self.addGestureRecognizer(dismissTap!) 255 | } 256 | 257 | //MARK: - 1、高度封装一行即可完全配置alert,如不习惯,可使用第二种常用方法 258 | /*! 259 | * 创建一个完全自定义的 alertView 260 | * 261 | * @param customView 自定义 View 262 | * @param configuration 属性配置:如 bgColor、buttonTitleColor、isTouchEdgeHide... 263 | */ 264 | static func ds_showCustomView(customView customView : UIView, configuration : DSAlert ->Void ) { 265 | let temp = DSAlert.initWithCustomView(customView) 266 | configuration(temp) 267 | temp.ds_showAlertView() 268 | } 269 | 270 | /*! 271 | * 创建一个类似于系统的alert 272 | * 273 | * @param title 标题:可空 274 | * @param message 消息内容:可空 275 | * @param image 图片:可空 276 | * @param buttonTitles 按钮标题:不可空 277 | * @param configuration 属性配置:如 bgColor、buttonTitleColor、isTouchEdgeHide... 278 | * @param action 按钮的点击事件处理 279 | */ 280 | static func ds_showAlertWithTitle(title title : String, message : String, image : UIImage?, buttonTitles : [String], configuration : DSAlert -> Void, action : Int -> Void) { 281 | 282 | let temp = DSAlert.ds_showTitle(title: title, message: message, image: image, buttonTitles: buttonTitles) 283 | 284 | configuration(temp) 285 | 286 | temp.ds_showAlertView() 287 | 288 | temp.buttonActionBlock = action; 289 | } 290 | 291 | //MARK: - 2、常用方法 292 | /*! 293 | * 初始化自定义动画视图 294 | * @return instancetype 295 | */ 296 | static func initWithCustomView(customView : UIView) -> DSAlert { 297 | let view = DSAlert() 298 | 299 | view.property!.subView = customView 300 | 301 | view.setupUI() 302 | 303 | return view 304 | } 305 | 306 | /*! 307 | * 创建一个类似系统的警告框 308 | * 309 | * @param title title 310 | * @param message message 311 | * @param image image 312 | * @param buttonTitles 按钮的标题 313 | * 314 | * @return 创建一个类似系统的警告框 315 | */ 316 | static func ds_showTitle(title title : String,message : String, image : UIImage?, buttonTitles : [String]?) -> DSAlert { 317 | 318 | let view = DSAlert() 319 | view.frame = CGRect(x: 0, y: 0, width: (view.property?.kDSAlertWidth)!, height: 0) 320 | view.property!.title = title 321 | view.property!.image = image 322 | view.property!.message = message 323 | view.property!.buttonTitles = buttonTitles 324 | 325 | NSNotificationCenter.defaultCenter().addObserver(view, selector: #selector(view.changeFrames(_:)), name: UIDeviceOrientationDidChangeNotification, object: nil) 326 | 327 | view.loadUI() 328 | return view 329 | } 330 | 331 | //MARK: - **** 视图显示方法 332 | func ds_showAlertView() { 333 | let keyWindow = UIApplication.sharedApplication().keyWindow 334 | if blurEffectStyle != .DSAlertBlurEffectStyleNone { 335 | keyWindow?.addSubview(property!.blurImageView) 336 | } 337 | 338 | keyWindow?.addSubview(self) 339 | 340 | self.layoutMySubViews() 341 | 342 | if showAnimate { 343 | animatingStyle = .DSAlertAnimatingStyleScale 344 | } 345 | else if !showAnimate 346 | { 347 | showAnimate = true 348 | } 349 | else 350 | { 351 | print("您没有开启动画,也没有设置动画样式,默认为没有动画!") 352 | } 353 | 354 | if showAnimate { 355 | if property!.subView != nil { 356 | self.showAnimationWithView(property!.subView) 357 | } 358 | else if property!.containerView != nil 359 | { 360 | self.showAnimationWithView(property!.containerView!) 361 | } 362 | } 363 | else 364 | { 365 | if property!.subView != nil { 366 | property!.subView?.center = (window?.center)! 367 | } 368 | else if property!.containerView != nil 369 | { 370 | self.prepareForShow() 371 | property!.containerView?.center = (window?.center)! 372 | } 373 | } 374 | } 375 | 376 | 377 | 378 | //MARK: - **** 视图消失 379 | func ds_dismissAlertView() { 380 | if showAnimate { 381 | if property!.subView != nil { 382 | self.dismissAnimationView(property!.subView!) 383 | } 384 | else if property!.containerView != nil 385 | { 386 | self.dismissAnimationView(property!.containerView!) 387 | } 388 | } 389 | else 390 | { 391 | self.removeSelf() 392 | animating = false 393 | } 394 | } 395 | 396 | //MARK: - **** 进场动画 397 | func showAnimationWithView(animationView : UIView?) { 398 | animating = true 399 | if animatingStyle == .DSAlertAnimatingStyleScale 400 | { 401 | animationView!.scaleAnimationShowFinishAnimation({ () in 402 | self.animating = false 403 | }) 404 | } 405 | else if animatingStyle == .DSAlertAnimatingStyleShake 406 | { 407 | if animationDuration == 0 { 408 | animationDuration = 1.0 409 | } 410 | animationView?.layer.shakeAnimationWithDuration(duration: animationDuration, 411 | radius: 16.0, 412 | repeatCount: 1.0, 413 | finish: { () in 414 | self.animating = false 415 | }) 416 | } 417 | else if animatingStyle == .DSAlertAnimatingStyleFall 418 | { 419 | if animationDuration == 0 { 420 | animationDuration = 0.35 421 | } 422 | animationView?.layer.fallAnimationWithDuration(duration: animationDuration, 423 | finish: { () in 424 | self.animating = false 425 | }) 426 | } 427 | } 428 | 429 | //MARK: - **** 出场动画 430 | func dismissAnimationView(animationView : UIView?) { 431 | animating = true 432 | if animatingStyle == .DSAlertAnimatingStyleScale 433 | { 434 | animationView!.scaleAnimationDismissFinishAnimation({ () in 435 | self.removeSelf() 436 | self.animating = false 437 | }) 438 | } 439 | else if animatingStyle == .DSAlertAnimatingStyleShake 440 | { 441 | if animationDuration == 0 { 442 | animationDuration = 1.0 443 | } 444 | animationView?.layer.floatAnimationWithDuration(duration: animationDuration, 445 | finish: { () in 446 | self.removeSelf() 447 | self.animating = false 448 | }) 449 | } 450 | else if animatingStyle == .DSAlertAnimatingStyleFall 451 | { 452 | if animationDuration == 0 { 453 | animationDuration = 0.35 454 | } 455 | animationView?.layer.floatAnimationWithDuration(duration: animationDuration, finish: { () in 456 | self.removeSelf() 457 | self.animating = false 458 | }) 459 | } 460 | else 461 | { 462 | print("您没有选择出场动画样式:animatingStyle,默认为没有动画样式!") 463 | self.removeSelf() 464 | animating = false 465 | } 466 | } 467 | 468 | //MAKR: - ***** 设置UI 469 | func prepareForShow() { 470 | self.resetViews() 471 | property!._scrollBottom = 0.0 472 | 473 | let insetY : CGFloat = property!.kDSAlertPaddingV 474 | property!._maxContentWidth = property!.kDSAlertWidth - 2 * property!.kDSAlertPaddingH 475 | property!._maxAlertViewHeight = property!.viewHeight - 50 476 | 477 | self.loadTitle() 478 | self.loadImage() 479 | self.loadMessage() 480 | 481 | property!._buttonsHeight = property!.kDSAlertButtonHeight * CGFloat( ((property!.buttonTitles?.count)! > 2 || property!.buttonTitles?.count == 0) ? (property!.buttonTitles?.count)! : 1) 482 | 483 | frame = (window?.bounds)! 484 | backgroundColor = bgColor 485 | 486 | let containViewHeight : CGFloat = min(max(property!._scrollBottom + 2 * insetY + property!._buttonsHeight, 2 * property!.kDSAlertRadius + property!.kDSAlertPaddingV), property!._maxAlertViewHeight) 487 | property!.containerView?.frame = CGRect(x: 0.0, y: 0.0, width: property!.kDSAlertWidth, height: containViewHeight) 488 | 489 | let scrollView = min(property!._scrollBottom, CGRectGetHeight(property!.containerView!.frame) - 2 * insetY - property!._buttonsHeight) 490 | property!.scrollView!.frame = CGRect(x: 0.0, y: insetY, width: CGRectGetWidth(property!.containerView!.frame), height: scrollView) 491 | property!.scrollView!.contentSize = CGSize(width: property!._maxContentWidth, height: property!._scrollBottom) 492 | 493 | self.loadButtons() 494 | 495 | } 496 | 497 | //MARK: - **** 重置subviews 498 | func resetViews() { 499 | if (property!.titleLabel != nil) { 500 | property!.titleLabel! .removeFromSuperview() 501 | property!.titleLabel = nil 502 | } 503 | 504 | if (property!.imageView != nil) { 505 | property!.imageView! .removeFromSuperview() 506 | property!.imageView = nil 507 | } 508 | 509 | if (property!.messageLabel != nil) { 510 | property!.messageLabel! .removeFromSuperview() 511 | property!.messageLabel = nil 512 | } 513 | 514 | if ( property!.buttons?.count > 0 ) { 515 | for subview in property!.buttons! { 516 | subview.removeFromSuperview() 517 | } 518 | property!.buttons!.removeAll() 519 | } 520 | 521 | if (property!.lines != nil) { 522 | for subview in property!.lines! { 523 | subview.removeFromSuperview() 524 | } 525 | property!.lines!.removeAll() 526 | } 527 | } 528 | 529 | //MARK: - 初始化标题 530 | func loadTitle() { 531 | if property!.title == nil { 532 | return 533 | } 534 | if property!.titleLabel == nil { 535 | let titleLabel = UILabel() 536 | titleLabel.textColor = UIColor.blackColor() 537 | titleLabel.font = UIFont(name: "FontNameAmericanTypewriterBold", size: 20.0) 538 | titleLabel.textAlignment = .Center 539 | titleLabel.numberOfLines = 0 540 | 541 | property!.titleLabel = titleLabel 542 | } 543 | property!.titleLabel?.text = property!.title 544 | self.addLabel(property!.titleLabel!, maxHeight: 100) 545 | self.addLine(CGRect(x: property!.kDSAlertPaddingH, y: property!._scrollBottom, width: property!._maxContentWidth, height: 0.5), view: property!.scrollView!) 546 | 547 | property!._scrollBottom += property!.kDSAlertPaddingV 548 | } 549 | 550 | //MARK: - 初始化图片 551 | func loadImage() { 552 | if property!.image == nil { 553 | return 554 | } 555 | if property!.imageView == nil { 556 | 557 | property!.imageView = UIImageView() 558 | } 559 | property!.imageView?.image = property!.image 560 | 561 | var size : CGSize = (property!.image?.size)! 562 | 563 | if size.width > property!._maxContentWidth { 564 | size = CGSize(width: property!._maxContentWidth, height: size.height/size.width * property!._maxContentWidth) 565 | } 566 | 567 | property!.imageView?.frame = CGRect(x: property!.kDSAlertPaddingH + property!._maxContentWidth / 2 - size.width / 2, y: property!._scrollBottom, width: size.width, height: size.height) 568 | property!.scrollView!.addSubview(property!.imageView!) 569 | 570 | property!._scrollBottom = CGRectGetMaxY(property!.imageView!.frame) + property!.kDSAlertPaddingV 571 | } 572 | 573 | //MARK: - 初始化内容标签 574 | func loadMessage() { 575 | if ( property!.message == nil ) 576 | { 577 | return 578 | } 579 | if ( property!.messageLabel == nil ) 580 | { 581 | let _messageLabel : UILabel = UILabel() 582 | _messageLabel.textColor = UIColor.blackColor() 583 | _messageLabel.font = UIFont.systemFontOfSize(14.0) 584 | _messageLabel.textAlignment = .Center 585 | _messageLabel.numberOfLines = 0 586 | 587 | property!.messageLabel = _messageLabel 588 | } 589 | property!.messageLabel?.text = property!.message! 590 | 591 | self.addLabel(property!.messageLabel!, maxHeight: 100000.0) 592 | } 593 | 594 | //MARK: - 初始化按钮 595 | func loadButtons() { 596 | 597 | if (property!.buttonTitles == nil || (property!.buttonTitles?.isEmpty)! ) 598 | { 599 | return 600 | } 601 | let buttonHeight : CGFloat = property!.kDSAlertButtonHeight 602 | let buttonWidth : CGFloat = property!.kDSAlertWidth 603 | var top : CGFloat = CGRectGetHeight(property!.containerView!.frame)-property!._buttonsHeight 604 | 605 | self.addLine(CGRect(x: 0.0, y: top - 0.5, width: buttonWidth, height:0.5), view: property!.containerView!) 606 | 607 | if ( 1 == property!.buttonTitles!.count ) 608 | { 609 | self.addButton(CGRect(x: 0.0, y: top, width: buttonWidth, height: buttonHeight), title: (property!.buttonTitles?.first)!, tag: 0) 610 | } 611 | else if (2 == property!.buttonTitles!.count) 612 | { 613 | 614 | self.addButton(CGRect(x: 0.0, y: top, width: buttonWidth/2, height: buttonHeight), title: (property!.buttonTitles?.first)!, tag: 0) 615 | self.addButton(CGRect(x: 0 + buttonWidth / 2, y: top, width: buttonWidth/2, height: buttonHeight), title: (property!.buttonTitles?.last)!, tag: 1) 616 | self.addLine(CGRect(x: 0 + buttonWidth / 2 - 0.5, y: top, width: 0.5, height: buttonHeight), view: property!.containerView!) 617 | 618 | } 619 | else 620 | { 621 | for i in 0...property!.buttonTitles!.count { 622 | self.addButton(CGRect(x: 0.0, y: top, width: buttonWidth, height: buttonHeight), title: property!.buttonTitles![i], tag: i) 623 | 624 | top += buttonHeight 625 | 626 | if (property!.buttonTitles?.count)! - 1 != i { 627 | self.addLine(CGRect(x: 0.0, y: top, width: buttonWidth, height: 05), view: property!.containerView!) 628 | } 629 | } 630 | 631 | for view in property!.lines! { 632 | property!.containerView?.bringSubviewToFront(view) 633 | } 634 | } 635 | } 636 | 637 | //MARK: - 添加按钮方法 638 | func addButton(frame : CGRect, title : String, tag : Int) { 639 | 640 | if (property!.buttons == nil) { 641 | property!.buttons = [UIButton]() 642 | } 643 | 644 | let button : UIButton = UIButton() 645 | button.frame = frame 646 | button.setTitle(title, forState: .Normal) 647 | button.titleLabel?.font = UIFont.systemFontOfSize(17.0) 648 | button.tag = tag 649 | 650 | if ( buttonTitleColor != nil ) 651 | { 652 | button.setTitleColor(buttonTitleColor!, forState: .Normal) 653 | } 654 | else 655 | { 656 | button.setTitleColor(UIColor.blueColor(), forState: .Normal) 657 | } 658 | 659 | if ( bgImageName != nil ) 660 | { 661 | button.setBackgroundImage(UIImage.DSAlert_ImageWithColor(UIColor.clearColor()), forState: .Normal) 662 | button.setBackgroundImage(UIImage.DSAlert_ImageWithColor(property!.DS_COLOR(135, 140, 145, 0.45)), forState: .Highlighted) 663 | 664 | } 665 | else 666 | { 667 | button.setBackgroundImage(UIImage.DSAlert_ImageWithColor(UIColor.whiteColor()), forState: .Normal) 668 | button.setBackgroundImage(UIImage.DSAlert_ImageWithColor(property!.DS_COLOR(135, 140, 145, 0.45)), forState: .Highlighted) 669 | } 670 | button.addTarget(self, action: (#selector(self.buttonClicked(_:))), forControlEvents: .TouchUpInside) 671 | property!.containerView?.addSubview(button) 672 | property!.buttons?.append(button) 673 | 674 | } 675 | 676 | //MARK: - 添加标签方法 677 | func addLabel(label : UILabel, maxHeight : CGFloat) { 678 | let size : CGSize = label.sizeThatFits(CGSize(width: property!._maxContentWidth, height: maxHeight)) 679 | label.frame = CGRect(x: property!.kDSAlertPaddingH, y: property!._scrollBottom, width: property!._maxContentWidth, height: size.height) 680 | property!.scrollView!.addSubview(label) 681 | 682 | property!._scrollBottom = CGRectGetMaxY(label.frame) + property!.kDSAlertPaddingV 683 | } 684 | 685 | //MARK: - 添加底部横线方法 686 | func addLine(frame : CGRect, view : UIView) { 687 | let line : UIView = UIView(frame:frame) 688 | line.backgroundColor = property!.DS_COLOR(160, 170, 160, 1) 689 | view.addSubview(line) 690 | property!.lines?.append(line) 691 | } 692 | 693 | //MARK: - **** 清除所有视图 694 | func removeSelf() { 695 | print("【 \(self.classForCoder) 】已经释放!"); 696 | self.resetViews() 697 | 698 | if property!.subView == nil { 699 | for view in (property!.containerView?.subviews)! { 700 | view.removeFromSuperview() 701 | } 702 | }else { 703 | for view in (property!.subView?.subviews)! { 704 | view.removeFromSuperview() 705 | } 706 | property!.subView?.removeFromSuperview() 707 | } 708 | 709 | for view in subviews { 710 | view.removeFromSuperview() 711 | } 712 | self.removeFromSuperview() 713 | property!.blurImageView.removeFromSuperview() 714 | property = nil 715 | bgColor = nil 716 | animatingStyle = nil 717 | buttonActionBlock = nil 718 | blurEffectStyle = nil 719 | dismissTap = nil 720 | 721 | NSNotificationCenter.defaultCenter().removeObserver(self) 722 | } 723 | 724 | //MARK: - **** 更新frame 725 | func layoutMySubViews() { 726 | 727 | if (property!.subView != nil) { 728 | frame = CGRect(x: 0.0, y: 0.0, width: property!.viewWidth, height: property!.viewHeight) 729 | 730 | property!.subView!.frame = CGRect(x: 0.0, y: 0.0, width: property!.viewWidth - 100, height: CGRectGetHeight(property!.subView!.frame)) 731 | property!.subView!.center = CGPoint(x: property!.viewWidth / 2, y: property!.viewHeight / 2) 732 | } 733 | else 734 | { 735 | self.prepareForShow() 736 | property!.containerView?.center = CGPoint(x: property!.viewWidth / 2, y: property!.viewHeight / 2) 737 | } 738 | } 739 | 740 | override func layoutSubviews() { 741 | super.layoutSubviews() 742 | 743 | if !animating { 744 | self.layoutMySubViews() 745 | } 746 | } 747 | 748 | //MARK: - **** 手势消失方法 749 | func dismissTapAction(gesture : UITapGestureRecognizer) { 750 | print("触摸了边缘隐藏View!") 751 | 752 | if isTouchEdgeHide 753 | { 754 | self.ds_dismissAlertView() 755 | } 756 | else 757 | { 758 | print("触摸了View边缘,但您未开启触摸边缘隐藏方法,请设置 isTouchEdgeHide 属性为 true 后再使用!") 759 | } 760 | } 761 | 762 | //MARK: - **** 按钮事件 763 | func buttonClicked(button : UIButton) 764 | { 765 | self.ds_dismissAlertView() 766 | 767 | if (buttonActionBlock != nil) 768 | { 769 | buttonActionBlock!(index: button.tag) 770 | } 771 | } 772 | 773 | //MARK: - **** 转屏通知处理 774 | func changeFrames(notification : NSNotification) { 775 | 776 | property!.containerView?.layer.removeAllAnimations() 777 | animating = false 778 | self.layoutMySubViews() 779 | } 780 | 781 | //MARK: - **** lazy 782 | lazy var dismissTap : UITapGestureRecognizer? = { 783 | var _dismissTap = UITapGestureRecognizer(target: self, action: #selector(self.dismissTapAction(_:))) 784 | return _dismissTap 785 | }() 786 | 787 | lazy private var property : Property? = { 788 | var _property = Property() 789 | return _property 790 | }() 791 | } 792 | -------------------------------------------------------------------------------- /DSAlert-Swift/DSAlert/DSAlertImageEffects.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DSAlertImageEffects.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/9/1. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import Accelerate 12 | 13 | extension UIImage { 14 | func DSAlert_ApplyLightEffect() -> UIImage! { 15 | let tintColor = UIColor(white:0.3,alpha:0.4) 16 | return self.DSAlert_ApplyBlurWithRadius(blurRadius: 1.3, tintColor: tintColor, saturationDeltaFactor: 1.8, maskImage: nil) 17 | } 18 | 19 | func DSAlert_ApplyExtraLightEffect() -> UIImage! { 20 | let tintColor = UIColor(white:0.97,alpha:0.82) 21 | return self.DSAlert_ApplyBlurWithRadius(blurRadius: 2, tintColor: tintColor, saturationDeltaFactor: 1.8, maskImage: nil) 22 | } 23 | 24 | func DSAlert_ApplyDarkEffect() -> UIImage! { 25 | let tintColor = UIColor(white:0.11,alpha:0.73) 26 | return self.DSAlert_ApplyBlurWithRadius(blurRadius: 20, tintColor: tintColor, saturationDeltaFactor: 1.8, maskImage: nil) 27 | } 28 | 29 | func DSAlert_ApplyTintEffectWithColor(tintColor : UIColor) -> UIImage! { 30 | let EffectColorAlpha : CGFloat = 0.45 31 | var effectColor : UIColor = tintColor 32 | 33 | let componentCount = CGColorGetNumberOfComponents(tintColor.CGColor) 34 | 35 | if (componentCount == 2) { 36 | var b : CGFloat = 0.0 37 | if ( tintColor.getWhite(&b, alpha: nil) ) { 38 | effectColor = UIColor(white:b,alpha:EffectColorAlpha) 39 | } 40 | } 41 | else { 42 | var r : CGFloat = 0.0 43 | var g : CGFloat = 0.0 44 | var b : CGFloat = 0.0 45 | 46 | if ( tintColor.getRed(&r, green: &g, blue: &b, alpha: nil) ) { 47 | 48 | effectColor = UIColor(red: r, green: g, blue: b, alpha: EffectColorAlpha) 49 | 50 | } 51 | } 52 | return self.DSAlert_ApplyBlurWithRadius(blurRadius: 10, tintColor: effectColor, saturationDeltaFactor: -1.0, maskImage: nil) 53 | } 54 | 55 | func DSAlert_ApplyBlurWithRadius(blurRadius blurRadius : Float, tintColor : UIColor?, saturationDeltaFactor : Double, maskImage : UIImage?) -> UIImage! { 56 | // Check pre-conditions. 57 | if (self.size.width < 1 || self.size.height < 1) 58 | { 59 | print("*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@", self.size.width, self.size.height, self) 60 | return nil 61 | } 62 | if ( self.CGImage == nil ) 63 | { 64 | print("*** error: image must be backed by a CGImage: %@", self) 65 | return nil 66 | } 67 | if ( maskImage != nil && (maskImage!.CGImage == nil) ) 68 | { 69 | print("*** error: maskImage must be backed by a CGImage: %@", maskImage) 70 | return nil 71 | } 72 | 73 | let imageRect = CGRect(origin: CGPointZero, size: self.size) 74 | var effectImage : UIImage = self 75 | 76 | let hasBlur : Bool = blurRadius > FLT_EPSILON 77 | 78 | let hasSaturationChange : Bool = fabs(Float(saturationDeltaFactor) - 1.0) > FLT_EPSILON 79 | 80 | let screenScale = UIScreen.mainScreen().scale 81 | 82 | 83 | if ( hasBlur || hasSaturationChange ) { 84 | 85 | UIGraphicsBeginImageContextWithOptions(self.size, false, screenScale) 86 | let effectInContext : CGContextRef = UIGraphicsGetCurrentContext()! 87 | CGContextScaleCTM(effectInContext, 1.0, -1.0) 88 | CGContextTranslateCTM(effectInContext, 0, -self.size.height) 89 | CGContextDrawImage(effectInContext, imageRect, self.CGImage) 90 | 91 | var effectInBuffer = vImage_Buffer() 92 | effectInBuffer.data = CGBitmapContextGetData(effectInContext) 93 | effectInBuffer.width = vImagePixelCount(CGBitmapContextGetWidth(effectInContext)) 94 | effectInBuffer.height = vImagePixelCount(CGBitmapContextGetHeight(effectInContext)) 95 | effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext) 96 | 97 | UIGraphicsBeginImageContextWithOptions(self.size, false, screenScale) 98 | let effectOutContext : CGContextRef = UIGraphicsGetCurrentContext()! 99 | 100 | var effectOutBuffer = vImage_Buffer() 101 | effectOutBuffer.data = CGBitmapContextGetData(effectOutContext) 102 | effectOutBuffer.width = vImagePixelCount(CGBitmapContextGetWidth(effectOutContext)) 103 | effectOutBuffer.height = vImagePixelCount(CGBitmapContextGetHeight(effectOutContext)) 104 | effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext) 105 | 106 | if ( hasBlur ) { 107 | // A description of how to compute the box kernel width from the Gaussian 108 | // radius (aka standard deviation) appears in the SVG spec: 109 | // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement 110 | // 111 | // For larger values of 's' (s >= 2.0), an approximation can be used: Three 112 | // successive box-blurs build a piece-wise quadratic convolution kernel, which 113 | // approximates the Gaussian kernel to within roughly 3%. 114 | // 115 | // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) 116 | // 117 | // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. 118 | // 119 | let inputRadius : Double = Double(blurRadius) * Double(screenScale) 120 | 121 | var radius = floor(inputRadius * 3.0 * sqrt(2 * M_PI) / 4 + 0.5) 122 | 123 | if (radius % 2 != 1) { 124 | radius += 1 // force radius to be odd so that the three box-blur methodology works. 125 | } 126 | 127 | var unsafePointer : UInt8 = 0 128 | 129 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, UInt32(radius), UInt32(radius), &unsafePointer, UInt32(kvImageEdgeExtend)) 130 | vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, nil, 0, 0, UInt32(radius), UInt32(radius), &unsafePointer, UInt32(kvImageEdgeExtend)) 131 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, UInt32(radius), UInt32(radius), &unsafePointer, UInt32(kvImageEdgeExtend)) 132 | } 133 | 134 | var effectImageBuffersAreSwapped : Bool = false 135 | 136 | if ( hasSaturationChange ) { 137 | let s : Double = saturationDeltaFactor 138 | let floatingPointSaturationMatrix : [Double] = [ 139 | 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0, 140 | 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0, 141 | 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0, 142 | 0, 0, 0, 1, 143 | ] 144 | 145 | let divisor : Int32 = 256 146 | let matrixSize : Int = sizeofValue(floatingPointSaturationMatrix) / sizeofValue(floatingPointSaturationMatrix[0]) 147 | 148 | var saturationMatrix = [Int16]() 149 | 150 | for _ in 0...matrixSize { 151 | saturationMatrix.append(0) 152 | } 153 | 154 | for i in 0...matrixSize { 155 | saturationMatrix[i] = Int16(roundf(Float(floatingPointSaturationMatrix[i]) * Float(divisor))) 156 | } 157 | 158 | if (hasBlur) { 159 | vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, divisor, nil, nil, UInt32(kvImageNoFlags)) 160 | effectImageBuffersAreSwapped = true 161 | } 162 | else { 163 | vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, divisor, nil, nil, UInt32(kvImageNoFlags)) 164 | } 165 | } 166 | if ( !effectImageBuffersAreSwapped ) { 167 | effectImage = UIGraphicsGetImageFromCurrentImageContext() 168 | UIGraphicsEndImageContext() 169 | } 170 | 171 | if ( effectImageBuffersAreSwapped ) { 172 | effectImage = UIGraphicsGetImageFromCurrentImageContext() 173 | UIGraphicsEndImageContext() 174 | } 175 | } 176 | 177 | // 开启上下文 用于输出图像 178 | UIGraphicsBeginImageContextWithOptions(self.size, false, screenScale) 179 | let outputContext : CGContextRef = UIGraphicsGetCurrentContext()! 180 | CGContextScaleCTM(outputContext, 1.0, -1.0) 181 | CGContextTranslateCTM(outputContext, 0, -self.size.height) 182 | 183 | // 开始画底图 184 | CGContextDrawImage(outputContext, imageRect, self.CGImage) 185 | 186 | // 开始画模糊效果 187 | if (hasBlur) { 188 | CGContextSaveGState(outputContext) 189 | if ( (maskImage) != nil) { 190 | CGContextClipToMask(outputContext, imageRect, maskImage!.CGImage) 191 | } 192 | CGContextDrawImage(outputContext, imageRect, effectImage.CGImage) 193 | CGContextRestoreGState(outputContext) 194 | } 195 | 196 | // 添加颜色渲染 197 | if ( tintColor != nil ) { 198 | CGContextSaveGState(outputContext) 199 | CGContextSetFillColorWithColor(outputContext, tintColor!.CGColor) 200 | CGContextFillRect(outputContext, imageRect) 201 | CGContextRestoreGState(outputContext) 202 | } 203 | 204 | // 输出成品,并关闭上下文 205 | let outputImage : UIImage = UIGraphicsGetImageFromCurrentImageContext() 206 | UIGraphicsEndImageContext() 207 | 208 | return outputImage 209 | } 210 | 211 | //MARK: - 纯颜色转图片 212 | static func DSAlert_ImageWithColor(color : UIColor) -> UIImage! { 213 | return self.DSAlert_ImageWithColor(color, size: CGSize(width: 1.0, height: 1.0)) 214 | } 215 | 216 | static func DSAlert_ImageWithColor(color : UIColor, size : CGSize) -> UIImage! { 217 | let rect : CGRect = CGRect(origin: CGPointZero, size: size) 218 | UIGraphicsBeginImageContext(rect.size) 219 | let context : CGContextRef = UIGraphicsGetCurrentContext()! 220 | CGContextSetFillColorWithColor(context, color.CGColor) 221 | 222 | CGContextFillRect(context, rect) 223 | let image : UIImage = UIGraphicsGetImageFromCurrentImageContext() 224 | UIGraphicsEndImageContext() 225 | 226 | return image 227 | } 228 | 229 | static func screenShotImage() -> UIImage! { 230 | 231 | let window : UIWindow = UIApplication.sharedApplication().windows.first! 232 | 233 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGRectGetWidth(window.frame), CGRectGetHeight(window.frame)), true, 1.0); 234 | // 235 | // /*! 设置截屏大小 */ 236 | 237 | window.layer.renderInContext(UIGraphicsGetCurrentContext()!) 238 | let viewImage : UIImage = UIGraphicsGetImageFromCurrentImageContext() 239 | 240 | UIGraphicsEndImageContext() 241 | 242 | return viewImage 243 | } 244 | } -------------------------------------------------------------------------------- /DSAlert-Swift/DSAlert/MyAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MyAnimation.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/9/1. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension CALayer { 13 | /*! 14 | * 晃动动画 15 | * 16 | * @param duration 一次动画用时 17 | * @param radius 晃动角度0-180 18 | * @param repeatCount 重复次数 19 | * @param finish 动画完成 20 | */ 21 | func shakeAnimationWithDuration(duration duration:NSTimeInterval, radius : Double, repeatCount : Float, finish : (Void -> Void)?) { 22 | let keyAnimation = CAKeyframeAnimation() 23 | keyAnimation.duration = duration 24 | keyAnimation.keyPath = "transform.rotation.z" 25 | keyAnimation.values = [NSNumber.init(double: (0) / 180.0 * M_PI), 26 | NSNumber.init(double: (-radius) / 180.0 * M_PI), 27 | NSNumber.init(double: (radius) / 180.0 * M_PI), 28 | NSNumber.init(double: (-radius) / 180.0 * M_PI), 29 | NSNumber.init(double: (0) / 180.0 * M_PI)] 30 | keyAnimation.repeatCount = repeatCount 31 | self .addAnimation(keyAnimation, forKey: nil) 32 | 33 | if (finish != nil) { 34 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(repeatCount) * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 35 | finish!() 36 | }) 37 | } 38 | } 39 | 40 | /*! 41 | * 根据路径执行动画 42 | * 43 | * @param duration 一次动画用时 44 | * @param path 路径CGPathRef 45 | * @param repeat 重复次数 46 | * @param finish 动画完成 47 | */ 48 | func pathAnimationWithDuration(duration duration:NSTimeInterval, path : CGPathRef, repeatCount : Float, finish : (Void -> Void)?) { 49 | let keyAnimation = CAKeyframeAnimation() 50 | keyAnimation.duration = duration 51 | keyAnimation.keyPath = "position" 52 | keyAnimation.repeatCount = repeatCount 53 | keyAnimation.fillMode = kCAFillModeForwards 54 | self .addAnimation(keyAnimation, forKey: nil) 55 | 56 | if (finish != nil) { 57 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(duration * (Double(repeatCount) - 0.1) * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 58 | finish!() 59 | }) 60 | } 61 | } 62 | 63 | /*! 这两个动画只适合本项目 */ 64 | /*! 天上掉下 */ 65 | func fallAnimationWithDuration(duration duration:NSTimeInterval, finish : (Void -> Void)?) { 66 | let frame = UIScreen.mainScreen().bounds 67 | 68 | let center = CGPoint(x: CGRectGetWidth(frame) * 0.5, y: CGRectGetHeight(frame) * 0.5) 69 | 70 | let point = CGPoint(x: CGRectGetWidth(frame)*0.5, y: -(CGRectGetHeight(self.frame))) 71 | 72 | let path = UIBezierPath() 73 | 74 | path .moveToPoint(point) 75 | 76 | path.addLineToPoint(center) 77 | 78 | self.pathAnimationWithDuration(duration: duration, path: path.CGPath, repeatCount: 1.0) { () in 79 | if (finish != nil) 80 | { 81 | finish!() 82 | } 83 | } 84 | } 85 | 86 | /*! 上升 */ 87 | func floatAnimationWithDuration(duration duration:NSTimeInterval, finish : (Void -> Void)?) { 88 | let frame = UIScreen.mainScreen().bounds 89 | 90 | let center = CGPoint(x: CGRectGetWidth(frame) * 0.5, y: CGRectGetHeight(frame) * 0.5) 91 | 92 | let point = CGPoint(x: CGRectGetWidth(frame)*0.5, y: -(CGRectGetHeight(self.frame))) 93 | 94 | let path = UIBezierPath() 95 | 96 | path .moveToPoint(center) 97 | 98 | path.addLineToPoint(point) 99 | 100 | self.pathAnimationWithDuration(duration: duration, path: path.CGPath, repeatCount: 1.0) { () in 101 | if (finish != nil) 102 | { 103 | finish!() 104 | } 105 | } 106 | } 107 | 108 | } 109 | 110 | extension UIView { 111 | /** 112 | 缩放显示动画 113 | 114 | - parameter finish: 动画完成 115 | */ 116 | func scaleAnimationShowFinishAnimation(finish : (Void -> Void)?) { 117 | transform = CGAffineTransformMakeScale(0.001, 0.001) 118 | UIView.animateWithDuration(0.35, animations: { 119 | self.transform = CGAffineTransformMakeScale(1.18, 1.18) 120 | }) { (finished) in 121 | UIView.animateWithDuration(0.25, animations: { 122 | self.transform = CGAffineTransformMakeScale(1.0, 1.0) 123 | }, completion: { (finifhed) in 124 | if finished { 125 | finish!() 126 | } 127 | }) 128 | } 129 | } 130 | /** 131 | 缩放隐藏动画 132 | 133 | - parameter finish: 动画完成 134 | */ 135 | func scaleAnimationDismissFinishAnimation(finish : (Void -> Void)?) { 136 | UIView.animateWithDuration(0.15, animations: { 137 | self.transform = CGAffineTransformMakeScale(1.18, 1.18) 138 | }) { (finished) in 139 | UIView.animateWithDuration(0.25, animations: { 140 | self.transform = CGAffineTransformMakeScale(0.001, 0.001) 141 | }, completion: { (finifhed) in 142 | if finished { 143 | finish!() 144 | } 145 | }) 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /DSAlert-Swift/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 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /DSAlert-Swift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DSAlert-Swift 4 | // 5 | // Created by zeroLu on 16/8/31. 6 | // Copyright © 2016年 zeroLu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | let titleMsg1 = "欢迎使用 iPhone SE,迄今最高性能的 4 英寸 iPhone。在打造这款手机时,我们在深得人心的 4 英寸设计基础上,从里到外重新构想。它所采用的 A9 芯片,正是在 iPhone 6s 上使用的先进芯片。1200 万像素的摄像头能拍出令人叹为观止的精彩照片和 4K 视频,而 Live Photos 则会让你的照片栩栩如生。这一切,成就了一款外形小巧却异常强大的 iPhone。" 12 | 13 | let titleMsg2 = "对于 MacBook,我们给自己设定了一个几乎不可能实现的目标:在有史以来最为轻盈纤薄的 Mac 笔记本电脑上,打造全尺寸的使用体验。这就要求每个元素都必须重新构想,不仅令其更为纤薄轻巧,还要更加出色。最终我们带来的,不仅是一部新款的笔记本电脑,更是一种对笔记本电脑的前瞻性思考。现在,有了第六代 Intel 处理器、提升的图形处理性能、高速闪存和最长可达 10 小时的电池使用时间*,MacBook 的强大更进一步。" 14 | 15 | 16 | class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { 17 | 18 | //MARK: - IBOutlet - 19 | @IBOutlet weak var tableView: UITableView! 20 | 21 | var chooseBtn = UIButton?() 22 | var titleLabel = UILabel?() 23 | var alertView5 = DSAlert() 24 | 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | self.title = "DSAlert"; 30 | 31 | self.tableView.estimatedRowHeight = 44.0; 32 | self.tableView.rowHeight = UITableViewAutomaticDimension 33 | self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") 34 | } 35 | 36 | //MARK: - UITableViewDataSource 37 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 38 | return demoDataArray.count 39 | } 40 | 41 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 42 | let tempArray : Array = demoDataArray[section]; 43 | return tempArray.count 44 | } 45 | 46 | func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 47 | return (0 == section) ? 40 : 20; 48 | } 49 | 50 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 51 | let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 52 | cell.textLabel?.numberOfLines = 0; 53 | cell.accessoryType = (0 == indexPath.section) ? UITableViewCellAccessoryType.DisclosureIndicator: UITableViewCellAccessoryType.None 54 | cell.selectionStyle = (0 == indexPath.section) ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None 55 | 56 | let tempArray = demoDataArray[indexPath.section] 57 | cell.textLabel?.text = tempArray[indexPath.row] 58 | return cell; 59 | } 60 | 61 | //MARK: - UITableViewDelegate 62 | func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 63 | let headerView = UIView() 64 | 65 | let headerTitle = UILabel() 66 | headerTitle.font = UIFont.systemFontOfSize(13) 67 | headerTitle.textColor = UIColor.redColor() 68 | headerTitle.numberOfLines = 0; 69 | headerView.addSubview(headerTitle) 70 | 71 | if ( 0 == section) 72 | { 73 | headerTitle.frame = CGRectMake(20, 0, SCREENWIDTH - 40, 40); 74 | headerTitle.text = "alert 的几种日常用法,高斯模糊、炫酷动画,应有尽有!"; 75 | } 76 | else if (1 == section) 77 | { 78 | headerTitle.frame = CGRectMake(20, 0, SCREENWIDTH - 40, 20); 79 | headerTitle.text = "测试 ActionSheet,开发 ing 慎点!"; 80 | } 81 | 82 | return headerView 83 | } 84 | 85 | func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 86 | if 0 == indexPath.section 87 | { 88 | self.showAlert(indexPath.row) 89 | }else if 1 == indexPath.section 90 | { 91 | self.showActionSheet(indexPath.row) 92 | } 93 | 94 | tableView.deselectRowAtIndexPath(indexPath, animated: true) 95 | } 96 | 97 | //MARK: - ActionSheet点击事件 98 | func showActionSheet(index : Int) { 99 | switch index { 100 | case 0: 101 | DSActionSheet.ds_showActionSheetWithStyle(style: .DSCustomActionSheetStyleNormal, 102 | contentArray: ["测试1","测试2","测试3"], 103 | imageArray: nil, 104 | redIndex: 1, 105 | title: nil) 106 | { (index) in 107 | print("你点击了第 \(index) 行!") 108 | } 109 | case 1: 110 | DSActionSheet.ds_showActionSheetWithStyle(style: .DSCustomActionSheetStyleTitle, 111 | contentArray: ["测试1","测试2","测试3"], 112 | imageArray: nil, 113 | redIndex: 1, 114 | title: "测试带标题的ActionSheet增加长度~~~~~~~~~~~~~~~~~~~~~~~~~") 115 | { (index) in 116 | print("你点击了第 \(index) 行!") 117 | } 118 | case 2: 119 | DSActionSheet.ds_showActionSheetWithStyle(style: .DSCustomActionSheetStyleImageAndTitle, 120 | contentArray: ["测试1增加长度~~~~~~~~~~~~~~~~~~~~~~~~~","测试2","测试3"], 121 | imageArray: [UIImage.init(named: "123.png")!,UIImage.init(named: "背景.jpg")!,UIImage.init(named: "美女.jpg")!], 122 | redIndex: 1, 123 | title: "测试带标题的ActionSheet增加长度~~~~~~~~~~~~~~~~~~~~~~~~~!!") 124 | { (index) in 125 | print("你点击了第 \(index) 行!") 126 | } 127 | default: 128 | break 129 | } 130 | } 131 | 132 | //MARK: - Alert点击事件 133 | func showAlert(index : Int) { 134 | switch (index) { 135 | case 0: 136 | self.alert1() 137 | case 1: 138 | self.alert2() 139 | case 2: 140 | self.alert3() 141 | case 3: 142 | self.alert4() 143 | case 4: 144 | self.alert5() 145 | default: 146 | break 147 | } 148 | } 149 | 150 | func alert1() { 151 | 152 | var duration : NSTimeInterval = 0.0 153 | 154 | 155 | DSAlert.ds_showAlertWithTitle(title: "温馨提示:", message: titleMsg1, image: nil, buttonTitles: ["取消","确定"], configuration: { (temp) in 156 | // temp.bgColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0.3]; 157 | /*! 开启边缘触摸隐藏alertView */ 158 | temp.isTouchEdgeHide = true 159 | /*! 添加高斯模糊的样式 */ 160 | temp.blurEffectStyle = .DSAlertBlurEffectStyleLight 161 | /*! 开启动画 */ 162 | // temp.isShowAnimate = true; 163 | // /*! 进出场动画样式 默认为:DSAlertBlurEffectStyleNone */ 164 | duration = temp.animationDuration 165 | }) { (index) in 166 | if index == 0 167 | { 168 | print("点击了取消按钮!") 169 | /*! 隐藏alert */ 170 | // [weakSelf.alertView1 ds_dismissAlertView]; 171 | } 172 | else if (index == 1) 173 | { 174 | print("点击了确定按钮!"); 175 | 176 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(NSEC_PER_SEC))) 177 | dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in 178 | let vc2 : ViewController2 = ViewController2() 179 | vc2.title = "alert1"; 180 | self.navigationController?.pushViewController(vc2, animated: true) 181 | } 182 | } 183 | } 184 | } 185 | 186 | func alert2() { 187 | /*! 2、自定义按钮颜色 */ 188 | let alertView : DSAlert = DSAlert.ds_showTitle(title: "博爱温馨提示:", message: titleMsg2, image: nil, buttonTitles: ["取消", "跳转VC2"]) 189 | 190 | alertView.buttonTitleColor = UIColor.orangeColor(); 191 | alertView.bgColor = UIColor(red: 1.0, green: 1.0, blue: 0, alpha: 0.3) 192 | 193 | /*! 是否开启进出场动画 默认:false,如果 true ,并且同步设置进出场动画枚举为默认值:1 */ 194 | alertView.showAnimate = true 195 | 196 | /*! 显示alert */ 197 | alertView.ds_showAlertView() 198 | 199 | alertView.buttonActionBlock = { (index) -> Void in 200 | if index == 0 201 | { 202 | print("点击了取消按钮!") 203 | /*! 隐藏alert */ 204 | // [weakSelf.alertView1 ds_dismissAlertView]; 205 | } 206 | else if (index == 1) 207 | { 208 | print("点击了确定按钮!"); 209 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(alertView.animationDuration * Double(NSEC_PER_SEC))) 210 | dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in 211 | let vc2 : ViewController2 = ViewController2() 212 | vc2.title = "alert2"; 213 | self.navigationController?.pushViewController(vc2, animated: true) 214 | } 215 | } 216 | } 217 | } 218 | 219 | func alert3() { 220 | 221 | /*! 3、自定义背景图片 */ 222 | let alertView : DSAlert = DSAlert.ds_showTitle(title: "博爱温馨提示:", message: titleMsg1, image: nil, buttonTitles: ["取消", "确定"]) 223 | 224 | alertView.buttonTitleColor = UIColor.orangeColor() 225 | alertView.bgImageName = "背景.jpg" 226 | 227 | /*! 是否开启进出场动画 默认:false,如果 true ,并且同步设置进出场动画枚举为默认值:1 */ 228 | // alertView.showAnimate = true 229 | 230 | /*! 没有开启动画,直接进出场动画样式,默认开启动画 */ 231 | alertView.animatingStyle = .DSAlertAnimatingStyleShake 232 | 233 | /*! 显示alert */ 234 | alertView.ds_showAlertView() 235 | 236 | alertView.buttonActionBlock = { (index) -> Void in 237 | if index == 0 238 | { 239 | print("点击了取消按钮!") 240 | /*! 隐藏alert */ 241 | // [weakSelf.alertView1 ds_dismissAlertView]; 242 | } 243 | else if (index == 1) 244 | { 245 | print("点击了确定按钮!"); 246 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(alertView.animationDuration * Double(NSEC_PER_SEC))) 247 | dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in 248 | let vc2 : ViewController2 = ViewController2() 249 | vc2.title = "alert3"; 250 | self.navigationController?.pushViewController(vc2, animated: true) 251 | } 252 | } 253 | } 254 | } 255 | 256 | func alert4() { 257 | 258 | /*! 4、内置图片和文字,可滑动查看 */ 259 | let alertView : DSAlert = DSAlert.ds_showTitle(title: "博爱温馨提示:", message: titleMsg1, image: UIImage(named: "美女.jpg"), buttonTitles: ["取消", "跳转VC2"]) 260 | /*! 自定义按钮文字颜色 */ 261 | alertView.buttonTitleColor = UIColor.orangeColor() 262 | /*! 自定义alert的背景图片 */ 263 | alertView.bgImageName = "背景.jpg" 264 | /*! 是否开启进出场动画 */ 265 | alertView.showAnimate = true 266 | /*! 显示alert */ 267 | alertView.ds_showAlertView() 268 | 269 | alertView.buttonActionBlock = { (index) -> Void in 270 | if index == 0 271 | { 272 | print("点击了取消按钮!") 273 | /*! 隐藏alert */ 274 | // [weakSelf.alertView1 ds_dismissAlertView]; 275 | } 276 | else if (index == 1) 277 | { 278 | print("点击了确定按钮!"); 279 | 280 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(alertView.animationDuration * Double(NSEC_PER_SEC))) 281 | 282 | dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in 283 | let vc2 : ViewController2 = ViewController2() 284 | vc2.title = "alert4"; 285 | self.navigationController?.pushViewController(vc2, animated: true) 286 | } 287 | } 288 | } 289 | } 290 | 291 | func alert5() { 292 | 293 | let screenWidth = CGRectGetWidth(UIScreen.mainScreen().bounds) 294 | 295 | let view1 = UIView() 296 | view1.frame = CGRect(x: 30, y: 100, width: screenWidth - 60, height: 200) 297 | print(view1.frame) 298 | view1.backgroundColor = UIColor.yellowColor() 299 | view1.layer.masksToBounds = true 300 | view1.layer.cornerRadius = 10.0 301 | 302 | if titleLabel == nil { 303 | titleLabel = UILabel(frame : CGRect(x: 0, y: 0, width: CGRectGetWidth(view1.frame), height: 40)) 304 | titleLabel?.text = "测试title" 305 | titleLabel?.textAlignment = .Center 306 | titleLabel?.font = UIFont.systemFontOfSize(18) 307 | titleLabel?.backgroundColor = UIColor.greenColor() 308 | titleLabel?.autoresizingMask = UIViewAutoresizing([.FlexibleWidth]) 309 | view1.addSubview(titleLabel!) 310 | } 311 | 312 | 313 | if chooseBtn == nil { 314 | chooseBtn = UIButton(frame: CGRect(x: 0, y: CGRectGetHeight(view1.frame) - 40, width: CGRectGetWidth(view1.frame), height: 40)) 315 | chooseBtn?.setTitle("取消", forState: .Normal) 316 | chooseBtn?.backgroundColor = UIColor.redColor() 317 | chooseBtn?.setTitleColor(UIColor.whiteColor(), forState: .Normal) 318 | chooseBtn?.addTarget(self, action: #selector(self.cancleButtonAction(_:)), forControlEvents: .TouchUpInside) 319 | chooseBtn?.autoresizingMask = UIViewAutoresizing([.FlexibleWidth]) 320 | view1.addSubview(chooseBtn!) 321 | } 322 | 323 | 324 | alertView5 = DSAlert.initWithCustomView(view1) 325 | alertView5.showAnimate = true 326 | alertView5.ds_showAlertView() 327 | } 328 | 329 | func cancleButtonAction(sender: UIButton) { 330 | print("点击了取消按钮!") 331 | alertView5.ds_dismissAlertView() 332 | titleLabel = nil 333 | chooseBtn = nil 334 | } 335 | 336 | //MARK: - lazy 337 | lazy var demoDataArray:[[String]]! = { 338 | 339 | var result = [[String]]() 340 | 341 | result.append(["1、类似系统alert【加边缘手势消失】", 342 | "2、自定义按钮颜色", 343 | "3、自定义背景图片", 344 | "4、内置图片和文字,可滑动查看", 345 | "5、完全自定义alert"]) 346 | 347 | result.append(["6、actionsheet", 348 | "7、actionsheet带标题", 349 | "8、actionsheet带标题带图片"]) 350 | 351 | result.append(["DSAlert特点:\n1、手势触摸隐藏开关,可随时开关\n2、可以自定义背景图片、背景颜色、按钮颜色\n3、可以添加文字和图片,且可以滑动查看!\n4、横竖屏适配完美\n5、有各种炫酷动画展示你的alert\n6、理论完全兼容现有所有 iOS 系统版本"]) 352 | 353 | return result 354 | }() 355 | 356 | 357 | override func didReceiveMemoryWarning() { 358 | super.didReceiveMemoryWarning() 359 | // Dispose of any resources that can be recreated. 360 | } 361 | 362 | 363 | } 364 | 365 | -------------------------------------------------------------------------------- /DSAlert-Swift/ViewController2.swift: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @brief DSAlert-swift 4 | * 5 | * @author DS-Team 6 | * @copyright Copyright © 2016年 DS-Team. All rights reserved. 7 | * @version V1.0.0 8 | */ 9 | 10 | /* 11 | *************************** DSAlert 项目简介: ********************** 12 | 13 | 1、开发人员【DS-Team】: 14 | 孙博岩:[『https://github.com/boai』](https://github.com/boai)
15 | 陆晓峰:[『https://github.com/zeR0Lu』](https://github.com/zeR0Lu)
16 | 陈集 :[『https://github.com/chenjipdc』](https://github.com/chenjipdc) 17 | 2、项目源码地址: 18 | OC版 :https://github.com/DS-Team/DSAlert-OC 19 | swift版:https://github.com/DS-Team/DSAlert-swift 20 | 3、安装及使用方式: 21 | * 3.1、pod 导入【当前最新版本:1.0.0】: 22 | pod 'DSAlert' 23 | 导入头文件:#import 24 | * 3.2、下载demo,把 DSAlert 文件夹拖入项目即可, 25 | 导入头文件:#import "DSAlert.h" 26 | 4、如果开发中遇到特殊情况或者bug,请及时反馈给我们,谢谢! 27 | 5、也可以加入我们的大家庭:QQ群 【 479663605 】,希望广大小白和大神能够积极加入! 28 | 29 | */ 30 | 31 | 32 | import UIKit 33 | 34 | class ViewController2: UIViewController { 35 | 36 | override func viewDidLoad() { 37 | super.viewDidLoad() 38 | 39 | view.backgroundColor = UIColor.redColor() 40 | } 41 | 42 | override func didReceiveMemoryWarning() { 43 | super.didReceiveMemoryWarning() 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | 48 | /* 49 | // MARK: - Navigation 50 | 51 | // In a storyboard-based application, you will often want to do a little preparation before navigation 52 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 53 | // Get the new view controller using segue.destinationViewController. 54 | // Pass the selected object to the new view controller. 55 | } 56 | */ 57 | 58 | } 59 | -------------------------------------------------------------------------------- /DSAlert-Swift/美女.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift/美女.jpg -------------------------------------------------------------------------------- /DSAlert-Swift/背景.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DS-Team/DSAlert-Swift/f97fd7302c55dcd3d7bdafa88b57c9562be7a12c/DSAlert-Swift/背景.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 DS-Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #DSAlert 2 | 目前为止,最为精简的 alert 和 actionSheet 封装!DSAlert 让你的弹框不再孤单! 3 | 4 | --- 5 | 6 | ## 更新提示:【倒叙更新】 7 | 8 | #### version 1.0.0 9 | * 10、再次设计结构,新增frameWork静态库文件封装,喜欢简洁的你可以直接导入frameWork即可! 10 | * 9、多种炫酷入场、退出动画,让你的APP各种叼! 11 | * 8、新增高斯模糊,枚举选择,简单明了! 12 | * 7、新增是否开启边缘触摸隐藏 alert 默认:关闭,属性:isTouchEdgeHide,可自由开关边缘触摸! 13 | * 6、完美适配横竖屏 14 | * 5、简单的两行搞定一个自定义 alert 15 | * 4、手势触摸隐藏 16 | * 3、可以自定义背景图片、按钮颜色 17 | * 2、可以添加文字和图片,且可以滑动查看 18 | * 1、理论完全兼容目前所有 iOS 系统版本 19 | 20 | --- 21 | 22 | ## 0、安装和导入示例: 23 | * 0.1、使用方法1:pod 导入【当前最新版本:1.0.0】:
24 | ` pod 'DSAlert' `
25 | 导入头文件:
26 | ` #import ` 27 | * 0.2、使用方法2:下载demo,把 DSAlert 文件夹拖入项目即可,
28 | 导入头文件:
29 | ` #import "DSAlert.h" `
30 | 如果使用 DSActionSheet 需导入头文件:
31 | `#import "DSActionSheet.h"` 32 | * 0.3、使用方法3:frameWork ,把demo中的frameWork直接拖入项目即可
33 | `#import ` 34 | * 0.4、项目源码地址:
35 | OC版 :[https://github.com/DS-Team/DSAlert-OC](https://github.com/DS-Team/DSAlert-OC)
36 | swift 版:[https://github.com/DS-Team/DSAlert-swift](https://github.com/DS-Team/DSAlert-swift) 37 | 38 | #### 注:swift 版正在调试,稍后上传! 39 | 40 | --- 41 | 42 | ## 1、图片示例: 43 | 44 | ![DSAlert.gif](https://github.com/DS-Team/DSAlert-OC/blob/master/DSAlert.gif) 45 | 46 | --- 47 | 48 | ## 2、代码示例: 49 | * 2.1 类似系统 alert【加边缘手势消失】、高斯模糊背景 50 | 51 | ``` 52 | - (void)alert1 53 | { 54 | DSWeak; 55 | /*! 第一种封装使用示例 */ 56 | [DSAlert ds_showAlertWithTitle:@"温馨提示:" message:titleMsg1 image:nil buttonTitles:@[@"取消",@"确定"] configuration:^(DSAlert *temp) { 57 | 58 | // temp.bgColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0.3]; 59 | /*! 开启边缘触摸隐藏alertView */ 60 | temp.isTouchEdgeHide = YES; 61 | /*! 添加高斯模糊的样式 */ 62 | temp.blurEffectStyle = DSAlertBlurEffectStyleLight; 63 | /*! 开启动画 */ 64 | // temp.isShowAnimate = YES; 65 | // /*! 进出场动画样式 默认为:1 */ 66 | // temp.animatingStyle = 1; 67 | }actionClick:^(NSInteger index) { 68 | if (index == 0) 69 | { 70 | NSLog(@"点击了取消按钮!"); 71 | /*! 隐藏alert */ 72 | // [weakSelf.alertView1 ds_dismissAlertView]; 73 | } 74 | else if (index == 1) 75 | { 76 | NSLog(@"点击了确定按钮!"); 77 | ViewController2 *vc2 = [ViewController2 new]; 78 | vc2.title = @"alert1"; 79 | [weakSelf.navigationController pushViewController:vc2 animated:YES]; 80 | /*! 隐藏alert */ 81 | // [weakSelf.alertView1 ds_dismissAlertView]; 82 | } 83 | }]; 84 | } 85 | ``` 86 | 87 | * 2.2 自定义按钮颜色 88 | 89 | ``` 90 | - (void)alert2 91 | { 92 | /*! 2、自定义按钮颜色 */ 93 | _alertView2 = [[DSAlert alloc] ds_showTitle:@"温馨提示:" 94 | message:titleMsg2 95 | image:nil 96 | buttonTitles:@[@"取消", @"跳转VC2"]]; 97 | /*! 自定义按钮文字颜色 */ 98 | _alertView2.buttonTitleColor = [UIColor orangeColor]; 99 | _alertView2.bgColor = [UIColor colorWithRed:1.0 green:1.0 blue:0 alpha:0.3]; 100 | 101 | /*! 是否开启进出场动画 默认:NO,如果 YES ,并且同步设置进出场动画枚举为默认值:1 */ 102 | _alertView2.showAnimate = YES; 103 | 104 | /*! 显示alert */ 105 | [_alertView2 ds_showAlertView]; 106 | DSWeak; 107 | _alertView2.buttonActionBlock = ^(NSInteger index){ 108 | if (index == 0) 109 | { 110 | NSLog(@"点击了取消按钮!"); 111 | /*! 隐藏alert */ 112 | [weakSelf.alertView2 ds_dismissAlertView]; 113 | } 114 | else if (index == 1) 115 | { 116 | NSLog(@"点击了确定按钮!"); 117 | ViewController2 *vc2 = [ViewController2 new]; 118 | vc2.title = @"alert2"; 119 | [weakSelf.navigationController pushViewController:vc2 animated:YES]; 120 | /*! 隐藏alert */ 121 | // [weakSelf.alertView2 ds_dismissAlertView]; 122 | } 123 | }; 124 | } 125 | ``` 126 | 127 | * 2.3 自定义背景图片 128 | 129 | ``` 130 | - (void)alert3 131 | { 132 | /*! 3、自定义背景图片 */ 133 | _alertView3 = [[DSAlert alloc] ds_showTitle:@"温馨提示:" 134 | message:titleMsg1 135 | image:nil 136 | buttonTitles:@[@"取消", @"确定"]]; 137 | /*! 自定义按钮文字颜色 */ 138 | _alertView3.buttonTitleColor = [UIColor orangeColor]; 139 | /*! 自定义alert的背景图片 */ 140 | _alertView3.bgImageName = @"背景.jpg"; 141 | /*! 开启动画,并且设置动画样式,默认:1 */ 142 | // _alertView3.isShowAnimate = YES; 143 | 144 | /*! 没有开启动画,直接进出场动画样式,默认开启动画 */ 145 | _alertView3.animatingStyle = DSAlertAnimatingStyleFall; 146 | 147 | /*! 显示alert */ 148 | [_alertView3 ds_showAlertView]; 149 | DSWeak; 150 | _alertView3.buttonActionBlock = ^(NSInteger index){ 151 | if (index == 0) 152 | { 153 | NSLog(@"点击了取消按钮!"); 154 | /*! 隐藏alert */ 155 | // [weakSelf.alertView3 ds_dismissAlertView]; 156 | } 157 | else if (index == 1) 158 | { 159 | NSLog(@"点击了确定按钮!"); 160 | ViewController2 *vc2 = [ViewController2 new]; 161 | vc2.title = @"alert3"; 162 | [weakSelf.navigationController pushViewController:vc2 animated:YES]; 163 | /*! 隐藏alert */ 164 | // [weakSelf.alertView3 ds_dismissAlertView]; 165 | } 166 | }; 167 | } 168 | ``` 169 | 170 | * 2.4 内置图片和文字,可滑动查看 171 | 172 | ``` 173 | - (void)alert4 174 | { 175 | /*! 4、内置图片和文字,可滑动查看 */ 176 | _alertView4 = [[DSAlert alloc] ds_showTitle:@"温馨提示:" 177 | message:titleMsg1 178 | image:[UIImage imageNamed:@"美女.jpg"] 179 | buttonTitles:@[@"取消", @"跳转VC2"]]; 180 | /*! 自定义按钮文字颜色 */ 181 | _alertView4.buttonTitleColor = [UIColor orangeColor]; 182 | /*! 自定义alert的背景图片 */ 183 | _alertView4.bgImageName = @"背景.jpg"; 184 | /*! 是否显示动画效果 */ 185 | _alertView4.showAnimate = YES; 186 | /*! 显示alert */ 187 | [_alertView4 ds_showAlertView]; 188 | DSWeak; 189 | _alertView4.buttonActionBlock = ^(NSInteger index){ 190 | if (index == 0) 191 | { 192 | NSLog(@"点击了取消按钮!"); 193 | /*! 隐藏alert */ 194 | // [weakSelf.alertView4 ds_dismissAlertView]; 195 | } 196 | else if (index == 1) 197 | { 198 | NSLog(@"点击了确定按钮!"); 199 | ViewController2 *vc2 = [ViewController2 new]; 200 | vc2.title = @"alert4"; 201 | [weakSelf.navigationController pushViewController:vc2 animated:YES]; 202 | /*! 隐藏alert */ 203 | // [weakSelf.alertView4 ds_dismissAlertView]; 204 | } 205 | }; 206 | } 207 | ``` 208 | 209 | * 2.5 完全自定义alert 210 | 211 | ``` 212 | - (void)alert5 213 | { 214 | /*! 5、完全自定义alert */ 215 | UIView *view1 = [UIView new]; 216 | view1.frame = CGRectMake(30, 100, SCREENWIDTH - 60, 200); 217 | view1.backgroundColor = [UIColor yellowColor]; 218 | view1.layer.masksToBounds = YES; 219 | view1.layer.cornerRadius = 10.0f; 220 | // view1.clipsToBounds = YES; 221 | 222 | _titleLabel = [UILabel new]; 223 | _titleLabel.frame = CGRectMake(0, 0, view1.frame.size.width, 40); 224 | _titleLabel.text = @"测试title"; 225 | _titleLabel.textAlignment = NSTextAlignmentCenter; 226 | _titleLabel.font = [UIFont systemFontOfSize:18]; 227 | _titleLabel.backgroundColor = [UIColor greenColor]; 228 | [view1 addSubview:_titleLabel]; 229 | _titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; 230 | 231 | _chooseBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, view1.frame.size.height - 40, view1.frame.size.width, 40)]; 232 | // _chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 233 | [_chooseBtn setTitle:@"取消" forState:UIControlStateNormal]; 234 | [_chooseBtn setBackgroundColor:[UIColor redColor]]; 235 | [_chooseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 236 | [_chooseBtn addTarget:self action:@selector(cancleButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 237 | [view1 addSubview:_chooseBtn]; 238 | _chooseBtn.autoresizingMask = UIViewAutoresizingFlexibleWidth; 239 | 240 | _alertView5 = [[DSAlert alloc] initWithCustomView:view1]; 241 | _alertView5.showAnimate = YES; 242 | [_alertView5 ds_showAlertView]; 243 | } 244 | 245 | - (void)cancleButtonAction:(UIButton *)sender 246 | { 247 | NSLog(@"点击了取消按钮!"); 248 | /*! 隐藏alert */ 249 | [_alertView5 ds_dismissAlertView]; 250 | } 251 | ``` 252 | 253 | * 2.6 actionsheet 254 | 255 | ``` 256 | [DSActionSheet ds_showActionSheetWithStyle:DSCustomActionSheetStyleNormal 257 | contentArray:@[@"测试1",@"测试2",@"测试3"] 258 | imageArray:nil 259 | redIndex:1 260 | title:nil 261 | ClikckButtonIndex:^(NSInteger index) { 262 | NSLog(@"你点击了第 %ld 行!",(long)index); 263 | }]; 264 | ``` 265 | 266 | * 2.7 actionsheet带标题 267 | 268 | ``` 269 | [DSActionSheet ds_showActionSheetWithStyle:DSCustomActionSheetStyleTitle 270 | contentArray:@[@"测试1",@"测试2",@"测试3"] 271 | imageArray:nil 272 | redIndex:1 273 | title:@"测试带标题的ActionSheet" 274 | ClikckButtonIndex:^(NSInteger index) { 275 | NSLog(@"你点击了第 %ld 行!",(long)index); 276 | }]; 277 | ``` 278 | 279 | * 2.8 actionsheet带标题带图片 280 | 281 | ``` 282 | [DSActionSheet ds_showActionSheetWithStyle:DSCustomActionSheetStyleImageAndTitle 283 | contentArray:@[@"测试1",@"测试2",@"测试3"] 284 | imageArray:@[[UIImage imageNamed:@"123.png"],[UIImage imageNamed:@"背景.jpg"],[UIImage imageNamed:@"美女.jpg"]] 285 | redIndex:1 286 | title:@"测试带标题和图片的ActionSheet" 287 | ClikckButtonIndex:^(NSInteger index) { 288 | NSLog(@"你点击了第 %ld 行!",(long)index); 289 | }]; 290 | ``` 291 | 292 | ## 3、DS-Team 简介 293 | DS-Team 是一个自发组织的民间团队,成立于2016年,致力于 iOS 最简洁的封装和最新技术的研发,一般都有 OC 和 swift 版本,后期会推出其他语言版本。 294 | 295 | 为解决广大小白项目中遇到的各种疑难杂症,小伙伴儿们可以加入我们的QQ群 `479663605`,希望广大小白和大神能够积极加入! 296 | 297 | 298 | ## 4、系统要求 299 | 300 | 该项目最低支持 iOS 7.0 和 Xcode 7.2(swift 版本只支持Xcode 7.3及以上版本),理论支持目前所有 iOS 系统版本! 301 | 302 | --- 303 | 304 | 305 | 306 | 307 | 308 | 309 | --------------------------------------------------------------------------------