├── .gitignore ├── LinkTextView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── LinkTextView ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── first.imageset │ │ ├── Contents.json │ │ └── first.pdf │ └── second.imageset │ │ ├── Contents.json │ │ └── second.pdf ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── FirstViewController.swift ├── Info.plist ├── LinkTextView.swift ├── SecondViewController.swift └── TouchUpDownGestureRecognizer.swift ├── LinkTextViewTests ├── Info.plist └── LinkTextViewTests.swift ├── LinkTextViewUITests ├── Info.plist └── LinkTextViewUITests.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | xcuserdata 2 | -------------------------------------------------------------------------------- /LinkTextView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CEA786401BDA375B00682F9B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA7863F1BDA375B00682F9B /* AppDelegate.swift */; }; 11 | CEA786421BDA375B00682F9B /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA786411BDA375B00682F9B /* FirstViewController.swift */; }; 12 | CEA786441BDA375B00682F9B /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA786431BDA375B00682F9B /* SecondViewController.swift */; }; 13 | CEA786471BDA375B00682F9B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEA786451BDA375B00682F9B /* Main.storyboard */; }; 14 | CEA786491BDA375B00682F9B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CEA786481BDA375B00682F9B /* Assets.xcassets */; }; 15 | CEA7864C1BDA375B00682F9B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEA7864A1BDA375B00682F9B /* LaunchScreen.storyboard */; }; 16 | CEA786571BDA375B00682F9B /* LinkTextViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA786561BDA375B00682F9B /* LinkTextViewTests.swift */; }; 17 | CEA786621BDA375B00682F9B /* LinkTextViewUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA786611BDA375B00682F9B /* LinkTextViewUITests.swift */; }; 18 | CEA786701BDA37F200682F9B /* LinkTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA7866F1BDA37F200682F9B /* LinkTextView.swift */; }; 19 | CEA786721BDA380400682F9B /* TouchUpDownGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA786711BDA380400682F9B /* TouchUpDownGestureRecognizer.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | CEA786531BDA375B00682F9B /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = CEA786341BDA375B00682F9B /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = CEA7863B1BDA375B00682F9B; 28 | remoteInfo = LinkTextView; 29 | }; 30 | CEA7865E1BDA375B00682F9B /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = CEA786341BDA375B00682F9B /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = CEA7863B1BDA375B00682F9B; 35 | remoteInfo = LinkTextView; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | CEA7863C1BDA375B00682F9B /* LinkTextView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LinkTextView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | CEA7863F1BDA375B00682F9B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 42 | CEA786411BDA375B00682F9B /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; 43 | CEA786431BDA375B00682F9B /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; 44 | CEA786461BDA375B00682F9B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 45 | CEA786481BDA375B00682F9B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 46 | CEA7864B1BDA375B00682F9B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 47 | CEA7864D1BDA375B00682F9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | CEA786521BDA375B00682F9B /* LinkTextViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LinkTextViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | CEA786561BDA375B00682F9B /* LinkTextViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkTextViewTests.swift; sourceTree = ""; }; 50 | CEA786581BDA375B00682F9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | CEA7865D1BDA375B00682F9B /* LinkTextViewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LinkTextViewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | CEA786611BDA375B00682F9B /* LinkTextViewUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkTextViewUITests.swift; sourceTree = ""; }; 53 | CEA786631BDA375B00682F9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | CEA7866F1BDA37F200682F9B /* LinkTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkTextView.swift; sourceTree = ""; }; 55 | CEA786711BDA380400682F9B /* TouchUpDownGestureRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchUpDownGestureRecognizer.swift; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | CEA786391BDA375B00682F9B /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | CEA7864F1BDA375B00682F9B /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | CEA7865A1BDA375B00682F9B /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | /* End PBXFrameworksBuildPhase section */ 81 | 82 | /* Begin PBXGroup section */ 83 | CEA786331BDA375B00682F9B = { 84 | isa = PBXGroup; 85 | children = ( 86 | CEA7863E1BDA375B00682F9B /* LinkTextView */, 87 | CEA786551BDA375B00682F9B /* LinkTextViewTests */, 88 | CEA786601BDA375B00682F9B /* LinkTextViewUITests */, 89 | CEA7863D1BDA375B00682F9B /* Products */, 90 | ); 91 | sourceTree = ""; 92 | }; 93 | CEA7863D1BDA375B00682F9B /* Products */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | CEA7863C1BDA375B00682F9B /* LinkTextView.app */, 97 | CEA786521BDA375B00682F9B /* LinkTextViewTests.xctest */, 98 | CEA7865D1BDA375B00682F9B /* LinkTextViewUITests.xctest */, 99 | ); 100 | name = Products; 101 | sourceTree = ""; 102 | }; 103 | CEA7863E1BDA375B00682F9B /* LinkTextView */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | CEA7863F1BDA375B00682F9B /* AppDelegate.swift */, 107 | CEA786411BDA375B00682F9B /* FirstViewController.swift */, 108 | CEA786431BDA375B00682F9B /* SecondViewController.swift */, 109 | CEA786451BDA375B00682F9B /* Main.storyboard */, 110 | CEA786481BDA375B00682F9B /* Assets.xcassets */, 111 | CEA7864A1BDA375B00682F9B /* LaunchScreen.storyboard */, 112 | CEA7864D1BDA375B00682F9B /* Info.plist */, 113 | CEA7866F1BDA37F200682F9B /* LinkTextView.swift */, 114 | CEA786711BDA380400682F9B /* TouchUpDownGestureRecognizer.swift */, 115 | ); 116 | path = LinkTextView; 117 | sourceTree = ""; 118 | }; 119 | CEA786551BDA375B00682F9B /* LinkTextViewTests */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | CEA786561BDA375B00682F9B /* LinkTextViewTests.swift */, 123 | CEA786581BDA375B00682F9B /* Info.plist */, 124 | ); 125 | path = LinkTextViewTests; 126 | sourceTree = ""; 127 | }; 128 | CEA786601BDA375B00682F9B /* LinkTextViewUITests */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | CEA786611BDA375B00682F9B /* LinkTextViewUITests.swift */, 132 | CEA786631BDA375B00682F9B /* Info.plist */, 133 | ); 134 | path = LinkTextViewUITests; 135 | sourceTree = ""; 136 | }; 137 | /* End PBXGroup section */ 138 | 139 | /* Begin PBXNativeTarget section */ 140 | CEA7863B1BDA375B00682F9B /* LinkTextView */ = { 141 | isa = PBXNativeTarget; 142 | buildConfigurationList = CEA786661BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextView" */; 143 | buildPhases = ( 144 | CEA786381BDA375B00682F9B /* Sources */, 145 | CEA786391BDA375B00682F9B /* Frameworks */, 146 | CEA7863A1BDA375B00682F9B /* Resources */, 147 | ); 148 | buildRules = ( 149 | ); 150 | dependencies = ( 151 | ); 152 | name = LinkTextView; 153 | productName = LinkTextView; 154 | productReference = CEA7863C1BDA375B00682F9B /* LinkTextView.app */; 155 | productType = "com.apple.product-type.application"; 156 | }; 157 | CEA786511BDA375B00682F9B /* LinkTextViewTests */ = { 158 | isa = PBXNativeTarget; 159 | buildConfigurationList = CEA786691BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextViewTests" */; 160 | buildPhases = ( 161 | CEA7864E1BDA375B00682F9B /* Sources */, 162 | CEA7864F1BDA375B00682F9B /* Frameworks */, 163 | CEA786501BDA375B00682F9B /* Resources */, 164 | ); 165 | buildRules = ( 166 | ); 167 | dependencies = ( 168 | CEA786541BDA375B00682F9B /* PBXTargetDependency */, 169 | ); 170 | name = LinkTextViewTests; 171 | productName = LinkTextViewTests; 172 | productReference = CEA786521BDA375B00682F9B /* LinkTextViewTests.xctest */; 173 | productType = "com.apple.product-type.bundle.unit-test"; 174 | }; 175 | CEA7865C1BDA375B00682F9B /* LinkTextViewUITests */ = { 176 | isa = PBXNativeTarget; 177 | buildConfigurationList = CEA7866C1BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextViewUITests" */; 178 | buildPhases = ( 179 | CEA786591BDA375B00682F9B /* Sources */, 180 | CEA7865A1BDA375B00682F9B /* Frameworks */, 181 | CEA7865B1BDA375B00682F9B /* Resources */, 182 | ); 183 | buildRules = ( 184 | ); 185 | dependencies = ( 186 | CEA7865F1BDA375B00682F9B /* PBXTargetDependency */, 187 | ); 188 | name = LinkTextViewUITests; 189 | productName = LinkTextViewUITests; 190 | productReference = CEA7865D1BDA375B00682F9B /* LinkTextViewUITests.xctest */; 191 | productType = "com.apple.product-type.bundle.ui-testing"; 192 | }; 193 | /* End PBXNativeTarget section */ 194 | 195 | /* Begin PBXProject section */ 196 | CEA786341BDA375B00682F9B /* Project object */ = { 197 | isa = PBXProject; 198 | attributes = { 199 | LastSwiftUpdateCheck = 0710; 200 | LastUpgradeCheck = 0710; 201 | ORGANIZATIONNAME = vasily.jp; 202 | TargetAttributes = { 203 | CEA7863B1BDA375B00682F9B = { 204 | CreatedOnToolsVersion = 7.1; 205 | }; 206 | CEA786511BDA375B00682F9B = { 207 | CreatedOnToolsVersion = 7.1; 208 | TestTargetID = CEA7863B1BDA375B00682F9B; 209 | }; 210 | CEA7865C1BDA375B00682F9B = { 211 | CreatedOnToolsVersion = 7.1; 212 | TestTargetID = CEA7863B1BDA375B00682F9B; 213 | }; 214 | }; 215 | }; 216 | buildConfigurationList = CEA786371BDA375B00682F9B /* Build configuration list for PBXProject "LinkTextView" */; 217 | compatibilityVersion = "Xcode 3.2"; 218 | developmentRegion = English; 219 | hasScannedForEncodings = 0; 220 | knownRegions = ( 221 | en, 222 | Base, 223 | ); 224 | mainGroup = CEA786331BDA375B00682F9B; 225 | productRefGroup = CEA7863D1BDA375B00682F9B /* Products */; 226 | projectDirPath = ""; 227 | projectRoot = ""; 228 | targets = ( 229 | CEA7863B1BDA375B00682F9B /* LinkTextView */, 230 | CEA786511BDA375B00682F9B /* LinkTextViewTests */, 231 | CEA7865C1BDA375B00682F9B /* LinkTextViewUITests */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | CEA7863A1BDA375B00682F9B /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | CEA7864C1BDA375B00682F9B /* LaunchScreen.storyboard in Resources */, 242 | CEA786491BDA375B00682F9B /* Assets.xcassets in Resources */, 243 | CEA786471BDA375B00682F9B /* Main.storyboard in Resources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | CEA786501BDA375B00682F9B /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | CEA7865B1BDA375B00682F9B /* Resources */ = { 255 | isa = PBXResourcesBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | /* End PBXResourcesBuildPhase section */ 262 | 263 | /* Begin PBXSourcesBuildPhase section */ 264 | CEA786381BDA375B00682F9B /* Sources */ = { 265 | isa = PBXSourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | CEA786441BDA375B00682F9B /* SecondViewController.swift in Sources */, 269 | CEA786401BDA375B00682F9B /* AppDelegate.swift in Sources */, 270 | CEA786421BDA375B00682F9B /* FirstViewController.swift in Sources */, 271 | CEA786721BDA380400682F9B /* TouchUpDownGestureRecognizer.swift in Sources */, 272 | CEA786701BDA37F200682F9B /* LinkTextView.swift in Sources */, 273 | ); 274 | runOnlyForDeploymentPostprocessing = 0; 275 | }; 276 | CEA7864E1BDA375B00682F9B /* Sources */ = { 277 | isa = PBXSourcesBuildPhase; 278 | buildActionMask = 2147483647; 279 | files = ( 280 | CEA786571BDA375B00682F9B /* LinkTextViewTests.swift in Sources */, 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | }; 284 | CEA786591BDA375B00682F9B /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | CEA786621BDA375B00682F9B /* LinkTextViewUITests.swift in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | /* End PBXSourcesBuildPhase section */ 293 | 294 | /* Begin PBXTargetDependency section */ 295 | CEA786541BDA375B00682F9B /* PBXTargetDependency */ = { 296 | isa = PBXTargetDependency; 297 | target = CEA7863B1BDA375B00682F9B /* LinkTextView */; 298 | targetProxy = CEA786531BDA375B00682F9B /* PBXContainerItemProxy */; 299 | }; 300 | CEA7865F1BDA375B00682F9B /* PBXTargetDependency */ = { 301 | isa = PBXTargetDependency; 302 | target = CEA7863B1BDA375B00682F9B /* LinkTextView */; 303 | targetProxy = CEA7865E1BDA375B00682F9B /* PBXContainerItemProxy */; 304 | }; 305 | /* End PBXTargetDependency section */ 306 | 307 | /* Begin PBXVariantGroup section */ 308 | CEA786451BDA375B00682F9B /* Main.storyboard */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | CEA786461BDA375B00682F9B /* Base */, 312 | ); 313 | name = Main.storyboard; 314 | sourceTree = ""; 315 | }; 316 | CEA7864A1BDA375B00682F9B /* LaunchScreen.storyboard */ = { 317 | isa = PBXVariantGroup; 318 | children = ( 319 | CEA7864B1BDA375B00682F9B /* Base */, 320 | ); 321 | name = LaunchScreen.storyboard; 322 | sourceTree = ""; 323 | }; 324 | /* End PBXVariantGroup section */ 325 | 326 | /* Begin XCBuildConfiguration section */ 327 | CEA786641BDA375B00682F9B /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ALWAYS_SEARCH_USER_PATHS = NO; 331 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 332 | CLANG_CXX_LIBRARY = "libc++"; 333 | CLANG_ENABLE_MODULES = YES; 334 | CLANG_ENABLE_OBJC_ARC = YES; 335 | CLANG_WARN_BOOL_CONVERSION = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 | CLANG_WARN_EMPTY_BODY = YES; 339 | CLANG_WARN_ENUM_CONVERSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN_UNREACHABLE_CODE = YES; 343 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 344 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 345 | COPY_PHASE_STRIP = NO; 346 | DEBUG_INFORMATION_FORMAT = dwarf; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | ENABLE_TESTABILITY = YES; 349 | GCC_C_LANGUAGE_STANDARD = gnu99; 350 | GCC_DYNAMIC_NO_PIC = NO; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_OPTIMIZATION_LEVEL = 0; 353 | GCC_PREPROCESSOR_DEFINITIONS = ( 354 | "DEBUG=1", 355 | "$(inherited)", 356 | ); 357 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 358 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 359 | GCC_WARN_UNDECLARED_SELECTOR = YES; 360 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 361 | GCC_WARN_UNUSED_FUNCTION = YES; 362 | GCC_WARN_UNUSED_VARIABLE = YES; 363 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 364 | MTL_ENABLE_DEBUG_INFO = YES; 365 | ONLY_ACTIVE_ARCH = YES; 366 | SDKROOT = iphoneos; 367 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 368 | }; 369 | name = Debug; 370 | }; 371 | CEA786651BDA375B00682F9B /* Release */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ALWAYS_SEARCH_USER_PATHS = NO; 375 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 376 | CLANG_CXX_LIBRARY = "libc++"; 377 | CLANG_ENABLE_MODULES = YES; 378 | CLANG_ENABLE_OBJC_ARC = YES; 379 | CLANG_WARN_BOOL_CONVERSION = YES; 380 | CLANG_WARN_CONSTANT_CONVERSION = YES; 381 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 382 | CLANG_WARN_EMPTY_BODY = YES; 383 | CLANG_WARN_ENUM_CONVERSION = YES; 384 | CLANG_WARN_INT_CONVERSION = YES; 385 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 386 | CLANG_WARN_UNREACHABLE_CODE = YES; 387 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 388 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 389 | COPY_PHASE_STRIP = NO; 390 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 391 | ENABLE_NS_ASSERTIONS = NO; 392 | ENABLE_STRICT_OBJC_MSGSEND = YES; 393 | GCC_C_LANGUAGE_STANDARD = gnu99; 394 | GCC_NO_COMMON_BLOCKS = YES; 395 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 396 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 397 | GCC_WARN_UNDECLARED_SELECTOR = YES; 398 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 399 | GCC_WARN_UNUSED_FUNCTION = YES; 400 | GCC_WARN_UNUSED_VARIABLE = YES; 401 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 402 | MTL_ENABLE_DEBUG_INFO = NO; 403 | SDKROOT = iphoneos; 404 | VALIDATE_PRODUCT = YES; 405 | }; 406 | name = Release; 407 | }; 408 | CEA786671BDA375B00682F9B /* Debug */ = { 409 | isa = XCBuildConfiguration; 410 | buildSettings = { 411 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 412 | INFOPLIST_FILE = LinkTextView/Info.plist; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 414 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextView; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | }; 417 | name = Debug; 418 | }; 419 | CEA786681BDA375B00682F9B /* Release */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 423 | INFOPLIST_FILE = LinkTextView/Info.plist; 424 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 425 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextView; 426 | PRODUCT_NAME = "$(TARGET_NAME)"; 427 | }; 428 | name = Release; 429 | }; 430 | CEA7866A1BDA375B00682F9B /* Debug */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | BUNDLE_LOADER = "$(TEST_HOST)"; 434 | INFOPLIST_FILE = LinkTextViewTests/Info.plist; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 436 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextViewTests; 437 | PRODUCT_NAME = "$(TARGET_NAME)"; 438 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LinkTextView.app/LinkTextView"; 439 | }; 440 | name = Debug; 441 | }; 442 | CEA7866B1BDA375B00682F9B /* Release */ = { 443 | isa = XCBuildConfiguration; 444 | buildSettings = { 445 | BUNDLE_LOADER = "$(TEST_HOST)"; 446 | INFOPLIST_FILE = LinkTextViewTests/Info.plist; 447 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 448 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextViewTests; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LinkTextView.app/LinkTextView"; 451 | }; 452 | name = Release; 453 | }; 454 | CEA7866D1BDA375B00682F9B /* Debug */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | INFOPLIST_FILE = LinkTextViewUITests/Info.plist; 458 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 459 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextViewUITests; 460 | PRODUCT_NAME = "$(TARGET_NAME)"; 461 | TEST_TARGET_NAME = LinkTextView; 462 | USES_XCTRUNNER = YES; 463 | }; 464 | name = Debug; 465 | }; 466 | CEA7866E1BDA375B00682F9B /* Release */ = { 467 | isa = XCBuildConfiguration; 468 | buildSettings = { 469 | INFOPLIST_FILE = LinkTextViewUITests/Info.plist; 470 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 471 | PRODUCT_BUNDLE_IDENTIFIER = vasily.jp.LinkTextViewUITests; 472 | PRODUCT_NAME = "$(TARGET_NAME)"; 473 | TEST_TARGET_NAME = LinkTextView; 474 | USES_XCTRUNNER = YES; 475 | }; 476 | name = Release; 477 | }; 478 | /* End XCBuildConfiguration section */ 479 | 480 | /* Begin XCConfigurationList section */ 481 | CEA786371BDA375B00682F9B /* Build configuration list for PBXProject "LinkTextView" */ = { 482 | isa = XCConfigurationList; 483 | buildConfigurations = ( 484 | CEA786641BDA375B00682F9B /* Debug */, 485 | CEA786651BDA375B00682F9B /* Release */, 486 | ); 487 | defaultConfigurationIsVisible = 0; 488 | defaultConfigurationName = Release; 489 | }; 490 | CEA786661BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextView" */ = { 491 | isa = XCConfigurationList; 492 | buildConfigurations = ( 493 | CEA786671BDA375B00682F9B /* Debug */, 494 | CEA786681BDA375B00682F9B /* Release */, 495 | ); 496 | defaultConfigurationIsVisible = 0; 497 | defaultConfigurationName = Release; 498 | }; 499 | CEA786691BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextViewTests" */ = { 500 | isa = XCConfigurationList; 501 | buildConfigurations = ( 502 | CEA7866A1BDA375B00682F9B /* Debug */, 503 | CEA7866B1BDA375B00682F9B /* Release */, 504 | ); 505 | defaultConfigurationIsVisible = 0; 506 | defaultConfigurationName = Release; 507 | }; 508 | CEA7866C1BDA375B00682F9B /* Build configuration list for PBXNativeTarget "LinkTextViewUITests" */ = { 509 | isa = XCConfigurationList; 510 | buildConfigurations = ( 511 | CEA7866D1BDA375B00682F9B /* Debug */, 512 | CEA7866E1BDA375B00682F9B /* Release */, 513 | ); 514 | defaultConfigurationIsVisible = 0; 515 | defaultConfigurationName = Release; 516 | }; 517 | /* End XCConfigurationList section */ 518 | }; 519 | rootObject = CEA786341BDA375B00682F9B /* Project object */; 520 | } 521 | -------------------------------------------------------------------------------- /LinkTextView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LinkTextView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LinkTextView 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. 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 | -------------------------------------------------------------------------------- /LinkTextView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /LinkTextView/Assets.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /LinkTextView/Assets.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WorldDownTown/LinkTextView/fbad20f3d67836d2e06662804021a1cf3bf95e5d/LinkTextView/Assets.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /LinkTextView/Assets.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /LinkTextView/Assets.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WorldDownTown/LinkTextView/fbad20f3d67836d2e06662804021a1cf3bf95e5d/LinkTextView/Assets.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /LinkTextView/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 | 29 | -------------------------------------------------------------------------------- /LinkTextView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | チュール×ロゴトップス 33 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | チュール×ロゴトップス 61 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 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 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | チュール×ロゴトップス 146 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | チュール×ロゴトップス 232 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | チュール×ロゴトップス 260 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | チュール×ロゴトップス 288 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | チュール×ロゴトップス 315 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | チュール×ロゴトップス 344 | #ロゴ #ロゴニット #チュールスカート #ダッフルコート #スニーカー #コーデュロイ #ファーバッグ #クラッチバッグ #時計 #アースカラー 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | -------------------------------------------------------------------------------- /LinkTextView/FirstViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.swift 3 | // LinkTextView 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FirstViewController: UIViewController { 12 | 13 | @IBOutlet private var textViews: [UITextView]! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | setupTextView() 19 | } 20 | 21 | private func setupTextView() { 22 | 23 | let linkKeywords = ["#ロゴ", "#ロゴニット", "#チュールスカート", "#ダッフルコート", "#スニーカー", "#コーデュロイ", "#ファーバッグ", "#クラッチバッグ", "#時計", "#アースカラー"] 24 | 25 | let url = NSURL(string: "http://google.co.jp")! 26 | for textView in textViews { 27 | let string = textView.attributedText.string 28 | let mutableAttributedString = textView.attributedText.mutableCopy() as! NSMutableAttributedString 29 | for keyword in linkKeywords { 30 | let range = (string as NSString).rangeOfString(keyword) 31 | mutableAttributedString.addAttribute(NSLinkAttributeName, value: url, range: range) 32 | } 33 | textView.attributedText = mutableAttributedString 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LinkTextView/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 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /LinkTextView/LinkTextView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LinkTextView.swift 3 | // LinkTextView 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class LinkTextView: UITextView { 12 | 13 | static let LinkKey = "LinkKey" 14 | var linkClickedBlock: ((string: String) -> Void)? 15 | private var selectedStringRange: NSRange? 16 | 17 | required init?(coder aDecoder: NSCoder) { 18 | super.init(coder: aDecoder) 19 | 20 | editable = false 21 | selectable = false 22 | scrollEnabled = false 23 | 24 | let recognizer = TouchUpDownGestureRecognizer(target: self, action: "handleTouchUpDownGesture:") 25 | addGestureRecognizer(recognizer) 26 | } 27 | } 28 | 29 | 30 | // MARK: - public 31 | 32 | extension LinkTextView { 33 | 34 | func handleTouchUpDownGesture(recognizer: TouchUpDownGestureRecognizer) { 35 | switch recognizer.state { 36 | case .Began: 37 | touchDownWithRecognizer(recognizer) 38 | case .Changed: 39 | break 40 | case .Ended: 41 | touchUpWithRecognizer(recognizer) 42 | default: 43 | touchCancelWithRecognizer(recognizer) 44 | } 45 | } 46 | } 47 | 48 | 49 | // MARK: - private 50 | 51 | extension LinkTextView { 52 | 53 | private func touchDownWithRecognizer(recognizer: TouchUpDownGestureRecognizer) { 54 | if let range = selectedLinkRangeWithRecognizer(recognizer) { 55 | selectedStringRange = range 56 | // リンクをタップした場合はハイライトさせる 57 | attributedText = attributedText(range: range, highlighted: true) 58 | setNeedsDisplay() 59 | } 60 | } 61 | 62 | private func touchUpWithRecognizer(recognizer: TouchUpDownGestureRecognizer) { 63 | if let selectedStringRange = selectedStringRange, linkClickedBlock = linkClickedBlock { 64 | let string = (attributedText.string as NSString).substringWithRange(selectedStringRange) 65 | linkClickedBlock(string: string) 66 | } 67 | 68 | if let range = selectedStringRange { 69 | // ハイライトした文字列を戻す 70 | attributedText = attributedText(range: range, highlighted: false) 71 | setNeedsDisplay() 72 | } 73 | selectedStringRange = nil 74 | } 75 | 76 | private func touchCancelWithRecognizer(recognizer: TouchUpDownGestureRecognizer) { 77 | if let range = selectedStringRange { 78 | // ハイライトした文字列を戻す 79 | attributedText = attributedText(range: range, highlighted: false) 80 | setNeedsDisplay() 81 | } 82 | selectedStringRange = nil 83 | } 84 | 85 | /** 86 | 選択したリンク文字列のrangeを返す 87 | 88 | - parameter recognizer: ジェスチャーレコグナイザ 89 | 90 | - returns: タップしたリンク文字列のNSRange。リンク出ない場合はnil 91 | */ 92 | private func selectedLinkRangeWithRecognizer(recognizer: TouchUpDownGestureRecognizer) -> NSRange? { 93 | var location = recognizer.locationInView(self) 94 | location.y -= textContainerInset.top // タッチ位置がtextContainerInsetの分だけズレるので調整 95 | location.x -= textContainerInset.left 96 | 97 | let characterIndex = layoutManager.characterIndexForPoint( // タッチした位置の文字列のindex 98 | location, 99 | inTextContainer: textContainer, 100 | fractionOfDistanceBetweenInsertionPoints: nil) 101 | 102 | // 指定した位置と属性に該当するリンク文字列のNSRangeをrangeに格納する 103 | var range = NSMakeRange(0, 0) 104 | let object = attributedText.attribute( 105 | LinkTextView.LinkKey, 106 | atIndex: characterIndex, 107 | effectiveRange: &range) 108 | 109 | return (object == nil) ? nil : range 110 | } 111 | 112 | private func attributedText(range range: NSRange, highlighted: Bool) -> NSAttributedString { 113 | var attributes = attributedText.attributesAtIndex(range.location, effectiveRange: nil) 114 | let mutableAttributedString = attributedText.mutableCopy() as! NSMutableAttributedString 115 | let color = highlighted ? UIColor.redColor() : UIColor.blueColor() 116 | attributes[NSForegroundColorAttributeName] = color 117 | mutableAttributedString.setAttributes(attributes, range: range) 118 | return mutableAttributedString 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /LinkTextView/SecondViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.swift 3 | // LinkTextView 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondViewController: UIViewController { 12 | 13 | @IBOutlet private var textViews: [LinkTextView]! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | setupTextView() 19 | } 20 | 21 | private func setupTextView() { 22 | 23 | let linkKeywords = ["#ロゴ", "#ロゴニット", "#チュールスカート", "#ダッフルコート", "#スニーカー", "#コーデュロイ", "#ファーバッグ", "#クラッチバッグ", "#時計", "#アースカラー"] 24 | 25 | let attributes = [ 26 | NSForegroundColorAttributeName: UIColor.blueColor(), 27 | LinkTextView.LinkKey: "linked", 28 | ] 29 | 30 | 31 | for textView in textViews { 32 | 33 | // TextViewにリンクを設定 34 | let string = textView.attributedText.string 35 | let mutableAttributedString = textView.attributedText.mutableCopy() as! NSMutableAttributedString 36 | for keyword in linkKeywords { 37 | let range = (string as NSString).rangeOfString(keyword) 38 | mutableAttributedString.addAttributes(attributes, range: range) 39 | } 40 | textView.attributedText = mutableAttributedString 41 | 42 | textView.linkClickedBlock = { [weak self] (string: String) in 43 | // タップした文字列をアラート表示 44 | let alertController = UIAlertController(title: string, message: nil, preferredStyle: .Alert) 45 | let action = UIAlertAction(title: "close", style: .Cancel, handler: nil) 46 | alertController.addAction(action) 47 | self?.presentViewController(alertController, animated: true, completion: nil) 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /LinkTextView/TouchUpDownGestureRecognizer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchUpDownGestureRecognizer.swift 3 | // LinkTextView 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import UIKit.UIGestureRecognizerSubclass 11 | 12 | class TouchUpDownGestureRecognizer: UIGestureRecognizer { 13 | 14 | override func touchesBegan(touches: Set, withEvent event: UIEvent) { 15 | super.touchesBegan(touches, withEvent: event) 16 | 17 | state = .Began 18 | } 19 | 20 | override func touchesMoved(touches: Set, withEvent event: UIEvent) { 21 | super.touchesMoved(touches, withEvent: event) 22 | 23 | if let touch = touches.first { 24 | let beforePoint = touch.previousLocationInView(view) 25 | let afterPoint = touch.locationInView(view) 26 | if !CGPointEqualToPoint(beforePoint, afterPoint) { 27 | // タッチした指が動いたらキャンセル 28 | // 3D Touch 対応端末では touch.force の変化でも touchesMoved:withEvent: が呼ばれてしまうので、厳密にtouchの位置の変化を監視する 29 | state = .Cancelled 30 | } 31 | } 32 | } 33 | 34 | override func touchesEnded(touches: Set, withEvent event: UIEvent) { 35 | super.touchesEnded(touches, withEvent: event) 36 | 37 | state = .Ended 38 | } 39 | 40 | override func touchesCancelled(touches: Set, withEvent event: UIEvent) { 41 | super.touchesCancelled(touches, withEvent: event) 42 | 43 | state = .Cancelled 44 | } 45 | 46 | override func canPreventGestureRecognizer(preventedGestureRecognizer: UIGestureRecognizer) -> Bool { 47 | if let _ = preventedGestureRecognizer.view as? UIScrollView { 48 | return false 49 | } 50 | return true 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LinkTextViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LinkTextViewTests/LinkTextViewTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LinkTextViewTests.swift 3 | // LinkTextViewTests 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import LinkTextView 11 | 12 | class LinkTextViewTests: 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 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /LinkTextViewUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LinkTextViewUITests/LinkTextViewUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LinkTextViewUITests.swift 3 | // LinkTextViewUITests 4 | // 5 | // Created by shoji on 2015/10/23. 6 | // Copyright © 2015年 vasily.jp. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class LinkTextViewUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LinkTextView - UITextview + Clickable Text 2 | 3 | A simple extension to UITextView that enables clickable text. 4 | Scroll is always enabled as usual for UITextViews but support has been added to observe 5 | touch events at the same time as scroll events. 6 | The user can scroll and perform click actions at the same time. 7 | 8 | ## UITextView 9 | ![UITextView](https://media.giphy.com/media/3o85xwIUHvxJWx4iu4/giphy.gif) 10 | 11 | ## LinkTextView 12 | ![LinkTextView](https://media.giphy.com/media/l0O9ydb94Ddm8YnRK/giphy.gif) 13 | --------------------------------------------------------------------------------