├── .gitignore ├── MultipleTruncationExample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── MultipleTruncationExample ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── MTEAppDelegate.h ├── MTEAppDelegate.m ├── MTEFocusedTruncationRenderer.h ├── MTEFocusedTruncationRenderer.m ├── MTERootViewController.h ├── MTERootViewController.m ├── MTETextView.h ├── MTETextView.m ├── MultipleTruncationExample-Info.plist ├── MultipleTruncationExample-Prefix.pch ├── en.lproj │ └── InfoPlist.strings └── main.m ├── MultipleTruncationExampleTests ├── MultipleTruncationExampleTests-Info.plist ├── MultipleTruncationExampleTests.m └── en.lproj │ └── InfoPlist.strings └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | Code/Secrets.m 20 | -------------------------------------------------------------------------------- /MultipleTruncationExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3D8808691833040200165C83 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D8808681833040200165C83 /* Foundation.framework */; }; 11 | 3D88086B1833040200165C83 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D88086A1833040200165C83 /* CoreGraphics.framework */; }; 12 | 3D88086D1833040200165C83 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D88086C1833040200165C83 /* UIKit.framework */; }; 13 | 3D8808731833040200165C83 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3D8808711833040200165C83 /* InfoPlist.strings */; }; 14 | 3D8808751833040300165C83 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D8808741833040300165C83 /* main.m */; }; 15 | 3D8808791833040300165C83 /* MTEAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D8808781833040300165C83 /* MTEAppDelegate.m */; }; 16 | 3D88087B1833040300165C83 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D88087A1833040300165C83 /* Images.xcassets */; }; 17 | 3D8808821833040300165C83 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D8808811833040300165C83 /* XCTest.framework */; }; 18 | 3D8808831833040300165C83 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D8808681833040200165C83 /* Foundation.framework */; }; 19 | 3D8808841833040300165C83 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D88086C1833040200165C83 /* UIKit.framework */; }; 20 | 3D88088C1833040300165C83 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3D88088A1833040300165C83 /* InfoPlist.strings */; }; 21 | 3D88088E1833040300165C83 /* MultipleTruncationExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D88088D1833040300165C83 /* MultipleTruncationExampleTests.m */; }; 22 | 3D8808991833041700165C83 /* MTERootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D8808981833041700165C83 /* MTERootViewController.m */; }; 23 | 3D88089C1833046900165C83 /* MTETextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D88089B1833046900165C83 /* MTETextView.m */; }; 24 | 3D88089F1833071600165C83 /* MTEFocusedTruncationRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D88089E1833071600165C83 /* MTEFocusedTruncationRenderer.m */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXContainerItemProxy section */ 28 | 3D8808851833040300165C83 /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = 3D88085D1833040200165C83 /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = 3D8808641833040200165C83; 33 | remoteInfo = MultipleTruncationExample; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 3D8808651833040200165C83 /* MultipleTruncationExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultipleTruncationExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 3D8808681833040200165C83 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 40 | 3D88086A1833040200165C83 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 41 | 3D88086C1833040200165C83 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 42 | 3D8808701833040200165C83 /* MultipleTruncationExample-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MultipleTruncationExample-Info.plist"; sourceTree = ""; }; 43 | 3D8808721833040200165C83 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 44 | 3D8808741833040300165C83 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 45 | 3D8808761833040300165C83 /* MultipleTruncationExample-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MultipleTruncationExample-Prefix.pch"; sourceTree = ""; }; 46 | 3D8808771833040300165C83 /* MTEAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTEAppDelegate.h; sourceTree = ""; }; 47 | 3D8808781833040300165C83 /* MTEAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MTEAppDelegate.m; sourceTree = ""; }; 48 | 3D88087A1833040300165C83 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 49 | 3D8808801833040300165C83 /* MultipleTruncationExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MultipleTruncationExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 3D8808811833040300165C83 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 51 | 3D8808891833040300165C83 /* MultipleTruncationExampleTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MultipleTruncationExampleTests-Info.plist"; sourceTree = ""; }; 52 | 3D88088B1833040300165C83 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 53 | 3D88088D1833040300165C83 /* MultipleTruncationExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MultipleTruncationExampleTests.m; sourceTree = ""; }; 54 | 3D8808971833041700165C83 /* MTERootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTERootViewController.h; sourceTree = ""; }; 55 | 3D8808981833041700165C83 /* MTERootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTERootViewController.m; sourceTree = ""; }; 56 | 3D88089A1833046900165C83 /* MTETextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTETextView.h; sourceTree = ""; }; 57 | 3D88089B1833046900165C83 /* MTETextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTETextView.m; sourceTree = ""; }; 58 | 3D88089D1833071600165C83 /* MTEFocusedTruncationRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTEFocusedTruncationRenderer.h; sourceTree = ""; }; 59 | 3D88089E1833071600165C83 /* MTEFocusedTruncationRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTEFocusedTruncationRenderer.m; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | 3D8808621833040200165C83 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | 3D88086B1833040200165C83 /* CoreGraphics.framework in Frameworks */, 68 | 3D88086D1833040200165C83 /* UIKit.framework in Frameworks */, 69 | 3D8808691833040200165C83 /* Foundation.framework in Frameworks */, 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | 3D88087D1833040300165C83 /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | 3D8808821833040300165C83 /* XCTest.framework in Frameworks */, 78 | 3D8808841833040300165C83 /* UIKit.framework in Frameworks */, 79 | 3D8808831833040300165C83 /* Foundation.framework in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 3D88085C1833040200165C83 = { 87 | isa = PBXGroup; 88 | children = ( 89 | 3D88086E1833040200165C83 /* MultipleTruncationExample */, 90 | 3D8808871833040300165C83 /* MultipleTruncationExampleTests */, 91 | 3D8808671833040200165C83 /* Frameworks */, 92 | 3D8808661833040200165C83 /* Products */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | 3D8808661833040200165C83 /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 3D8808651833040200165C83 /* MultipleTruncationExample.app */, 100 | 3D8808801833040300165C83 /* MultipleTruncationExampleTests.xctest */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | 3D8808671833040200165C83 /* Frameworks */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 3D8808681833040200165C83 /* Foundation.framework */, 109 | 3D88086A1833040200165C83 /* CoreGraphics.framework */, 110 | 3D88086C1833040200165C83 /* UIKit.framework */, 111 | 3D8808811833040300165C83 /* XCTest.framework */, 112 | ); 113 | name = Frameworks; 114 | sourceTree = ""; 115 | }; 116 | 3D88086E1833040200165C83 /* MultipleTruncationExample */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 3D8808771833040300165C83 /* MTEAppDelegate.h */, 120 | 3D8808781833040300165C83 /* MTEAppDelegate.m */, 121 | 3D8808971833041700165C83 /* MTERootViewController.h */, 122 | 3D8808981833041700165C83 /* MTERootViewController.m */, 123 | 3D88089A1833046900165C83 /* MTETextView.h */, 124 | 3D88089B1833046900165C83 /* MTETextView.m */, 125 | 3D88089D1833071600165C83 /* MTEFocusedTruncationRenderer.h */, 126 | 3D88089E1833071600165C83 /* MTEFocusedTruncationRenderer.m */, 127 | 3D88087A1833040300165C83 /* Images.xcassets */, 128 | 3D88086F1833040200165C83 /* Supporting Files */, 129 | ); 130 | path = MultipleTruncationExample; 131 | sourceTree = ""; 132 | }; 133 | 3D88086F1833040200165C83 /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 3D8808701833040200165C83 /* MultipleTruncationExample-Info.plist */, 137 | 3D8808711833040200165C83 /* InfoPlist.strings */, 138 | 3D8808741833040300165C83 /* main.m */, 139 | 3D8808761833040300165C83 /* MultipleTruncationExample-Prefix.pch */, 140 | ); 141 | name = "Supporting Files"; 142 | sourceTree = ""; 143 | }; 144 | 3D8808871833040300165C83 /* MultipleTruncationExampleTests */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | 3D88088D1833040300165C83 /* MultipleTruncationExampleTests.m */, 148 | 3D8808881833040300165C83 /* Supporting Files */, 149 | ); 150 | path = MultipleTruncationExampleTests; 151 | sourceTree = ""; 152 | }; 153 | 3D8808881833040300165C83 /* Supporting Files */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | 3D8808891833040300165C83 /* MultipleTruncationExampleTests-Info.plist */, 157 | 3D88088A1833040300165C83 /* InfoPlist.strings */, 158 | ); 159 | name = "Supporting Files"; 160 | sourceTree = ""; 161 | }; 162 | /* End PBXGroup section */ 163 | 164 | /* Begin PBXNativeTarget section */ 165 | 3D8808641833040200165C83 /* MultipleTruncationExample */ = { 166 | isa = PBXNativeTarget; 167 | buildConfigurationList = 3D8808911833040300165C83 /* Build configuration list for PBXNativeTarget "MultipleTruncationExample" */; 168 | buildPhases = ( 169 | 3D8808611833040200165C83 /* Sources */, 170 | 3D8808621833040200165C83 /* Frameworks */, 171 | 3D8808631833040200165C83 /* Resources */, 172 | ); 173 | buildRules = ( 174 | ); 175 | dependencies = ( 176 | ); 177 | name = MultipleTruncationExample; 178 | productName = MultipleTruncationExample; 179 | productReference = 3D8808651833040200165C83 /* MultipleTruncationExample.app */; 180 | productType = "com.apple.product-type.application"; 181 | }; 182 | 3D88087F1833040300165C83 /* MultipleTruncationExampleTests */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = 3D8808941833040300165C83 /* Build configuration list for PBXNativeTarget "MultipleTruncationExampleTests" */; 185 | buildPhases = ( 186 | 3D88087C1833040300165C83 /* Sources */, 187 | 3D88087D1833040300165C83 /* Frameworks */, 188 | 3D88087E1833040300165C83 /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | 3D8808861833040300165C83 /* PBXTargetDependency */, 194 | ); 195 | name = MultipleTruncationExampleTests; 196 | productName = MultipleTruncationExampleTests; 197 | productReference = 3D8808801833040300165C83 /* MultipleTruncationExampleTests.xctest */; 198 | productType = "com.apple.product-type.bundle.unit-test"; 199 | }; 200 | /* End PBXNativeTarget section */ 201 | 202 | /* Begin PBXProject section */ 203 | 3D88085D1833040200165C83 /* Project object */ = { 204 | isa = PBXProject; 205 | attributes = { 206 | CLASSPREFIX = MTE; 207 | LastUpgradeCheck = 0500; 208 | ORGANIZATIONNAME = "Daniel Hammond"; 209 | TargetAttributes = { 210 | 3D88087F1833040300165C83 = { 211 | TestTargetID = 3D8808641833040200165C83; 212 | }; 213 | }; 214 | }; 215 | buildConfigurationList = 3D8808601833040200165C83 /* Build configuration list for PBXProject "MultipleTruncationExample" */; 216 | compatibilityVersion = "Xcode 3.2"; 217 | developmentRegion = English; 218 | hasScannedForEncodings = 0; 219 | knownRegions = ( 220 | en, 221 | ); 222 | mainGroup = 3D88085C1833040200165C83; 223 | productRefGroup = 3D8808661833040200165C83 /* Products */; 224 | projectDirPath = ""; 225 | projectRoot = ""; 226 | targets = ( 227 | 3D8808641833040200165C83 /* MultipleTruncationExample */, 228 | 3D88087F1833040300165C83 /* MultipleTruncationExampleTests */, 229 | ); 230 | }; 231 | /* End PBXProject section */ 232 | 233 | /* Begin PBXResourcesBuildPhase section */ 234 | 3D8808631833040200165C83 /* Resources */ = { 235 | isa = PBXResourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | 3D8808731833040200165C83 /* InfoPlist.strings in Resources */, 239 | 3D88087B1833040300165C83 /* Images.xcassets in Resources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | 3D88087E1833040300165C83 /* Resources */ = { 244 | isa = PBXResourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | 3D88088C1833040300165C83 /* InfoPlist.strings in Resources */, 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | /* End PBXResourcesBuildPhase section */ 252 | 253 | /* Begin PBXSourcesBuildPhase section */ 254 | 3D8808611833040200165C83 /* Sources */ = { 255 | isa = PBXSourcesBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | 3D8808751833040300165C83 /* main.m in Sources */, 259 | 3D8808791833040300165C83 /* MTEAppDelegate.m in Sources */, 260 | 3D88089C1833046900165C83 /* MTETextView.m in Sources */, 261 | 3D88089F1833071600165C83 /* MTEFocusedTruncationRenderer.m in Sources */, 262 | 3D8808991833041700165C83 /* MTERootViewController.m in Sources */, 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | 3D88087C1833040300165C83 /* Sources */ = { 267 | isa = PBXSourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | 3D88088E1833040300165C83 /* MultipleTruncationExampleTests.m in Sources */, 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | /* End PBXSourcesBuildPhase section */ 275 | 276 | /* Begin PBXTargetDependency section */ 277 | 3D8808861833040300165C83 /* PBXTargetDependency */ = { 278 | isa = PBXTargetDependency; 279 | target = 3D8808641833040200165C83 /* MultipleTruncationExample */; 280 | targetProxy = 3D8808851833040300165C83 /* PBXContainerItemProxy */; 281 | }; 282 | /* End PBXTargetDependency section */ 283 | 284 | /* Begin PBXVariantGroup section */ 285 | 3D8808711833040200165C83 /* InfoPlist.strings */ = { 286 | isa = PBXVariantGroup; 287 | children = ( 288 | 3D8808721833040200165C83 /* en */, 289 | ); 290 | name = InfoPlist.strings; 291 | sourceTree = ""; 292 | }; 293 | 3D88088A1833040300165C83 /* InfoPlist.strings */ = { 294 | isa = PBXVariantGroup; 295 | children = ( 296 | 3D88088B1833040300165C83 /* en */, 297 | ); 298 | name = InfoPlist.strings; 299 | sourceTree = ""; 300 | }; 301 | /* End PBXVariantGroup section */ 302 | 303 | /* Begin XCBuildConfiguration section */ 304 | 3D88088F1833040300165C83 /* Debug */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ALWAYS_SEARCH_USER_PATHS = NO; 308 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 309 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 310 | CLANG_CXX_LIBRARY = "libc++"; 311 | CLANG_ENABLE_MODULES = YES; 312 | CLANG_ENABLE_OBJC_ARC = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 316 | CLANG_WARN_EMPTY_BODY = YES; 317 | CLANG_WARN_ENUM_CONVERSION = YES; 318 | CLANG_WARN_INT_CONVERSION = YES; 319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 320 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 321 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 322 | COPY_PHASE_STRIP = NO; 323 | GCC_C_LANGUAGE_STANDARD = gnu99; 324 | GCC_DYNAMIC_NO_PIC = NO; 325 | GCC_OPTIMIZATION_LEVEL = 0; 326 | GCC_PREPROCESSOR_DEFINITIONS = ( 327 | "DEBUG=1", 328 | "$(inherited)", 329 | ); 330 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 331 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 332 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 333 | GCC_WARN_UNDECLARED_SELECTOR = YES; 334 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 335 | GCC_WARN_UNUSED_FUNCTION = YES; 336 | GCC_WARN_UNUSED_VARIABLE = YES; 337 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 338 | ONLY_ACTIVE_ARCH = YES; 339 | SDKROOT = iphoneos; 340 | TARGETED_DEVICE_FAMILY = "1,2"; 341 | }; 342 | name = Debug; 343 | }; 344 | 3D8808901833040300165C83 /* Release */ = { 345 | isa = XCBuildConfiguration; 346 | buildSettings = { 347 | ALWAYS_SEARCH_USER_PATHS = NO; 348 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 349 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 350 | CLANG_CXX_LIBRARY = "libc++"; 351 | CLANG_ENABLE_MODULES = YES; 352 | CLANG_ENABLE_OBJC_ARC = YES; 353 | CLANG_WARN_BOOL_CONVERSION = YES; 354 | CLANG_WARN_CONSTANT_CONVERSION = YES; 355 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 356 | CLANG_WARN_EMPTY_BODY = YES; 357 | CLANG_WARN_ENUM_CONVERSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 360 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 361 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 362 | COPY_PHASE_STRIP = YES; 363 | ENABLE_NS_ASSERTIONS = NO; 364 | GCC_C_LANGUAGE_STANDARD = gnu99; 365 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 366 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 367 | GCC_WARN_UNDECLARED_SELECTOR = YES; 368 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 369 | GCC_WARN_UNUSED_FUNCTION = YES; 370 | GCC_WARN_UNUSED_VARIABLE = YES; 371 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 372 | SDKROOT = iphoneos; 373 | TARGETED_DEVICE_FAMILY = "1,2"; 374 | VALIDATE_PRODUCT = YES; 375 | }; 376 | name = Release; 377 | }; 378 | 3D8808921833040300165C83 /* Debug */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 382 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 383 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 384 | GCC_PREFIX_HEADER = "MultipleTruncationExample/MultipleTruncationExample-Prefix.pch"; 385 | INFOPLIST_FILE = "MultipleTruncationExample/MultipleTruncationExample-Info.plist"; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | WRAPPER_EXTENSION = app; 388 | }; 389 | name = Debug; 390 | }; 391 | 3D8808931833040300165C83 /* Release */ = { 392 | isa = XCBuildConfiguration; 393 | buildSettings = { 394 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 395 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 396 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 397 | GCC_PREFIX_HEADER = "MultipleTruncationExample/MultipleTruncationExample-Prefix.pch"; 398 | INFOPLIST_FILE = "MultipleTruncationExample/MultipleTruncationExample-Info.plist"; 399 | PRODUCT_NAME = "$(TARGET_NAME)"; 400 | WRAPPER_EXTENSION = app; 401 | }; 402 | name = Release; 403 | }; 404 | 3D8808951833040300165C83 /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | buildSettings = { 407 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 408 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MultipleTruncationExample.app/MultipleTruncationExample"; 409 | FRAMEWORK_SEARCH_PATHS = ( 410 | "$(SDKROOT)/Developer/Library/Frameworks", 411 | "$(inherited)", 412 | "$(DEVELOPER_FRAMEWORKS_DIR)", 413 | ); 414 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 415 | GCC_PREFIX_HEADER = "MultipleTruncationExample/MultipleTruncationExample-Prefix.pch"; 416 | GCC_PREPROCESSOR_DEFINITIONS = ( 417 | "DEBUG=1", 418 | "$(inherited)", 419 | ); 420 | INFOPLIST_FILE = "MultipleTruncationExampleTests/MultipleTruncationExampleTests-Info.plist"; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | TEST_HOST = "$(BUNDLE_LOADER)"; 423 | WRAPPER_EXTENSION = xctest; 424 | }; 425 | name = Debug; 426 | }; 427 | 3D8808961833040300165C83 /* Release */ = { 428 | isa = XCBuildConfiguration; 429 | buildSettings = { 430 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 431 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MultipleTruncationExample.app/MultipleTruncationExample"; 432 | FRAMEWORK_SEARCH_PATHS = ( 433 | "$(SDKROOT)/Developer/Library/Frameworks", 434 | "$(inherited)", 435 | "$(DEVELOPER_FRAMEWORKS_DIR)", 436 | ); 437 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 438 | GCC_PREFIX_HEADER = "MultipleTruncationExample/MultipleTruncationExample-Prefix.pch"; 439 | INFOPLIST_FILE = "MultipleTruncationExampleTests/MultipleTruncationExampleTests-Info.plist"; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | TEST_HOST = "$(BUNDLE_LOADER)"; 442 | WRAPPER_EXTENSION = xctest; 443 | }; 444 | name = Release; 445 | }; 446 | /* End XCBuildConfiguration section */ 447 | 448 | /* Begin XCConfigurationList section */ 449 | 3D8808601833040200165C83 /* Build configuration list for PBXProject "MultipleTruncationExample" */ = { 450 | isa = XCConfigurationList; 451 | buildConfigurations = ( 452 | 3D88088F1833040300165C83 /* Debug */, 453 | 3D8808901833040300165C83 /* Release */, 454 | ); 455 | defaultConfigurationIsVisible = 0; 456 | defaultConfigurationName = Release; 457 | }; 458 | 3D8808911833040300165C83 /* Build configuration list for PBXNativeTarget "MultipleTruncationExample" */ = { 459 | isa = XCConfigurationList; 460 | buildConfigurations = ( 461 | 3D8808921833040300165C83 /* Debug */, 462 | 3D8808931833040300165C83 /* Release */, 463 | ); 464 | defaultConfigurationIsVisible = 0; 465 | }; 466 | 3D8808941833040300165C83 /* Build configuration list for PBXNativeTarget "MultipleTruncationExampleTests" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | 3D8808951833040300165C83 /* Debug */, 470 | 3D8808961833040300165C83 /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | }; 474 | /* End XCConfigurationList section */ 475 | }; 476 | rootObject = 3D88085D1833040200165C83 /* Project object */; 477 | } 478 | -------------------------------------------------------------------------------- /MultipleTruncationExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MultipleTruncationExample/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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /MultipleTruncationExample/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /MultipleTruncationExample/MTEAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MTEAppDelegate.h 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MTEAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTEAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MTEAppDelegate.m 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import "MTEAppDelegate.h" 10 | #import "MTERootViewController.h" 11 | 12 | @implementation MTEAppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 17 | self.window.rootViewController = [MTERootViewController new]; 18 | self.window.backgroundColor = [UIColor whiteColor]; 19 | [self.window makeKeyAndVisible]; 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application 24 | { 25 | // 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. 26 | // 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. 27 | } 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application 30 | { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | - (void)applicationWillEnterForeground:(UIApplication *)application 36 | { 37 | // 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. 38 | } 39 | 40 | - (void)applicationDidBecomeActive:(UIApplication *)application 41 | { 42 | // 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. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application 46 | { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTEFocusedTruncationRenderer.h: -------------------------------------------------------------------------------- 1 | // 2 | // MTEFocusedTruncationRenderer.h 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MTEFocusedTruncationRenderer : NSObject 12 | 13 | @property (nonatomic, strong) NSAttributedString *contents; 14 | @property (nonatomic) NSRange focusedRange; 15 | 16 | - (void)drawInRect:(CGRect)rect; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTEFocusedTruncationRenderer.m: -------------------------------------------------------------------------------- 1 | // 2 | // MTEFocusedTruncationRenderer.m 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import "MTEFocusedTruncationRenderer.h" 10 | 11 | @import CoreText; 12 | 13 | @interface MTEFocusedTruncationRenderer () 14 | 15 | @property (nonatomic, strong) NSTextStorage *textStorage; 16 | @property (nonatomic, strong) NSLayoutManager *layoutManager; 17 | @property (nonatomic, strong) NSTextContainer *textContainer; 18 | @property (nonatomic) NSRange selectedRange; 19 | @property (nonatomic) NSRange truncationRange; 20 | @property (nonatomic) BOOL forceTailTruncationRange; // BOOL? 21 | 22 | @end 23 | 24 | @implementation MTEFocusedTruncationRenderer 25 | 26 | - (id)init 27 | { 28 | self = [super init]; 29 | if (self) { 30 | ; 31 | } 32 | return self; 33 | } 34 | 35 | #pragma mark - Drawing 36 | 37 | - (void)drawInRect:(CGRect)rect 38 | { 39 | NSUInteger length = self.textStorage.length; 40 | NSRange focusedRange = self.selectedRange; 41 | 42 | /* 43 | These next two lines aren't in the original demo code that was shown. 44 | 45 | This fixes a bug that happens when you shrink the view down to the point where it triggers the multiple truncation and then 46 | increase the size again, because of your alternate glyph mapping (putting the ellipsis earlier in the string), it will never 47 | expand back out and turn the middle-truncation off. 48 | 49 | In the talk he shrinks the textView but never increases the size again, so it might be a bug in the demo code that they very 50 | carefully didn't show or there is another fix for this somewhere else in the code that isn't visible 51 | */ 52 | 53 | [self invalidateGlyphMappings]; 54 | [self forceLayout]; 55 | 56 | self.textContainer.size = (CGSize){ CGRectGetWidth(rect), CGRectGetHeight(rect) }; 57 | _truncationRange = (NSRange){ 0, 0 }; 58 | _forceTailTruncationRange = false; 59 | 60 | if (length > 0) { 61 | NSRange glyphRange; 62 | CGRect bounds = CGRectZero; 63 | bounds.size = rect.size; 64 | 65 | if (NSMaxRange(focusedRange) > length) { 66 | focusedRange.length = length - focusedRange.location; 67 | } 68 | 69 | if (focusedRange.length > 0) { 70 | [self.layoutManager ensureLayoutForCharacterRange:(NSRange){ 0, NSMaxRange(focusedRange) }]; 71 | } else { 72 | [self.layoutManager ensureLayoutForBoundingRect:bounds inTextContainer:self.textContainer]; 73 | } 74 | 75 | glyphRange = [self.layoutManager glyphRangeForBoundingRect:bounds inTextContainer:self.textContainer]; 76 | 77 | if (glyphRange.length > 0) { 78 | 79 | /* 80 | This has been changed from the code shown in the talk to compare the character range of the truncated glyphs 81 | to the known character range of our focused range. This is because when the ranges intersect the glyph range for 82 | the focused character range is extended to represent all the glyphs that have been truncated making the check for overlap 83 | with the truncated range always true 84 | */ 85 | 86 | self.textContainer.size = bounds.size; 87 | 88 | if (focusedRange.length > 0) { 89 | NSUInteger location = [self.layoutManager glyphIndexForCharacterAtIndex:focusedRange.location]; 90 | NSRange glyphRange = [self.layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:location]; 91 | NSRange tailTruncatedCharacterRange = [self.layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL]; 92 | 93 | if (NSIntersectionRange((NSRange){ 0, NSMaxRange(focusedRange) }, tailTruncatedCharacterRange).length > 0) { 94 | // Focused range is truncated out 95 | if (focusedRange.location > 1) { 96 | NSString *string = [self.textStorage string]; 97 | 98 | // Move back and make space for ellipsis 99 | _truncationRange.location = [string rangeOfComposedCharacterSequenceAtIndex:(focusedRange.location-1)].location; 100 | _truncationRange.length = focusedRange.location - _truncationRange.location; 101 | 102 | while ((_truncationRange.location > 0) && (NSIntersectionRange(focusedRange, tailTruncatedCharacterRange).length > 0)) { 103 | _truncationRange.location = [string rangeOfComposedCharacterSequenceAtIndex:(_truncationRange.location - 1)].location; 104 | _truncationRange.length = focusedRange.location - _truncationRange.location; 105 | [self invalidateGlyphMappings]; 106 | [self forceLayout]; 107 | NSUInteger location = [self.layoutManager glyphIndexForCharacterAtIndex:focusedRange.location]; 108 | NSRange truncatedGlyphRange = [self.layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:location]; 109 | tailTruncatedCharacterRange = [self.layoutManager characterRangeForGlyphRange:truncatedGlyphRange actualGlyphRange:NULL]; 110 | } 111 | } else { 112 | _truncationRange = (NSRange){0, focusedRange.location}; 113 | [self invalidateGlyphMappings]; 114 | [self forceLayout]; 115 | NSUInteger focusedLocation = [self.layoutManager glyphIndexForCharacterAtIndex:focusedRange.location]; 116 | tailTruncatedCharacterRange = [self.layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:focusedLocation]; 117 | } 118 | 119 | // Make sure the tail truncation range is still right after the focused range 120 | if (NSMaxRange(focusedRange) != tailTruncatedCharacterRange.location) { 121 | _forceTailTruncationRange = true; 122 | [self invalidateGlyphMappings]; 123 | } 124 | } 125 | 126 | glyphRange = [self.layoutManager glyphRangeForBoundingRect:bounds inTextContainer:self.textContainer]; 127 | } 128 | 129 | [self.layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:rect.origin]; 130 | [self.layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:rect.origin]; 131 | } 132 | } 133 | } 134 | 135 | #pragma mark - Focused Range 136 | 137 | - (NSRange)focusedRange 138 | { 139 | return _selectedRange; 140 | } 141 | 142 | - (void)setFocusedRange:(NSRange)focusedRange 143 | { 144 | _selectedRange = focusedRange; 145 | [self.textStorage beginEditing]; 146 | [self.textStorage addAttribute:NSBackgroundColorAttributeName value:[UIColor lightGrayColor] range:focusedRange]; 147 | [self.textStorage endEditing]; 148 | } 149 | 150 | #pragma mark - Contents 151 | 152 | - (NSAttributedString *)contents 153 | { 154 | return _textStorage; 155 | } 156 | 157 | - (void)setContents:(NSAttributedString *)contents 158 | { 159 | if (!_textStorage) { 160 | _layoutManager = [[NSLayoutManager alloc] init]; 161 | _textContainer = [[NSTextContainer alloc] initWithSize:CGSizeZero]; 162 | _textStorage = [[NSTextStorage alloc] init]; 163 | [_textStorage addLayoutManager:_layoutManager]; 164 | [_layoutManager addTextContainer:_textContainer]; 165 | _layoutManager.delegate = self; 166 | _textContainer.lineFragmentPadding = 0; 167 | _textContainer.maximumNumberOfLines = 1; 168 | _textContainer.lineBreakMode = NSLineBreakByTruncatingTail; 169 | } 170 | [_textStorage appendAttributedString:contents]; 171 | } 172 | 173 | #pragma mark - Layout Invalidation 174 | 175 | - (void)invalidateGlyphMappings 176 | { 177 | [self.layoutManager invalidateGlyphsForCharacterRange:(NSRange){0, self.textStorage.length } changeInLength:0 actualCharacterRange:NULL]; 178 | } 179 | 180 | - (void)forceLayout 181 | { 182 | [self.layoutManager ensureLayoutForCharacterRange:(NSRange){ 0, self.textStorage.length }]; 183 | } 184 | 185 | #pragma mark - NSLayoutManagerDelegate 186 | 187 | - (NSUInteger)layoutManager:(NSLayoutManager *)layoutManager 188 | shouldGenerateGlyphs:(const CGGlyph *)glyphs 189 | properties:(const NSGlyphProperty *)props 190 | characterIndexes:(const NSUInteger *)charIndexes 191 | font:(UIFont *)aFont 192 | forGlyphRange:(NSRange)glyphRange 193 | { 194 | NSRange range = NSMakeRange(*charIndexes, charIndexes[glyphRange.length - 1] - charIndexes[0] + 1); 195 | NSRange targetRange = _truncationRange; 196 | NSRange intersectionRange = NSIntersectionRange(range, targetRange); 197 | 198 | if ((intersectionRange.length == 0) && _forceTailTruncationRange) { 199 | targetRange.location = NSMaxRange(_selectedRange); 200 | targetRange.length = layoutManager.textStorage.length - targetRange.location; 201 | intersectionRange = NSIntersectionRange(targetRange, range); 202 | } 203 | 204 | /* 205 | This value this is set to is never seen in the video, not really sure what a reasonable value would be. If you're using this code in an app you really should 206 | profile this and tweak this value. 207 | */ 208 | 209 | NSInteger BUFFER_LEN = 100; 210 | if (intersectionRange.length > 0) { 211 | CGGlyph glyphBuffer[BUFFER_LEN]; 212 | NSGlyphProperty propBuffer[BUFFER_LEN]; 213 | NSUInteger index; 214 | 215 | range = (NSRange){ 0, 0 }; 216 | 217 | for (index = 0; index < glyphRange.length; index++) { 218 | if (NSLocationInRange(charIndexes[index], targetRange)) { 219 | if ((index > 0) && (range.length == 0)) { 220 | // flush upto the current index (?) 221 | [layoutManager setGlyphs:glyphs properties:props characterIndexes:charIndexes font:aFont forGlyphRange:(NSRange){glyphRange.location, index}]; 222 | } 223 | if (range.length == BUFFER_LEN) { 224 | [layoutManager setGlyphs:glyphBuffer properties:propBuffer characterIndexes:charIndexes + range.location font:aFont forGlyphRange:(NSRange){ glyphRange.location + range.location, range.length }]; 225 | range.length = 0; 226 | } 227 | 228 | if (range.length == 0) { 229 | range.location = index; 230 | } 231 | 232 | if (charIndexes[index] == targetRange.location) { 233 | UTF16Char ellipsis = 0x2026; 234 | if (CTFontGetGlyphsForCharacters((CTFontRef)aFont, &ellipsis, glyphBuffer + range.length, 1)) { 235 | propBuffer[range.length] = 0; 236 | } else { 237 | // The font doesn't have ellipsis, try rendering manually later 238 | glyphBuffer[range.length] = kCGFontIndexInvalid; 239 | propBuffer[range.length] = NSGlyphPropertyControlCharacter; 240 | } 241 | } else { 242 | glyphBuffer[range.length] = kCGFontIndexInvalid; 243 | propBuffer[range.length] = NSGlyphPropertyNull; 244 | } 245 | ++range.length; 246 | } else if (charIndexes[index] >= NSMaxRange(targetRange)) { 247 | // Past the truncated range 248 | break; 249 | } 250 | } 251 | 252 | if (range.length > 0) { 253 | [layoutManager setGlyphs:glyphBuffer properties:propBuffer characterIndexes:charIndexes + range.location font:aFont forGlyphRange:(NSRange){ glyphRange.location + range.location, range.length }]; 254 | } 255 | 256 | if ((glyphRange.length - index) > 0) { 257 | [layoutManager setGlyphs:glyphs + index properties:props + index characterIndexes:charIndexes + index font:aFont forGlyphRange:(NSRange){ glyphRange.location + index, glyphRange.length - index}]; 258 | } 259 | return glyphRange.length; 260 | } else { 261 | return 0; 262 | } 263 | } 264 | 265 | @end 266 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTERootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MTERootViewController.h 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MTERootViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTERootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MTERootViewController.m 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import "MTERootViewController.h" 10 | #import "MTETextView.h" 11 | 12 | @interface MTERootViewController () 13 | 14 | @property (nonatomic, weak) MTETextView *textView; 15 | @property (nonatomic, strong) NSLayoutConstraint *textViewWidthConstraint; 16 | 17 | @end 18 | 19 | @implementation MTERootViewController 20 | 21 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 22 | { 23 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 24 | if (self) { 25 | // Custom initialization 26 | } 27 | return self; 28 | } 29 | 30 | - (void)viewDidLoad 31 | { 32 | [super viewDidLoad]; 33 | MTETextView *textView = [MTETextView new]; 34 | textView.translatesAutoresizingMaskIntoConstraints = NO; 35 | textView.backgroundColor = [UIColor lightGrayColor]; 36 | [self.view addSubview:textView]; 37 | self.textView = textView; 38 | 39 | UISlider *slider = [UISlider new]; 40 | slider.value = 1.0; 41 | slider.translatesAutoresizingMaskIntoConstraints = NO; 42 | [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged]; 43 | [self.view addSubview:slider]; 44 | 45 | id top = self.topLayoutGuide; 46 | 47 | NSDictionary *views = NSDictionaryOfVariableBindings(top, textView, slider); 48 | 49 | [self.view addConstraint:[NSLayoutConstraint constraintWithItem:textView 50 | attribute:NSLayoutAttributeCenterX 51 | relatedBy:NSLayoutRelationEqual 52 | toItem:self.view 53 | attribute:NSLayoutAttributeCenterX 54 | multiplier:1.0 55 | constant:0.0]]; 56 | self.textViewWidthConstraint = [NSLayoutConstraint constraintWithItem:textView 57 | attribute:NSLayoutAttributeWidth 58 | relatedBy:NSLayoutRelationEqual 59 | toItem:self.view 60 | attribute:NSLayoutAttributeWidth 61 | multiplier:1.0 62 | constant:0.0]; 63 | [self.view addConstraint:self.textViewWidthConstraint]; 64 | 65 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[slider]-|" options:0 metrics:nil views:views]]; 66 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[top]-[textView(==30)]-[slider]|" options:0 metrics:nil views:views]]; 67 | } 68 | 69 | - (void)sliderAction:(UISlider *)slider 70 | { 71 | [self.textViewWidthConstraint setConstant:-((1.0 - slider.value) * CGRectGetWidth(self.view.bounds))]; 72 | [self.view layoutIfNeeded]; 73 | } 74 | 75 | - (void)didReceiveMemoryWarning 76 | { 77 | [super didReceiveMemoryWarning]; 78 | // Dispose of any resources that can be recreated. 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTETextView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MTETextView.h 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MTETextView : UIView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MTETextView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MTETextView.m 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import "MTETextView.h" 10 | #import "MTEFocusedTruncationRenderer.h" 11 | 12 | @interface MTETextView () 13 | 14 | @property (nonatomic, strong) MTEFocusedTruncationRenderer *renderer; 15 | 16 | @end 17 | 18 | @implementation MTETextView 19 | 20 | - (id)initWithFrame:(CGRect)frame 21 | { 22 | self = [super initWithFrame:frame]; 23 | if (self) { 24 | _renderer = [MTEFocusedTruncationRenderer new]; 25 | NSString *string = @"Four loko mustache Helvetica, Schlitz Carles polaroid 8-bit literally photo booth 3 wolf moon Tumblr put a bird on it Blue Bottle 90's fanny pack. Banjo Portland viral, trust fund post-ironic hoodie Thundercats raw denim. Deep v seitan Thundercats, typewriter sartorial small batch hashtag umami gastropub meggings Vice try-hard Pitchfork McSweeney's Banksy. Vegan cardigan butcher distillery wayfarers, 3 wolf moon blog gentrify kogi pork belly street art skateboard. Thundercats Carles next level semiotics quinoa. Aesthetic farm-to-table Odd Future ethnic sustainable Austin. Paleo +1 gentrify, Pitchfork vinyl PBR tousled cardigan sartorial"; 26 | NSDictionary *attributes = @{ NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleBody] }; 27 | _renderer.contents = [[NSAttributedString alloc] initWithString:string attributes:attributes]; 28 | _renderer.focusedRange = (NSRange){ 19, 9 }; 29 | self.contentMode = UIViewContentModeRedraw; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)drawRect:(CGRect)rect 35 | { 36 | UIBezierPath *bezierPath = [UIBezierPath bezierPath]; 37 | CGContextRef context = UIGraphicsGetCurrentContext(); 38 | CGRect drawingBounds = CGRectInset(rect, 10.0, 0.0); 39 | 40 | [[UIColor whiteColor] set]; 41 | UIRectFill(rect); 42 | UIRectFrame(self.bounds); 43 | 44 | [bezierPath moveToPoint:(CGPoint){ 0.0, CGRectGetMinY(drawingBounds) - 10.0 }]; 45 | [bezierPath addLineToPoint:(CGPoint){ 0.0, CGRectGetMaxY(drawingBounds) + 30.0 }]; 46 | 47 | CGContextSaveGState(context); 48 | [[UIColor redColor] set]; 49 | CGContextConcatCTM(context, CGAffineTransformMakeTranslation(CGRectGetMinX(drawingBounds), 0.0)); 50 | [bezierPath stroke]; 51 | CGContextConcatCTM(context, CGAffineTransformMakeTranslation(CGRectGetWidth(drawingBounds), 0.0)); 52 | [bezierPath stroke]; 53 | CGContextRestoreGState(context); 54 | [self.renderer drawInRect:drawingBounds]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MultipleTruncationExample-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | danielrhammond.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /MultipleTruncationExample/MultipleTruncationExample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_3_0 10 | #warning "This project uses features only available in iOS SDK 3.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /MultipleTruncationExample/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /MultipleTruncationExample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MultipleTruncationExample 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "MTEAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([MTEAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MultipleTruncationExampleTests/MultipleTruncationExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | danielrhammond.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MultipleTruncationExampleTests/MultipleTruncationExampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MultipleTruncationExampleTests.m 3 | // MultipleTruncationExampleTests 4 | // 5 | // Created by Daniel Hammond on 11/12/13. 6 | // Copyright (c) 2013 Daniel Hammond. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MultipleTruncationExampleTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation MultipleTruncationExampleTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /MultipleTruncationExampleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multiple Truncation Example 2 | 3 | This is an attempt to replicate the demo code shown in WWDC 2013 session [#220 Advanced Text Layouts and Effects with Text Kit](https://developer.apple.com/wwdc/videos/index.php?id=220). I did this because the example of glyph substitution code that is shown in that talk was never published as sample code as far as I can tell. Which is really disappointing because there are a lot of interesting things that can be done with Glyph substitution in text kit, but it is kind of a tricky API and sample code is really helpful to understand how it is supposed to work. 4 | 5 | The purpose of the sample as presented in the talk is to demonstrate glyph substitution in the `NSLayoutManagerDelegate` to ensure that a highlighted range of text in a string is not truncated by a tail truncation. This is performed by detecting when part of the highlighted text would be truncated, adding a second truncation in the middle of the string by replacing some glyphs with an ellipsis. 6 | 7 | ![Screencast of truncation effect](http://f.cl.ly/items/3V2L072w3Q0v401e3Q03/Untitled.gif) 8 | 9 | # Notes 10 | 11 | The code was partially transcribed from the talk, but then I had to make several alterations: 12 | 13 | - I'm forcing invalidation of layout manager's layout in the drawRect 14 | 15 | Initially when I got it running there was a bug where once you had shrunk the text view and truncated the text to the point where it triggered the middle truncation it would never stop truncating in the middle if you grew the width of the text view again. This is because when the text view attempts to render the text again at the larger size the glyph substitution that has been performed doesn't ever get invalidated and so it will continue to think that it needs to be tail truncated at the same place as well. I force it to invalidate the layout at the beginning of the `drawRect` method. 16 | 17 | It's interesting that they never show the text view expanding again in the demo, it may be that this is just a bug in that code that they were very careful to not show. Or maybe they just picked a different spot to invalidate that layout in some of the code that wasn't ever shown on the video 18 | 19 | - Switch from glyph ranges to character ranges 20 | 21 | Additionally I found that the truncation didn't work as intended because when the tail truncation intersected our focused range, `glyphRangeForCharacterRange:actualCharacterRange:` would return the glyph range representing the focused range AND all the glyphs that were being replaced by the ellipsis. This meant that the conditional in the while loop checking whether the tail truncated range intersected with the focused range would always return true and the text would truncate to the beginning of the string. To avoid this I translate the glyph range returned from `truncatedGlyphRangeInLineFragmentForGlyphAtIndex:` into a character range to compare directly with focused range 22 | 23 | - Switched from lorem ipsum to [hipster ipsum](http://hipsteripsum.me) 24 | 25 | - Some DRYing/Cleaning up of code --------------------------------------------------------------------------------