├── README.md ├── SwiftPopTipView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SwiftPopTipView ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── SwiftPopTipView.swift └── ViewController.swift └── SwiftPopTipViewTests ├── Info.plist └── SwiftPopTipViewTests.swift /README.md: -------------------------------------------------------------------------------- 1 | # SwiftPopTipView 2 | 3 | The representation of CMPopTipView in Swift 4 | 5 | ![iPhone screenshot](https://farm8.staticflickr.com/7497/15865951110_8e30e1780e.jpg) 6 | 7 | An iOS UIView subclass that displays a rounded rect "bubble", containing 8 | a text message, pointing at a specified button or view. 9 | 10 | A SwiftPopTipView will automatically position itself within the view so that 11 | it is pointing at the specified button or view, positioning the "pointer" 12 | as necessary. 13 | 14 | A SwiftPopTipView can be pointed at any UIView within the containing view. 15 | It can also be pointed at a UIBarButtonItem within either a UINavigationBar 16 | or a UIToolbar and it will automatically position itself to point at the 17 | target. 18 | 19 | The background and text colors can be customised if the defaults are not 20 | suitable. 21 | 22 | Two animation options are available for when a SwiftPopTipView is presented: 23 | "slide" and "pop". 24 | 25 | A SwiftPopTipView can be dismissed by the user tapping on it. It can also 26 | be dismissed programatically. 27 | 28 | SwiftPopTipView is rendered entirely by Core Graphics. 29 | 30 | The source includes a universal (iPhone/iPad) demo app. 31 | 32 | ## URLs 33 | 34 | * https://github.com/chrismiles/CMPopTipView 35 | * http://mihaelisaev.com 36 | 37 | ## Requirements 38 | 39 | * iOS 8.1+ 40 | * Xcode 8+ 41 | 42 | ## Usage 43 | 44 | Example 1 - point at a UIBarButtonItem in a nav bar:: 45 | 46 | ``` swift 47 | // Present a SwiftPopTipView pointing at a UIBarButtonItem in the nav bar 48 | let navBarLeftButtonPopTipView = SwiftPopTipView(message: "A message") 49 | navBarLeftButtonPopTipView.presentPointingAtBarButtonItem(navigationItem.leftBarButtonItem!, animated: true) 50 | 51 | // Dismiss a SwiftPopTipView 52 | navBarLeftButtonPopTipView.dismissAnimated(true) 53 | 54 | ``` 55 | 56 | Example 2 - pointing at a UIButton, with custom color scheme:: 57 | 58 | ``` swift 59 | class ViewController: UIViewController, SwiftPopTipViewDelegate { 60 | var roundRectButtonPopTipView: SwiftPopTipView? 61 | 62 | @IBAction func buttonAction(_ sender: UIButton) { 63 | // Toggle popTipView when a standard UIButton is pressed 64 | if let _ = roundRectButtonPopTipView { 65 | // Dismiss 66 | roundRectButtonPopTipView?.dismissAnimated(true) 67 | roundRectButtonPopTipView = nil 68 | } else { 69 | roundRectButtonPopTipView = SwiftPopTipView(message: "My message") 70 | roundRectButtonPopTipView?.delegate = self 71 | roundRectButtonPopTipView?.popColor = UIColor.lightGray 72 | roundRectButtonPopTipView?.textColor = UIColor.darkText 73 | 74 | roundRectButtonPopTipView?.presentPointingAtView(sender as! UIView, containerView: view, animated: true) 75 | } 76 | } 77 | 78 | //MARK: - SwiftPopTipViewDelegate methods 79 | func popTipViewWasDismissedByUser(popTipView: SwiftPopTipView) { 80 | // User can tap SwiftPopTipView to dismiss it 81 | roundRectButtonPopTipView = nil 82 | } 83 | } 84 | ``` 85 | 86 | ## Support 87 | 88 | SwiftPopTipView is provided open source with no warranty and no guarantee 89 | of support. However, best effort is made to address issues raised on Github 90 | https://github.com/MihaelIsaev/SwiftPopTipView/issues 91 | 92 | If you would like assistance with integrating SwiftPopTipView or modifying 93 | it for your needs, contact the author for consulting 94 | opportunities. 95 | 96 | 97 | ## License 98 | 99 | SwiftPopTipView is Copyright (c) 2014 MihaelIsaev (mihaelisaev.com) and released open source 100 | under a MIT license: 101 | 102 | Permission is hereby granted, free of charge, to any person obtaining a copy 103 | of this software and associated documentation files (the "Software"), to deal 104 | in the Software without restriction, including without limitation the rights 105 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 106 | copies of the Software, and to permit persons to whom the Software is 107 | furnished to do so, subject to the following conditions: 108 | 109 | The above copyright notice and this permission notice shall be included in 110 | all copies or substantial portions of the Software. 111 | 112 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 113 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 114 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 115 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 116 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 117 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 118 | THE SOFTWARE. 119 | -------------------------------------------------------------------------------- /SwiftPopTipView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4780D01D1A43A03100E43757 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780D01C1A43A03100E43757 /* AppDelegate.swift */; }; 11 | 4780D01F1A43A03100E43757 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780D01E1A43A03100E43757 /* ViewController.swift */; }; 12 | 4780D0221A43A03100E43757 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4780D0201A43A03100E43757 /* Main.storyboard */; }; 13 | 4780D0241A43A03100E43757 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4780D0231A43A03100E43757 /* Images.xcassets */; }; 14 | 4780D0271A43A03100E43757 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4780D0251A43A03100E43757 /* LaunchScreen.xib */; }; 15 | 4780D0331A43A03100E43757 /* SwiftPopTipViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780D0321A43A03100E43757 /* SwiftPopTipViewTests.swift */; }; 16 | 4780D03D1A43A05100E43757 /* SwiftPopTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780D03C1A43A05100E43757 /* SwiftPopTipView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 4780D02D1A43A03100E43757 /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 4780D00F1A43A03100E43757 /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 4780D0161A43A03100E43757; 25 | remoteInfo = SwiftPopTipView; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 4780D0171A43A03100E43757 /* SwiftPopTipView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftPopTipView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 4780D01B1A43A03100E43757 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 4780D01C1A43A03100E43757 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | 4780D01E1A43A03100E43757 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 34 | 4780D0211A43A03100E43757 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 4780D0231A43A03100E43757 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 36 | 4780D0261A43A03100E43757 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 37 | 4780D02C1A43A03100E43757 /* SwiftPopTipViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftPopTipViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 4780D0311A43A03100E43757 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | 4780D0321A43A03100E43757 /* SwiftPopTipViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftPopTipViewTests.swift; sourceTree = ""; }; 40 | 4780D03C1A43A05100E43757 /* SwiftPopTipView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftPopTipView.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 4780D0141A43A03100E43757 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | 4780D0291A43A03100E43757 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | 4780D00E1A43A03100E43757 = { 62 | isa = PBXGroup; 63 | children = ( 64 | 4780D0191A43A03100E43757 /* SwiftPopTipView */, 65 | 4780D02F1A43A03100E43757 /* SwiftPopTipViewTests */, 66 | 4780D0181A43A03100E43757 /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 4780D0181A43A03100E43757 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 4780D0171A43A03100E43757 /* SwiftPopTipView.app */, 74 | 4780D02C1A43A03100E43757 /* SwiftPopTipViewTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 4780D0191A43A03100E43757 /* SwiftPopTipView */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 4780D01C1A43A03100E43757 /* AppDelegate.swift */, 83 | 4780D01E1A43A03100E43757 /* ViewController.swift */, 84 | 4780D03C1A43A05100E43757 /* SwiftPopTipView.swift */, 85 | 4780D0201A43A03100E43757 /* Main.storyboard */, 86 | 4780D0231A43A03100E43757 /* Images.xcassets */, 87 | 4780D0251A43A03100E43757 /* LaunchScreen.xib */, 88 | 4780D01A1A43A03100E43757 /* Supporting Files */, 89 | ); 90 | path = SwiftPopTipView; 91 | sourceTree = ""; 92 | }; 93 | 4780D01A1A43A03100E43757 /* Supporting Files */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 4780D01B1A43A03100E43757 /* Info.plist */, 97 | ); 98 | name = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | 4780D02F1A43A03100E43757 /* SwiftPopTipViewTests */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 4780D0321A43A03100E43757 /* SwiftPopTipViewTests.swift */, 105 | 4780D0301A43A03100E43757 /* Supporting Files */, 106 | ); 107 | path = SwiftPopTipViewTests; 108 | sourceTree = ""; 109 | }; 110 | 4780D0301A43A03100E43757 /* Supporting Files */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 4780D0311A43A03100E43757 /* Info.plist */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | 4780D0161A43A03100E43757 /* SwiftPopTipView */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = 4780D0361A43A03100E43757 /* Build configuration list for PBXNativeTarget "SwiftPopTipView" */; 124 | buildPhases = ( 125 | 4780D0131A43A03100E43757 /* Sources */, 126 | 4780D0141A43A03100E43757 /* Frameworks */, 127 | 4780D0151A43A03100E43757 /* Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = SwiftPopTipView; 134 | productName = SwiftPopTipView; 135 | productReference = 4780D0171A43A03100E43757 /* SwiftPopTipView.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | 4780D02B1A43A03100E43757 /* SwiftPopTipViewTests */ = { 139 | isa = PBXNativeTarget; 140 | buildConfigurationList = 4780D0391A43A03100E43757 /* Build configuration list for PBXNativeTarget "SwiftPopTipViewTests" */; 141 | buildPhases = ( 142 | 4780D0281A43A03100E43757 /* Sources */, 143 | 4780D0291A43A03100E43757 /* Frameworks */, 144 | 4780D02A1A43A03100E43757 /* Resources */, 145 | ); 146 | buildRules = ( 147 | ); 148 | dependencies = ( 149 | 4780D02E1A43A03100E43757 /* PBXTargetDependency */, 150 | ); 151 | name = SwiftPopTipViewTests; 152 | productName = SwiftPopTipViewTests; 153 | productReference = 4780D02C1A43A03100E43757 /* SwiftPopTipViewTests.xctest */; 154 | productType = "com.apple.product-type.bundle.unit-test"; 155 | }; 156 | /* End PBXNativeTarget section */ 157 | 158 | /* Begin PBXProject section */ 159 | 4780D00F1A43A03100E43757 /* Project object */ = { 160 | isa = PBXProject; 161 | attributes = { 162 | LastUpgradeCheck = 0610; 163 | ORGANIZATIONNAME = "Mihael Isaev inc."; 164 | TargetAttributes = { 165 | 4780D0161A43A03100E43757 = { 166 | CreatedOnToolsVersion = 6.1.1; 167 | LastSwiftMigration = 0800; 168 | }; 169 | 4780D02B1A43A03100E43757 = { 170 | CreatedOnToolsVersion = 6.1.1; 171 | LastSwiftMigration = 0800; 172 | TestTargetID = 4780D0161A43A03100E43757; 173 | }; 174 | }; 175 | }; 176 | buildConfigurationList = 4780D0121A43A03100E43757 /* Build configuration list for PBXProject "SwiftPopTipView" */; 177 | compatibilityVersion = "Xcode 3.2"; 178 | developmentRegion = English; 179 | hasScannedForEncodings = 0; 180 | knownRegions = ( 181 | English, 182 | en, 183 | Base, 184 | ); 185 | mainGroup = 4780D00E1A43A03100E43757; 186 | productRefGroup = 4780D0181A43A03100E43757 /* Products */; 187 | projectDirPath = ""; 188 | projectRoot = ""; 189 | targets = ( 190 | 4780D0161A43A03100E43757 /* SwiftPopTipView */, 191 | 4780D02B1A43A03100E43757 /* SwiftPopTipViewTests */, 192 | ); 193 | }; 194 | /* End PBXProject section */ 195 | 196 | /* Begin PBXResourcesBuildPhase section */ 197 | 4780D0151A43A03100E43757 /* Resources */ = { 198 | isa = PBXResourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | 4780D0221A43A03100E43757 /* Main.storyboard in Resources */, 202 | 4780D0271A43A03100E43757 /* LaunchScreen.xib in Resources */, 203 | 4780D0241A43A03100E43757 /* Images.xcassets in Resources */, 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | }; 207 | 4780D02A1A43A03100E43757 /* Resources */ = { 208 | isa = PBXResourcesBuildPhase; 209 | buildActionMask = 2147483647; 210 | files = ( 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | 4780D0131A43A03100E43757 /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 4780D01F1A43A03100E43757 /* ViewController.swift in Sources */, 222 | 4780D03D1A43A05100E43757 /* SwiftPopTipView.swift in Sources */, 223 | 4780D01D1A43A03100E43757 /* AppDelegate.swift in Sources */, 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | 4780D0281A43A03100E43757 /* Sources */ = { 228 | isa = PBXSourcesBuildPhase; 229 | buildActionMask = 2147483647; 230 | files = ( 231 | 4780D0331A43A03100E43757 /* SwiftPopTipViewTests.swift in Sources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXSourcesBuildPhase section */ 236 | 237 | /* Begin PBXTargetDependency section */ 238 | 4780D02E1A43A03100E43757 /* PBXTargetDependency */ = { 239 | isa = PBXTargetDependency; 240 | target = 4780D0161A43A03100E43757 /* SwiftPopTipView */; 241 | targetProxy = 4780D02D1A43A03100E43757 /* PBXContainerItemProxy */; 242 | }; 243 | /* End PBXTargetDependency section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | 4780D0201A43A03100E43757 /* Main.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | 4780D0211A43A03100E43757 /* Base */, 250 | ); 251 | name = Main.storyboard; 252 | sourceTree = ""; 253 | }; 254 | 4780D0251A43A03100E43757 /* LaunchScreen.xib */ = { 255 | isa = PBXVariantGroup; 256 | children = ( 257 | 4780D0261A43A03100E43757 /* Base */, 258 | ); 259 | name = LaunchScreen.xib; 260 | sourceTree = ""; 261 | }; 262 | /* End PBXVariantGroup section */ 263 | 264 | /* Begin XCBuildConfiguration section */ 265 | 4780D0341A43A03100E43757 /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ALWAYS_SEARCH_USER_PATHS = NO; 269 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 270 | CLANG_CXX_LIBRARY = "libc++"; 271 | CLANG_ENABLE_MODULES = YES; 272 | CLANG_ENABLE_OBJC_ARC = YES; 273 | CLANG_WARN_BOOL_CONVERSION = YES; 274 | CLANG_WARN_CONSTANT_CONVERSION = YES; 275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INT_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_UNREACHABLE_CODE = YES; 281 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 282 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 283 | COPY_PHASE_STRIP = NO; 284 | ENABLE_STRICT_OBJC_MSGSEND = YES; 285 | GCC_C_LANGUAGE_STANDARD = gnu99; 286 | GCC_DYNAMIC_NO_PIC = NO; 287 | GCC_OPTIMIZATION_LEVEL = 0; 288 | GCC_PREPROCESSOR_DEFINITIONS = ( 289 | "DEBUG=1", 290 | "$(inherited)", 291 | ); 292 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 293 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 294 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 295 | GCC_WARN_UNDECLARED_SELECTOR = YES; 296 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 297 | GCC_WARN_UNUSED_FUNCTION = YES; 298 | GCC_WARN_UNUSED_VARIABLE = YES; 299 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 300 | MTL_ENABLE_DEBUG_INFO = YES; 301 | ONLY_ACTIVE_ARCH = YES; 302 | SDKROOT = iphoneos; 303 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 304 | TARGETED_DEVICE_FAMILY = "1,2"; 305 | }; 306 | name = Debug; 307 | }; 308 | 4780D0351A43A03100E43757 /* Release */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ALWAYS_SEARCH_USER_PATHS = NO; 312 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 313 | CLANG_CXX_LIBRARY = "libc++"; 314 | CLANG_ENABLE_MODULES = YES; 315 | CLANG_ENABLE_OBJC_ARC = YES; 316 | CLANG_WARN_BOOL_CONVERSION = YES; 317 | CLANG_WARN_CONSTANT_CONVERSION = YES; 318 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 319 | CLANG_WARN_EMPTY_BODY = YES; 320 | CLANG_WARN_ENUM_CONVERSION = YES; 321 | CLANG_WARN_INT_CONVERSION = YES; 322 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 323 | CLANG_WARN_UNREACHABLE_CODE = YES; 324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 326 | COPY_PHASE_STRIP = YES; 327 | ENABLE_NS_ASSERTIONS = NO; 328 | ENABLE_STRICT_OBJC_MSGSEND = YES; 329 | GCC_C_LANGUAGE_STANDARD = gnu99; 330 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 331 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 332 | GCC_WARN_UNDECLARED_SELECTOR = YES; 333 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 334 | GCC_WARN_UNUSED_FUNCTION = YES; 335 | GCC_WARN_UNUSED_VARIABLE = YES; 336 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 337 | MTL_ENABLE_DEBUG_INFO = NO; 338 | SDKROOT = iphoneos; 339 | TARGETED_DEVICE_FAMILY = "1,2"; 340 | VALIDATE_PRODUCT = YES; 341 | }; 342 | name = Release; 343 | }; 344 | 4780D0371A43A03100E43757 /* Debug */ = { 345 | isa = XCBuildConfiguration; 346 | buildSettings = { 347 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 348 | INFOPLIST_FILE = SwiftPopTipView/Info.plist; 349 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | SWIFT_VERSION = 5.0; 353 | }; 354 | name = Debug; 355 | }; 356 | 4780D0381A43A03100E43757 /* Release */ = { 357 | isa = XCBuildConfiguration; 358 | buildSettings = { 359 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 360 | INFOPLIST_FILE = SwiftPopTipView/Info.plist; 361 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 362 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | SWIFT_VERSION = 5.0; 365 | }; 366 | name = Release; 367 | }; 368 | 4780D03A1A43A03100E43757 /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | BUNDLE_LOADER = "$(TEST_HOST)"; 372 | FRAMEWORK_SEARCH_PATHS = ( 373 | "$(SDKROOT)/Developer/Library/Frameworks", 374 | "$(inherited)", 375 | ); 376 | GCC_PREPROCESSOR_DEFINITIONS = ( 377 | "DEBUG=1", 378 | "$(inherited)", 379 | ); 380 | INFOPLIST_FILE = SwiftPopTipViewTests/Info.plist; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | SWIFT_VERSION = 3.0; 384 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftPopTipView.app/SwiftPopTipView"; 385 | }; 386 | name = Debug; 387 | }; 388 | 4780D03B1A43A03100E43757 /* Release */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | BUNDLE_LOADER = "$(TEST_HOST)"; 392 | FRAMEWORK_SEARCH_PATHS = ( 393 | "$(SDKROOT)/Developer/Library/Frameworks", 394 | "$(inherited)", 395 | ); 396 | INFOPLIST_FILE = SwiftPopTipViewTests/Info.plist; 397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | SWIFT_VERSION = 3.0; 400 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftPopTipView.app/SwiftPopTipView"; 401 | }; 402 | name = Release; 403 | }; 404 | /* End XCBuildConfiguration section */ 405 | 406 | /* Begin XCConfigurationList section */ 407 | 4780D0121A43A03100E43757 /* Build configuration list for PBXProject "SwiftPopTipView" */ = { 408 | isa = XCConfigurationList; 409 | buildConfigurations = ( 410 | 4780D0341A43A03100E43757 /* Debug */, 411 | 4780D0351A43A03100E43757 /* Release */, 412 | ); 413 | defaultConfigurationIsVisible = 0; 414 | defaultConfigurationName = Release; 415 | }; 416 | 4780D0361A43A03100E43757 /* Build configuration list for PBXNativeTarget "SwiftPopTipView" */ = { 417 | isa = XCConfigurationList; 418 | buildConfigurations = ( 419 | 4780D0371A43A03100E43757 /* Debug */, 420 | 4780D0381A43A03100E43757 /* Release */, 421 | ); 422 | defaultConfigurationIsVisible = 0; 423 | defaultConfigurationName = Release; 424 | }; 425 | 4780D0391A43A03100E43757 /* Build configuration list for PBXNativeTarget "SwiftPopTipViewTests" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | 4780D03A1A43A03100E43757 /* Debug */, 429 | 4780D03B1A43A03100E43757 /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | /* End XCConfigurationList section */ 435 | }; 436 | rootObject = 4780D00F1A43A03100E43757 /* Project object */; 437 | } 438 | -------------------------------------------------------------------------------- /SwiftPopTipView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftPopTipView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftPopTipView 4 | // 5 | // Created by Mihael Isaev on 18.12.14. 6 | // Copyright (c) 2014 Mihael Isaev inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /SwiftPopTipView/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SwiftPopTipView/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 | 44 | 53 | 62 | 72 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /SwiftPopTipView/Images.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 | } -------------------------------------------------------------------------------- /SwiftPopTipView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.mihaelisaev.$(PRODUCT_NAME:rfc1034identifier) 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 | -------------------------------------------------------------------------------- /SwiftPopTipView/SwiftPopTipView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftPopTipView.swift 3 | // SwiftPopTipView 4 | // 5 | // Created by Mihael Isaev on 18.12.14. 6 | // Copyright (c) 2014 Mihael Isaev inc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | enum PointDirection: Int { 13 | case any = 0 14 | case up, down 15 | } 16 | 17 | enum SwiftPopTipAnimation: Int { 18 | case slide = 0 19 | case pop 20 | } 21 | 22 | protocol SwiftPopTipViewDelegate { 23 | func popTipViewWasDismissedByUser(_ popTipView:SwiftPopTipView) 24 | } 25 | 26 | class SwiftPopTipView: UIView { 27 | var delegate: SwiftPopTipViewDelegate? 28 | var disableTapToDismiss = false 29 | var dismissTapAnywhere = true 30 | var isShowing = false 31 | var title: String? 32 | var message: String? 33 | var customView: UIView? 34 | var targetObject: Any? 35 | var popColor = UIColor.white 36 | var titleColor: UIColor? 37 | var titleFont = UIFont.boldSystemFont(ofSize: 16) 38 | var textColor = UIColor.black 39 | var textFont = UIFont.boldSystemFont(ofSize: 14) 40 | var titleAlignment: NSTextAlignment = .center 41 | var textAlignment: NSTextAlignment = .center 42 | var has3DStyle = false 43 | var borderColor = UIColor.black 44 | var cornerRadius: CGFloat = 10 45 | var borderWidth: CGFloat = 0.1 46 | var highlight = false 47 | private var _hasShadow: Bool? 48 | var hasShadow: Bool! { 49 | get { 50 | return self._hasShadow 51 | } 52 | set { 53 | self._hasShadow = newValue 54 | if newValue { 55 | layer.shadowOffset = CGSize(width: 0, height: 3) 56 | layer.shadowRadius = 2 57 | layer.shadowColor = UIColor.black.cgColor 58 | layer.shadowOpacity = 0.3 59 | } else { 60 | layer.shadowOpacity = 0.0 61 | } 62 | } 63 | } 64 | var animation: SwiftPopTipAnimation = .slide 65 | var maxWidth: CGFloat? 66 | var preferredPointDirection: PointDirection = .any 67 | var pointDirection: PointDirection = .any 68 | var hasGradientBackground = false 69 | var sidePadding: CGFloat = 2 70 | var topMargin: CGFloat = 2 71 | var pointerSize: CGFloat = 12 72 | var bubbleSize: CGSize = CGSize.zero 73 | var targetPoint: CGPoint = CGPoint.zero 74 | var autoDismissTimer: Timer? 75 | var dismissTarget: UIButton? 76 | 77 | required init?(coder aDecoder: NSCoder) { 78 | super.init(coder: aDecoder) 79 | isOpaque = false 80 | backgroundColor = UIColor.clear 81 | } 82 | 83 | override init(frame: CGRect) { 84 | super.init(frame: frame) 85 | isOpaque = false 86 | backgroundColor = UIColor.clear 87 | } 88 | 89 | required init () { 90 | super.init(frame: CGRect.zero) 91 | backgroundColor = UIColor.clear 92 | titleFont = UIFont.boldSystemFont(ofSize: 16) 93 | titleColor = UIColor.black 94 | titleAlignment = .center 95 | textFont = UIFont.systemFont(ofSize: 14) 96 | textColor = UIColor.black 97 | } 98 | 99 | init(title: String? = nil, message: String? = nil, customView: UIView? = nil) { 100 | super.init(frame: CGRect.zero) 101 | self.title = title 102 | self.message = message 103 | 104 | backgroundColor = UIColor.clear 105 | titleFont = UIFont.boldSystemFont(ofSize: 16) 106 | titleColor = UIColor.black 107 | titleAlignment = .center 108 | textFont = UIFont.systemFont(ofSize: 14) 109 | textColor = UIColor.black 110 | if let aView = customView { 111 | self.customView = aView 112 | addSubview(customView!) 113 | } 114 | } 115 | 116 | func bubbleFrame() -> CGRect { 117 | var bubbleFrame: CGRect 118 | if pointDirection == .up { 119 | bubbleFrame = CGRect(x: sidePadding, y: targetPoint.y+pointerSize, width: bubbleSize.width, height: bubbleSize.height); 120 | } else { 121 | bubbleFrame = CGRect(x: sidePadding, y: targetPoint.y-pointerSize-bubbleSize.height, width: bubbleSize.width, height: bubbleSize.height); 122 | } 123 | return bubbleFrame 124 | } 125 | 126 | func contentFrame() -> CGRect { 127 | let customBubbleFrame = bubbleFrame() 128 | let contentFrame = CGRect(x: customBubbleFrame.origin.x + cornerRadius, 129 | y: customBubbleFrame.origin.y + cornerRadius, 130 | width: customBubbleFrame.size.width - cornerRadius*2, 131 | height: customBubbleFrame.size.height - cornerRadius*2) 132 | return contentFrame 133 | } 134 | 135 | override func layoutSubviews() { 136 | if let customView = customView { 137 | let customContentFrame = contentFrame() 138 | customView.frame = customContentFrame 139 | } 140 | } 141 | 142 | override func draw(_ rect: CGRect) { 143 | let bubbleRect = bubbleFrame() 144 | 145 | let c = UIGraphicsGetCurrentContext() 146 | 147 | c?.setStrokeColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) 148 | c?.setLineWidth(borderWidth) 149 | 150 | let bubblePath = CGMutablePath() 151 | 152 | if pointDirection == .up { 153 | bubblePath.move(to: CGPoint(x: targetPoint.x+sidePadding, y: targetPoint.y)) 154 | bubblePath.addLine(to: CGPoint(x: targetPoint.x+sidePadding+pointerSize, y: targetPoint.y+pointerSize)) 155 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y), 156 | tangent2End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+cornerRadius), 157 | radius: cornerRadius) 158 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+bubbleRect.size.height), 159 | tangent2End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width-cornerRadius, y: bubbleRect.origin.y+bubbleRect.size.height), 160 | radius: cornerRadius) 161 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y+bubbleRect.size.height), 162 | tangent2End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y+bubbleRect.size.height-cornerRadius), 163 | radius: cornerRadius) 164 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y), 165 | tangent2End: CGPoint(x: bubbleRect.origin.x+cornerRadius, y: bubbleRect.origin.y), 166 | radius: cornerRadius) 167 | bubblePath.addLine(to: CGPoint(x: targetPoint.x+sidePadding-pointerSize, y: targetPoint.y+pointerSize)) 168 | } else { 169 | bubblePath.move(to: CGPoint(x: targetPoint.x+sidePadding, y: targetPoint.y)) 170 | bubblePath.addLine(to: CGPoint(x: targetPoint.x+sidePadding-pointerSize, y: targetPoint.y-pointerSize)) 171 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y+bubbleRect.size.height), 172 | tangent2End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y+bubbleRect.size.height-cornerRadius), 173 | radius: cornerRadius) 174 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x, y: bubbleRect.origin.y), 175 | tangent2End: CGPoint(x: bubbleRect.origin.x+cornerRadius, y: bubbleRect.origin.y), 176 | radius: cornerRadius) 177 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y), 178 | tangent2End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+cornerRadius), 179 | radius: cornerRadius) 180 | bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+bubbleRect.size.height), 181 | tangent2End: CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width-cornerRadius, y: bubbleRect.origin.y+bubbleRect.size.height), 182 | radius: cornerRadius) 183 | bubblePath.addLine(to: CGPoint(x: targetPoint.x+sidePadding+pointerSize, y: targetPoint.y-pointerSize)) 184 | } 185 | 186 | bubblePath.closeSubpath() 187 | 188 | c?.saveGState() 189 | c?.addPath(bubblePath) 190 | c?.clip() 191 | 192 | if !hasGradientBackground { 193 | c?.setFillColor(popColor.cgColor) 194 | c?.fill(bounds) 195 | } else { 196 | let bubbleMiddle = (bubbleRect.origin.y+(bubbleRect.size.height/2)) / bounds.size.height 197 | 198 | var myGradient: CGGradient 199 | var myColorSpace: CGColorSpace 200 | let locationCount: size_t = 5 201 | let locationList: [CGFloat] = [0.0, bubbleMiddle-0.03, bubbleMiddle, bubbleMiddle+0.03, 1.0] 202 | 203 | var colourHL: CGFloat = 0 204 | if highlight { 205 | colourHL = 0.25 206 | } 207 | 208 | var red, green, blue, alpha: CGFloat 209 | let numComponents: size_t = backgroundColor!.cgColor.numberOfComponents 210 | let components = backgroundColor!.cgColor.components 211 | if numComponents == 2 { 212 | red = (components?[0])! 213 | green = (components?[0])! 214 | blue = (components?[0])! 215 | alpha = (components?[1])! 216 | } else { 217 | red = (components?[0])! 218 | green = (components?[1])! 219 | blue = (components?[2])! 220 | alpha = (components?[3])! 221 | } 222 | let colorList: [CGFloat] = [ 223 | red*1.16+colourHL, green*1.16+colourHL, blue*1.16+colourHL, alpha, 224 | red*1.16+colourHL, green*1.16+colourHL, blue*1.16+colourHL, alpha, 225 | red*1.08+colourHL, green*1.08+colourHL, blue*1.08+colourHL, alpha, 226 | red+colourHL, green+colourHL, blue+colourHL, alpha, 227 | red+colourHL, green+colourHL, blue+colourHL, alpha 228 | ] 229 | myColorSpace = CGColorSpaceCreateDeviceRGB() 230 | myGradient = CGGradient(colorSpace: myColorSpace, colorComponents: colorList, locations: locationList, count: locationCount)! 231 | let startPoint = CGPoint(x: 0, y: 0) 232 | let endPoint = CGPoint(x: 0, y: bounds.maxY) 233 | 234 | c?.drawLinearGradient(myGradient, start: startPoint, end: endPoint, options: CGGradientDrawingOptions(rawValue: 0)) 235 | } 236 | 237 | if has3DStyle { 238 | c?.saveGState() 239 | let innerShadowPath = CGMutablePath() 240 | innerShadowPath.addRect(bubblePath.boundingBoxOfPath.insetBy(dx: -30, dy: -30)) 241 | innerShadowPath.addPath(bubblePath) 242 | innerShadowPath.closeSubpath() 243 | 244 | let highlightColor = UIColor(white: 1, alpha: 0.75) 245 | c?.setFillColor(highlightColor.cgColor) 246 | c?.setShadow(offset: CGSize(width: 0, height: 4), blur: 4, color: highlightColor.cgColor) 247 | c?.addPath(innerShadowPath) 248 | c?.fillPath() 249 | 250 | let shadowColor = UIColor(white: 0, alpha: 0.4) 251 | c?.setFillColor(shadowColor.cgColor) 252 | c?.setShadow(offset: CGSize(width: 0, height: -4), blur: 4, color: shadowColor.cgColor) 253 | c?.addPath(innerShadowPath) 254 | c?.fillPath() 255 | c?.restoreGState() 256 | } 257 | 258 | c?.restoreGState() 259 | 260 | if borderWidth > 0 { 261 | let numBorderComponents: size_t = borderColor.cgColor.numberOfComponents 262 | let borderComponents = borderColor.cgColor.components 263 | var r, g, b, a: CGFloat 264 | if numBorderComponents == 2 { 265 | r = (borderComponents?[0])! 266 | g = (borderComponents?[0])! 267 | b = (borderComponents?[0])! 268 | a = (borderComponents?[1])! 269 | } else { 270 | r = (borderComponents?[0])! 271 | g = (borderComponents?[1])! 272 | b = (borderComponents?[2])! 273 | a = (borderComponents?[3])! 274 | } 275 | 276 | c?.setStrokeColor(red: r, green: g, blue: b, alpha: a) 277 | c?.addPath(bubblePath) 278 | c?.drawPath(using: CGPathDrawingMode.stroke) 279 | } 280 | 281 | if let title = title { 282 | titleColor?.set() 283 | let titleFrame = contentFrame() 284 | let titleParagraphStyle = NSMutableParagraphStyle() 285 | titleParagraphStyle.alignment = titleAlignment 286 | titleParagraphStyle.lineBreakMode = .byClipping 287 | title.draw(with: titleFrame, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: titleFont, NSAttributedString.Key.foregroundColor: titleColor!, NSAttributedString.Key.paragraphStyle: titleParagraphStyle], context: nil) 288 | } 289 | 290 | if let message = message { 291 | textColor.set() 292 | var textFrame = contentFrame() 293 | 294 | if let title = title { 295 | let titleParagraphStyle = NSMutableParagraphStyle() 296 | titleParagraphStyle.alignment = titleAlignment 297 | titleParagraphStyle.lineBreakMode = .byClipping 298 | textFrame.origin.y += title.boundingRect(with: CGSize(width: textFrame.size.width, height: 99999.0), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: titleFont, NSAttributedString.Key.paragraphStyle: titleParagraphStyle], context: nil).size.height 299 | } 300 | 301 | let textParagraphStyle = NSMutableParagraphStyle() 302 | textParagraphStyle.alignment = textAlignment 303 | textParagraphStyle.lineBreakMode = .byWordWrapping 304 | 305 | message.draw(with: textFrame, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: textFont, NSAttributedString.Key.paragraphStyle: textParagraphStyle, NSAttributedString.Key.foregroundColor: textColor], context: nil) 306 | } 307 | } 308 | 309 | func presentPointingAtBarButtonItem(_ barButtonItem: UIBarButtonItem, animated: Bool) { 310 | let targetView = barButtonItem.value(forKey: "view") as! UIView 311 | let targetSuperview = targetView.superview 312 | var containerView: UIView? 313 | if type(of: targetSuperview!) === UINavigationBar.self { 314 | containerView = UIApplication.shared.windows.first { $0.isKeyWindow } 315 | } else if type(of: targetSuperview!) === UIToolbar.self { 316 | containerView = targetSuperview?.superview 317 | } 318 | containerView = targetSuperview?.superview 319 | 320 | if containerView == nil { 321 | NSLog("Cannot determine container view from UIBarButtonItem: %@", barButtonItem); 322 | targetObject = nil 323 | return 324 | } 325 | 326 | targetObject = barButtonItem 327 | 328 | self.presentPointingAtView(targetView, containerView: containerView!, animated: animated) 329 | } 330 | 331 | func presentPointingAtView(_ targetView: UIView, containerView: UIView, animated: Bool) { 332 | if isShowing { 333 | return 334 | } 335 | isShowing = true 336 | if targetObject == nil { 337 | targetObject = targetView 338 | } 339 | 340 | if dismissTapAnywhere { 341 | dismissTarget = UIButton(type: .custom) 342 | dismissTarget?.addTarget(self, action: #selector(dismissTapAnywhereFired(_:)), for: .touchUpInside) 343 | dismissTarget?.setTitle("", for: UIControl.State()) 344 | dismissTarget?.frame = containerView.bounds 345 | if let dismissTarget = dismissTarget { 346 | containerView.addSubview(dismissTarget) 347 | } 348 | } 349 | 350 | containerView.addSubview(self) 351 | 352 | var rectWidth: CGFloat 353 | 354 | if UIDevice.current.userInterfaceIdiom == .pad { 355 | if let maxWidth = maxWidth { 356 | if maxWidth < containerView.frame.size.width { 357 | rectWidth = maxWidth 358 | } else { 359 | rectWidth = containerView.frame.size.width - 20 360 | } 361 | } else { 362 | rectWidth = containerView.frame.size.width/3 363 | } 364 | } else { 365 | if let maxWidth = maxWidth { 366 | if maxWidth < containerView.frame.size.width { 367 | rectWidth = maxWidth 368 | } else { 369 | rectWidth = containerView.frame.size.width - 10 370 | } 371 | } else { 372 | rectWidth = containerView.frame.size.width*2/3 373 | } 374 | } 375 | 376 | var textSize = CGSize.zero 377 | 378 | if let message = message { 379 | let textParagraphStyle = NSMutableParagraphStyle() 380 | textParagraphStyle.alignment = textAlignment 381 | textParagraphStyle.lineBreakMode = .byWordWrapping 382 | textSize = message.boundingRect(with: CGSize(width: rectWidth, height: 99999.0), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: textFont, NSAttributedString.Key.paragraphStyle: textParagraphStyle], context: nil).size 383 | } 384 | if let customView = customView { 385 | textSize = customView.frame.size 386 | } 387 | if let title = title { 388 | let titleParagraphStyle = NSMutableParagraphStyle() 389 | titleParagraphStyle.lineBreakMode = .byClipping 390 | textSize.height += title.boundingRect(with: CGSize(width: rectWidth, height: 99999.0), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: titleFont, NSAttributedString.Key.paragraphStyle: titleParagraphStyle], context: nil).size.height 391 | } 392 | 393 | bubbleSize = CGSize(width: textSize.width + cornerRadius*2, height: textSize.height + cornerRadius*2) 394 | 395 | var superview = containerView.superview 396 | 397 | if let sv = superview, type(of: sv) === UIWindow.self { 398 | superview = containerView 399 | } 400 | 401 | let targetRelativeOrigin = targetView.superview!.convert(targetView.frame.origin, to:superview) 402 | let containerRelativeOrigin = superview!.convert(containerView.frame.origin, to:superview) 403 | 404 | var pointerY: CGFloat 405 | 406 | 407 | if targetRelativeOrigin.y+targetView.bounds.size.height < containerRelativeOrigin.y { 408 | pointerY = 0 409 | pointDirection = .up 410 | } else if targetRelativeOrigin.y > containerRelativeOrigin.y+containerView.bounds.size.height { 411 | pointerY = containerView.bounds.size.height 412 | pointDirection = .down 413 | } else { 414 | pointDirection = preferredPointDirection 415 | let targetOriginInContainer = targetView.convert(CGPoint(x: 0.0, y: 0.0), to:containerView) 416 | let sizeBelow = containerView.bounds.size.height - targetOriginInContainer.y 417 | if pointDirection == .any { 418 | if sizeBelow > targetOriginInContainer.y { 419 | pointerY = targetOriginInContainer.y + targetView.bounds.size.height 420 | pointDirection = .up 421 | } else { 422 | pointerY = targetOriginInContainer.y 423 | pointDirection = .down 424 | } 425 | } else { 426 | if pointDirection == .down { 427 | pointerY = targetOriginInContainer.y 428 | } else { 429 | pointerY = targetOriginInContainer.y + targetView.bounds.size.height 430 | } 431 | } 432 | } 433 | 434 | let W = containerView.bounds.size.width 435 | 436 | let p = targetView.superview!.convert(targetView.center, to:containerView) 437 | var x_p = p.x 438 | var x_b = x_p - CGFloat(roundf(Float(bubbleSize.width/2))) 439 | if x_b < sidePadding { 440 | x_b = sidePadding 441 | } 442 | if x_b + bubbleSize.width + sidePadding > W { 443 | x_b = W - bubbleSize.width - sidePadding 444 | } 445 | if x_p - pointerSize < x_b + cornerRadius { 446 | x_p = x_b + cornerRadius + pointerSize 447 | } 448 | if x_p + pointerSize > x_b + bubbleSize.width - cornerRadius { 449 | x_p = x_b + bubbleSize.width - cornerRadius - pointerSize 450 | } 451 | 452 | let fullHeight = bubbleSize.height + pointerSize + 10 453 | var y_b: CGFloat 454 | if pointDirection == .up { 455 | y_b = topMargin + pointerY 456 | targetPoint = CGPoint(x: x_p-x_b, y: 0) 457 | } else { 458 | y_b = pointerY - fullHeight 459 | targetPoint = CGPoint(x: x_p-x_b, y: fullHeight-2) 460 | } 461 | 462 | let finalFrame = CGRect(x: x_b-sidePadding, y: y_b, width: bubbleSize.width+sidePadding*2, height: fullHeight) 463 | if animated { 464 | if animation == .slide { 465 | alpha = 0 466 | var startFrame = finalFrame 467 | startFrame.origin.y += 10 468 | frame = startFrame 469 | } else if animation == .pop { 470 | frame = finalFrame 471 | alpha = 0.5 472 | transform = CGAffineTransform(scaleX: 0.75, y: 0.75) 473 | 474 | UIView.animate(withDuration: 0.15) { 475 | self.transform = CGAffineTransform(scaleX: 1.1, y: 1.1) 476 | self.alpha = 1 477 | } completion: { (finish) in 478 | self.popAnimationDidStop() 479 | } 480 | 481 | } 482 | 483 | setNeedsDisplay() 484 | 485 | if animation == .slide { 486 | UIView.animate(withDuration: 0.15, animations: { 487 | self.alpha = 1 488 | self.frame = finalFrame 489 | }, completion: nil) 490 | } 491 | } else { 492 | setNeedsDisplay() 493 | frame = finalFrame 494 | } 495 | } 496 | 497 | @objc func finaliseDismiss() { 498 | autoDismissTimer?.invalidate() 499 | autoDismissTimer = nil 500 | 501 | if let dismissTarget = dismissTarget { 502 | dismissTarget.removeFromSuperview() 503 | self.dismissTarget = nil 504 | } 505 | 506 | removeFromSuperview() 507 | 508 | highlight = false 509 | targetObject = nil 510 | } 511 | 512 | func dismissAnimated(_ animated: Bool) { 513 | isShowing = false 514 | if animated { 515 | var customFrame = frame 516 | customFrame.origin.y += 10 517 | UIView.animate(withDuration: 0.15, delay: 0, options: .showHideTransitionViews, animations: { 518 | self.alpha = 0 519 | self.frame = customFrame 520 | }, completion: { finished in 521 | self.finaliseDismiss() 522 | }) 523 | } else { 524 | finaliseDismiss() 525 | } 526 | } 527 | 528 | @objc func autoDismissAnimatedDidFire(_ theTimer: Timer) { 529 | let animated = (theTimer.userInfo as! [String: Any])["animated"] as! Bool 530 | dismissAnimated(animated) 531 | notifyDelegatePopTipViewWasDismissedByUser() 532 | } 533 | 534 | func autoDismissAnimated(_ animated: Bool, atTimeInterval timeInvertal:TimeInterval) { 535 | autoDismissTimer = Timer.scheduledTimer(timeInterval: timeInvertal, target: self, selector: #selector(autoDismissAnimatedDidFire(_:)), userInfo: ["animated": true], repeats: false) 536 | } 537 | 538 | func notifyDelegatePopTipViewWasDismissedByUser() { 539 | delegate?.popTipViewWasDismissedByUser(self) 540 | } 541 | 542 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 543 | if disableTapToDismiss { 544 | super.touchesBegan(touches, with: event) 545 | return 546 | } 547 | dismissByUser() 548 | } 549 | 550 | @objc func dismissTapAnywhereFired(_ button: UIButton) { 551 | dismissByUser() 552 | } 553 | 554 | func dismissByUser() { 555 | highlight = true 556 | setNeedsDisplay() 557 | dismissAnimated(true) 558 | notifyDelegatePopTipViewWasDismissedByUser() 559 | } 560 | 561 | @objc func popAnimationDidStop() { 562 | UIView.animate(withDuration: 0.1, animations: { 563 | self.transform = CGAffineTransform.identity 564 | }, completion: nil) 565 | } 566 | 567 | func presentAnimatedPointingAtBarButtonItem(_ barButtonItem: UIBarButtonItem, autodismissAtTime time:TimeInterval) { 568 | presentPointingAtBarButtonItem(barButtonItem, animated: true) 569 | autoDismissAnimated(true, atTimeInterval: time) 570 | } 571 | 572 | func presentAnimatedPointingAtView(_ atView: UIView, inView: UIView, autodismissAtTime time:TimeInterval) { 573 | presentPointingAtView(atView, containerView: inView, animated: true) 574 | autoDismissAnimated(true, atTimeInterval: time) 575 | } 576 | } 577 | 578 | -------------------------------------------------------------------------------- /SwiftPopTipView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SwiftPopTipView 4 | // 5 | // Created by Mihael Isaev on 18.12.14. 6 | // Copyright (c) 2014 Mihael Isaev inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | var roundRectButtonPopTipView: SwiftPopTipView? 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | navigationController?.setToolbarHidden(false, animated: false) 18 | let navBarLeftButtonPopTipView = SwiftPopTipView(message: "A message") 19 | navBarLeftButtonPopTipView.presentPointingAtBarButtonItem(navigationItem.leftBarButtonItem!, animated: true) 20 | navBarLeftButtonPopTipView.dismissAnimated(true) 21 | } 22 | 23 | @IBAction func showPopTip(_ sender: AnyObject) { 24 | let popTip = SwiftPopTipView(title: "Hello!", message: "This is the test pop tip view!!!") 25 | popTip.popColor = UIColor(red: 63/255, green: 162/255, blue: 232/255, alpha: 1) 26 | popTip.titleColor = UIColor.white 27 | popTip.textColor = UIColor.white 28 | if type(of: sender) === UIBarButtonItem.self { 29 | popTip.presentAnimatedPointingAtBarButtonItem(sender as! UIBarButtonItem, autodismissAtTime: 2) 30 | } else { 31 | popTip.presentAnimatedPointingAtView(sender as! UIView, inView: view, autodismissAtTime: 2) 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /SwiftPopTipViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.mihaelisaev.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SwiftPopTipViewTests/SwiftPopTipViewTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftPopTipViewTests.swift 3 | // SwiftPopTipViewTests 4 | // 5 | // Created by mihael on 18.12.14. 6 | // Copyright (c) 2014 Mihael Isaev inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class SwiftPopTipViewTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------