├── .gitignore ├── .swift-version ├── Demo └── HandyTextExample │ ├── HandyTextExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── HandyTextExample │ ├── AppDelegate.swift │ ├── ApplicationFonts.swift │ ├── ApplicationStyles.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── HandyText.podspec ├── HandyText ├── Font.swift ├── NSAttributedString+TextStyle.swift ├── String+TagScheme.swift ├── String+TextStyle.swift ├── TagScheme.swift ├── TextStyle+Modifiers.swift ├── TextStyle.swift ├── TextStyleApplicable.swift ├── UIBarButtonItem+TextStyleApplicable.swift └── UINavigationBar+TextStyle.swift ├── LICENSE ├── README.md └── img ├── 01.png ├── 02.png ├── 03.png ├── 04.png ├── 05.png └── 06.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5.0 2 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5B31FADD1DF45BE900EC9D42 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FADC1DF45BE900EC9D42 /* AppDelegate.swift */; }; 11 | 5B31FADF1DF45BE900EC9D42 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FADE1DF45BE900EC9D42 /* ViewController.swift */; }; 12 | 5B31FAE21DF45BE900EC9D42 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5B31FAE01DF45BE900EC9D42 /* Main.storyboard */; }; 13 | 5B31FAE41DF45BE900EC9D42 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5B31FAE31DF45BE900EC9D42 /* Assets.xcassets */; }; 14 | 5B31FAE71DF45BE900EC9D42 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5B31FAE51DF45BE900EC9D42 /* LaunchScreen.storyboard */; }; 15 | 5B31FAF91DF45D5200EC9D42 /* Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAEF1DF45D5200EC9D42 /* Font.swift */; }; 16 | 5B31FAFA1DF45D5200EC9D42 /* NSAttributedString+TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF01DF45D5200EC9D42 /* NSAttributedString+TextStyle.swift */; }; 17 | 5B31FAFB1DF45D5200EC9D42 /* String+TagScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF11DF45D5200EC9D42 /* String+TagScheme.swift */; }; 18 | 5B31FAFC1DF45D5200EC9D42 /* String+TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF21DF45D5200EC9D42 /* String+TextStyle.swift */; }; 19 | 5B31FAFD1DF45D5200EC9D42 /* TagScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF31DF45D5200EC9D42 /* TagScheme.swift */; }; 20 | 5B31FAFE1DF45D5200EC9D42 /* TextStyle+Modifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF41DF45D5200EC9D42 /* TextStyle+Modifiers.swift */; }; 21 | 5B31FAFF1DF45D5200EC9D42 /* TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF51DF45D5200EC9D42 /* TextStyle.swift */; }; 22 | 5B31FB001DF45D5200EC9D42 /* TextStyleApplicable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF61DF45D5200EC9D42 /* TextStyleApplicable.swift */; }; 23 | 5B31FB011DF45D5200EC9D42 /* UIBarButtonItem+TextStyleApplicable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF71DF45D5200EC9D42 /* UIBarButtonItem+TextStyleApplicable.swift */; }; 24 | 5B31FB021DF45D5200EC9D42 /* UINavigationBar+TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B31FAF81DF45D5200EC9D42 /* UINavigationBar+TextStyle.swift */; }; 25 | 5BC2FEF51DF50C3900463413 /* ApplicationFonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2FEF31DF50C3900463413 /* ApplicationFonts.swift */; }; 26 | 5BC2FEF61DF50C3900463413 /* ApplicationStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2FEF41DF50C3900463413 /* ApplicationStyles.swift */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 5B31FAD91DF45BE900EC9D42 /* HandyTextExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HandyTextExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 5B31FADC1DF45BE900EC9D42 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 32 | 5B31FADE1DF45BE900EC9D42 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 33 | 5B31FAE11DF45BE900EC9D42 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | 5B31FAE31DF45BE900EC9D42 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 35 | 5B31FAE61DF45BE900EC9D42 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 36 | 5B31FAE81DF45BE900EC9D42 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 5B31FAEF1DF45D5200EC9D42 /* Font.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = ""; }; 38 | 5B31FAF01DF45D5200EC9D42 /* NSAttributedString+TextStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+TextStyle.swift"; sourceTree = ""; }; 39 | 5B31FAF11DF45D5200EC9D42 /* String+TagScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+TagScheme.swift"; sourceTree = ""; }; 40 | 5B31FAF21DF45D5200EC9D42 /* String+TextStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+TextStyle.swift"; sourceTree = ""; }; 41 | 5B31FAF31DF45D5200EC9D42 /* TagScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TagScheme.swift; sourceTree = ""; }; 42 | 5B31FAF41DF45D5200EC9D42 /* TextStyle+Modifiers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TextStyle+Modifiers.swift"; sourceTree = ""; }; 43 | 5B31FAF51DF45D5200EC9D42 /* TextStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStyle.swift; sourceTree = ""; }; 44 | 5B31FAF61DF45D5200EC9D42 /* TextStyleApplicable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStyleApplicable.swift; sourceTree = ""; }; 45 | 5B31FAF71DF45D5200EC9D42 /* UIBarButtonItem+TextStyleApplicable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+TextStyleApplicable.swift"; sourceTree = ""; }; 46 | 5B31FAF81DF45D5200EC9D42 /* UINavigationBar+TextStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationBar+TextStyle.swift"; sourceTree = ""; }; 47 | 5BC2FEF31DF50C3900463413 /* ApplicationFonts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationFonts.swift; sourceTree = ""; }; 48 | 5BC2FEF41DF50C3900463413 /* ApplicationStyles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationStyles.swift; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 5B31FAD61DF45BE900EC9D42 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 5B31FAD01DF45BE900EC9D42 = { 63 | isa = PBXGroup; 64 | children = ( 65 | 5B31FAEE1DF45D5200EC9D42 /* HandyText */, 66 | 5B31FADB1DF45BE900EC9D42 /* HandyTextExample */, 67 | 5B31FADA1DF45BE900EC9D42 /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | 5B31FADA1DF45BE900EC9D42 /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 5B31FAD91DF45BE900EC9D42 /* HandyTextExample.app */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 5B31FADB1DF45BE900EC9D42 /* HandyTextExample */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 5BC2FEF31DF50C3900463413 /* ApplicationFonts.swift */, 83 | 5BC2FEF41DF50C3900463413 /* ApplicationStyles.swift */, 84 | 5B31FADC1DF45BE900EC9D42 /* AppDelegate.swift */, 85 | 5B31FADE1DF45BE900EC9D42 /* ViewController.swift */, 86 | 5B31FAE01DF45BE900EC9D42 /* Main.storyboard */, 87 | 5B31FAE31DF45BE900EC9D42 /* Assets.xcassets */, 88 | 5B31FAE51DF45BE900EC9D42 /* LaunchScreen.storyboard */, 89 | 5B31FAE81DF45BE900EC9D42 /* Info.plist */, 90 | ); 91 | path = HandyTextExample; 92 | sourceTree = ""; 93 | }; 94 | 5B31FAEE1DF45D5200EC9D42 /* HandyText */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 5B31FAEF1DF45D5200EC9D42 /* Font.swift */, 98 | 5B31FAF01DF45D5200EC9D42 /* NSAttributedString+TextStyle.swift */, 99 | 5B31FAF11DF45D5200EC9D42 /* String+TagScheme.swift */, 100 | 5B31FAF21DF45D5200EC9D42 /* String+TextStyle.swift */, 101 | 5B31FAF31DF45D5200EC9D42 /* TagScheme.swift */, 102 | 5B31FAF41DF45D5200EC9D42 /* TextStyle+Modifiers.swift */, 103 | 5B31FAF51DF45D5200EC9D42 /* TextStyle.swift */, 104 | 5B31FAF61DF45D5200EC9D42 /* TextStyleApplicable.swift */, 105 | 5B31FAF71DF45D5200EC9D42 /* UIBarButtonItem+TextStyleApplicable.swift */, 106 | 5B31FAF81DF45D5200EC9D42 /* UINavigationBar+TextStyle.swift */, 107 | ); 108 | name = HandyText; 109 | path = ../../HandyText; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 5B31FAD81DF45BE900EC9D42 /* HandyTextExample */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 5B31FAEB1DF45BE900EC9D42 /* Build configuration list for PBXNativeTarget "HandyTextExample" */; 118 | buildPhases = ( 119 | 5B31FAD51DF45BE900EC9D42 /* Sources */, 120 | 5B31FAD61DF45BE900EC9D42 /* Frameworks */, 121 | 5B31FAD71DF45BE900EC9D42 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = HandyTextExample; 128 | productName = HandyTextExample; 129 | productReference = 5B31FAD91DF45BE900EC9D42 /* HandyTextExample.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 5B31FAD11DF45BE900EC9D42 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastSwiftUpdateCheck = 0810; 139 | LastUpgradeCheck = 1120; 140 | ORGANIZATIONNAME = "aleksey chernish"; 141 | TargetAttributes = { 142 | 5B31FAD81DF45BE900EC9D42 = { 143 | CreatedOnToolsVersion = 8.1; 144 | LastSwiftMigration = 1120; 145 | ProvisioningStyle = Automatic; 146 | }; 147 | }; 148 | }; 149 | buildConfigurationList = 5B31FAD41DF45BE900EC9D42 /* Build configuration list for PBXProject "HandyTextExample" */; 150 | compatibilityVersion = "Xcode 3.2"; 151 | developmentRegion = en; 152 | hasScannedForEncodings = 0; 153 | knownRegions = ( 154 | en, 155 | Base, 156 | ); 157 | mainGroup = 5B31FAD01DF45BE900EC9D42; 158 | productRefGroup = 5B31FADA1DF45BE900EC9D42 /* Products */; 159 | projectDirPath = ""; 160 | projectRoot = ""; 161 | targets = ( 162 | 5B31FAD81DF45BE900EC9D42 /* HandyTextExample */, 163 | ); 164 | }; 165 | /* End PBXProject section */ 166 | 167 | /* Begin PBXResourcesBuildPhase section */ 168 | 5B31FAD71DF45BE900EC9D42 /* Resources */ = { 169 | isa = PBXResourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | 5B31FAE71DF45BE900EC9D42 /* LaunchScreen.storyboard in Resources */, 173 | 5B31FAE41DF45BE900EC9D42 /* Assets.xcassets in Resources */, 174 | 5B31FAE21DF45BE900EC9D42 /* Main.storyboard in Resources */, 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | }; 178 | /* End PBXResourcesBuildPhase section */ 179 | 180 | /* Begin PBXSourcesBuildPhase section */ 181 | 5B31FAD51DF45BE900EC9D42 /* Sources */ = { 182 | isa = PBXSourcesBuildPhase; 183 | buildActionMask = 2147483647; 184 | files = ( 185 | 5BC2FEF61DF50C3900463413 /* ApplicationStyles.swift in Sources */, 186 | 5B31FAFF1DF45D5200EC9D42 /* TextStyle.swift in Sources */, 187 | 5B31FB011DF45D5200EC9D42 /* UIBarButtonItem+TextStyleApplicable.swift in Sources */, 188 | 5B31FB001DF45D5200EC9D42 /* TextStyleApplicable.swift in Sources */, 189 | 5B31FADF1DF45BE900EC9D42 /* ViewController.swift in Sources */, 190 | 5B31FADD1DF45BE900EC9D42 /* AppDelegate.swift in Sources */, 191 | 5B31FAFD1DF45D5200EC9D42 /* TagScheme.swift in Sources */, 192 | 5B31FB021DF45D5200EC9D42 /* UINavigationBar+TextStyle.swift in Sources */, 193 | 5B31FAFA1DF45D5200EC9D42 /* NSAttributedString+TextStyle.swift in Sources */, 194 | 5B31FAFB1DF45D5200EC9D42 /* String+TagScheme.swift in Sources */, 195 | 5B31FAF91DF45D5200EC9D42 /* Font.swift in Sources */, 196 | 5B31FAFC1DF45D5200EC9D42 /* String+TextStyle.swift in Sources */, 197 | 5B31FAFE1DF45D5200EC9D42 /* TextStyle+Modifiers.swift in Sources */, 198 | 5BC2FEF51DF50C3900463413 /* ApplicationFonts.swift in Sources */, 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | /* End PBXSourcesBuildPhase section */ 203 | 204 | /* Begin PBXVariantGroup section */ 205 | 5B31FAE01DF45BE900EC9D42 /* Main.storyboard */ = { 206 | isa = PBXVariantGroup; 207 | children = ( 208 | 5B31FAE11DF45BE900EC9D42 /* Base */, 209 | ); 210 | name = Main.storyboard; 211 | sourceTree = ""; 212 | }; 213 | 5B31FAE51DF45BE900EC9D42 /* LaunchScreen.storyboard */ = { 214 | isa = PBXVariantGroup; 215 | children = ( 216 | 5B31FAE61DF45BE900EC9D42 /* Base */, 217 | ); 218 | name = LaunchScreen.storyboard; 219 | sourceTree = ""; 220 | }; 221 | /* End PBXVariantGroup section */ 222 | 223 | /* Begin XCBuildConfiguration section */ 224 | 5B31FAE91DF45BE900EC9D42 /* Debug */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_COMMA = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 239 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 240 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 241 | CLANG_WARN_EMPTY_BODY = YES; 242 | CLANG_WARN_ENUM_CONVERSION = YES; 243 | CLANG_WARN_INFINITE_RECURSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 246 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 247 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 249 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 250 | CLANG_WARN_STRICT_PROTOTYPES = YES; 251 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = dwarf; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | ENABLE_TESTABILITY = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_DYNAMIC_NO_PIC = NO; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_OPTIMIZATION_LEVEL = 0; 264 | GCC_PREPROCESSOR_DEFINITIONS = ( 265 | "DEBUG=1", 266 | "$(inherited)", 267 | ); 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 275 | MTL_ENABLE_DEBUG_INFO = YES; 276 | ONLY_ACTIVE_ARCH = YES; 277 | SDKROOT = iphoneos; 278 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 279 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 280 | SWIFT_VERSION = 5.0; 281 | TARGETED_DEVICE_FAMILY = "1,2"; 282 | }; 283 | name = Debug; 284 | }; 285 | 5B31FAEA1DF45BE900EC9D42 /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 290 | CLANG_ANALYZER_NONNULL = YES; 291 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 292 | CLANG_CXX_LIBRARY = "libc++"; 293 | CLANG_ENABLE_MODULES = YES; 294 | CLANG_ENABLE_OBJC_ARC = YES; 295 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 296 | CLANG_WARN_BOOL_CONVERSION = YES; 297 | CLANG_WARN_COMMA = YES; 298 | CLANG_WARN_CONSTANT_CONVERSION = YES; 299 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 302 | CLANG_WARN_EMPTY_BODY = YES; 303 | CLANG_WARN_ENUM_CONVERSION = YES; 304 | CLANG_WARN_INFINITE_RECURSION = YES; 305 | CLANG_WARN_INT_CONVERSION = YES; 306 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 307 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 308 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 309 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 310 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 311 | CLANG_WARN_STRICT_PROTOTYPES = YES; 312 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 313 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 314 | CLANG_WARN_UNREACHABLE_CODE = YES; 315 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 316 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 317 | COPY_PHASE_STRIP = NO; 318 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 319 | ENABLE_NS_ASSERTIONS = NO; 320 | ENABLE_STRICT_OBJC_MSGSEND = YES; 321 | GCC_C_LANGUAGE_STANDARD = gnu99; 322 | GCC_NO_COMMON_BLOCKS = YES; 323 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 324 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 325 | GCC_WARN_UNDECLARED_SELECTOR = YES; 326 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 327 | GCC_WARN_UNUSED_FUNCTION = YES; 328 | GCC_WARN_UNUSED_VARIABLE = YES; 329 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 330 | MTL_ENABLE_DEBUG_INFO = NO; 331 | SDKROOT = iphoneos; 332 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 333 | SWIFT_VERSION = 5.0; 334 | TARGETED_DEVICE_FAMILY = "1,2"; 335 | VALIDATE_PRODUCT = YES; 336 | }; 337 | name = Release; 338 | }; 339 | 5B31FAEC1DF45BE900EC9D42 /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 343 | INFOPLIST_FILE = HandyTextExample/Info.plist; 344 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 345 | PRODUCT_BUNDLE_IDENTIFIER = com.achernish.home.HandyTextExample; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SWIFT_VERSION = 5.0; 348 | }; 349 | name = Debug; 350 | }; 351 | 5B31FAED1DF45BE900EC9D42 /* Release */ = { 352 | isa = XCBuildConfiguration; 353 | buildSettings = { 354 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 355 | INFOPLIST_FILE = HandyTextExample/Info.plist; 356 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 357 | PRODUCT_BUNDLE_IDENTIFIER = com.achernish.home.HandyTextExample; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | SWIFT_VERSION = 5.0; 360 | }; 361 | name = Release; 362 | }; 363 | /* End XCBuildConfiguration section */ 364 | 365 | /* Begin XCConfigurationList section */ 366 | 5B31FAD41DF45BE900EC9D42 /* Build configuration list for PBXProject "HandyTextExample" */ = { 367 | isa = XCConfigurationList; 368 | buildConfigurations = ( 369 | 5B31FAE91DF45BE900EC9D42 /* Debug */, 370 | 5B31FAEA1DF45BE900EC9D42 /* Release */, 371 | ); 372 | defaultConfigurationIsVisible = 0; 373 | defaultConfigurationName = Release; 374 | }; 375 | 5B31FAEB1DF45BE900EC9D42 /* Build configuration list for PBXNativeTarget "HandyTextExample" */ = { 376 | isa = XCConfigurationList; 377 | buildConfigurations = ( 378 | 5B31FAEC1DF45BE900EC9D42 /* Debug */, 379 | 5B31FAED1DF45BE900EC9D42 /* Release */, 380 | ); 381 | defaultConfigurationIsVisible = 0; 382 | defaultConfigurationName = Release; 383 | }; 384 | /* End XCConfigurationList section */ 385 | }; 386 | rootObject = 5B31FAD11DF45BE900EC9D42 /* Project object */; 387 | } 388 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // HandyTextExample 4 | // 5 | // Created by Aleksey on 04.12.16. 6 | // Copyright © 2016 aleksey chernish. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | func applicationWillResignActive(_ application: UIApplication) { 22 | // 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. 23 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 24 | } 25 | 26 | func applicationDidEnterBackground(_ application: UIApplication) { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | func applicationWillEnterForeground(_ application: UIApplication) { 32 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 33 | } 34 | 35 | func applicationDidBecomeActive(_ application: UIApplication) { 36 | // 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. 37 | } 38 | 39 | func applicationWillTerminate(_ application: UIApplication) { 40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 41 | } 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/ApplicationFonts.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ApplicationFonts.swift 3 | // TextStyleExample 4 | // 5 | // Created by Aleksey on 04.07.16. 6 | // Copyright © 2016 Aleksey Chernish. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension Font { 12 | 13 | static var avenir: Font { 14 | return Font( 15 | light: "Avenir-Light", 16 | lightItalic: "Avenir-LightOblique", 17 | regular: "Avenir", 18 | italic: "Avenir-Oblique", 19 | bold: "Avenir-Heavy", 20 | boldItalic: "Avenir-HeavyOblique") 21 | } 22 | 23 | static var helvetica: Font { 24 | return Font( 25 | light: "Helvetica-Light", 26 | lightItalic: "Helvetica-LightOblique", 27 | regular: "Helvetica", 28 | italic: "Helvetica-Oblique", 29 | bold: "Helvetica-Bold", 30 | boldItalic: "Helvetica-BoldOblique") 31 | } 32 | 33 | static var georgia: Font { 34 | return Font( 35 | regular: "Georgia", 36 | italic: "Georgia-Italic", 37 | bold: "Georgia-Bold", 38 | boldItalic: "Georgia-BoldItalic") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/ApplicationStyles.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ApplicationStyles.swift 3 | // TextStyleExample 4 | // 5 | // Created by Aleksey on 04.07.16. 6 | // Copyright © 2016 Aleksey Chernish. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension TextStyle { 12 | 13 | static var plainText: TextStyle { 14 | return TextStyle(font: .helvetica).withSize(12) 15 | } 16 | 17 | static var url: TextStyle { 18 | return plainText.withForegroundColor(.blue).italic().withUnderline(.single) 19 | } 20 | 21 | static var header: TextStyle { 22 | return plainText.withSizeMultiplied(by: 1.4).withForegroundColor(.orange).uppercase().bold() 23 | } 24 | 25 | static var button: TextStyle { 26 | let shadow = NSShadow() 27 | shadow.shadowOffset = CGSize(width: 1.0, height: 1.0) 28 | shadow.shadowBlurRadius = 1.0 29 | shadow.shadowColor = UIColor.lightGray 30 | 31 | return header.withForegroundColor(.black).withShadow(shadow) 32 | } 33 | 34 | } 35 | 36 | extension TagScheme { 37 | 38 | static var `default`: TagScheme { 39 | let scheme = TagScheme() 40 | scheme.forTag("b") { $0.bold() } 41 | scheme.forTag("i") { $0.italic().withUnderline(.single) } 42 | scheme.forTag("u") { $0.uppercase() } 43 | 44 | return scheme 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/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 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/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 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. 55 | 56 | 57 | 58 | 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 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 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 | -------------------------------------------------------------------------------- /Demo/HandyTextExample/HandyTextExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // HandyTextExample 4 | // 5 | // Created by Aleksey on 04.12.16. 6 | // Copyright © 2016 aleksey chernish. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet 14 | private weak var label: UILabel! 15 | 16 | @IBOutlet 17 | private weak var textField: UITextField! 18 | 19 | @IBOutlet 20 | private weak var textView: UITextView! 21 | 22 | @IBOutlet 23 | private weak var button: UIButton! 24 | 25 | override func viewDidLoad() { 26 | super.viewDidLoad() 27 | 28 | navigationController?.navigationBar.applyAttributes(from: TextStyle.header.withForegroundColor(.black)) 29 | 30 | title = "Handy text demo" 31 | 32 | label.attributedText = "about zebras".withStyle(.header, tagScheme: .default) 33 | 34 | textField.applyAttributes(from: .plainText) 35 | 36 | textField.attributedPlaceholder = "search" 37 | .withStyle(TextStyle.plainText 38 | .withForegroundColor(.lightGray) 39 | .italic()) 40 | 41 | let textViewText = "Zebras are several species of African equids (horse family) united by their distinctive black and white striped coats. Their stripes come in different patterns, unique to each individual." 42 | 43 | textView.attributedText = textViewText 44 | .withStyle(.plainText) 45 | .applyStyle(.url, toOccurencesOf: "species") 46 | 47 | button.setAttributedTitle("Got it!".withStyle(.button), for: .normal) 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /HandyText.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = 'HandyText' 4 | s.version = '1.4.5' 5 | s.ios.deployment_target = '10.0' 6 | s.license = 'MIT' 7 | s.summary = 'HandyText library helps you manage text styles in a declarative manner.' 8 | s.description = 'A tool providing a flexible and self descriptive wrapper for creating and managing attributed strings.' 9 | s.homepage = 'https://github.com/mmrmmlrr/TextStyle' 10 | s.author = { 'aleksey' => 'achernish85@gmail.com' } 11 | s.source = { :git => 'https://github.com/mmrmmlrr/TextStyle.git', :tag => s.version.to_s } 12 | s.exclude_files = ["Demo/", "img/"] 13 | 14 | s.frameworks = ['UIKit'] 15 | s.source_files = '**/*.{m,h,mm,hpp,cpp,c,swift}' 16 | s.requires_arc = true 17 | s.swift_version = '5.0' 18 | 19 | end 20 | -------------------------------------------------------------------------------- /HandyText/Font.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Font.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | public struct Font { 9 | 10 | public enum Thickness { 11 | case extralight, light, regular, medium, bold, heavy, extraheavy 12 | } 13 | 14 | public let extralight: String 15 | public let extralightItalic: String 16 | public let light: String 17 | public let lightItalic: String 18 | public let regular: String 19 | public let italic: String 20 | public let medium: String 21 | public let mediumItalic: String 22 | public let bold: String 23 | public let boldItalic: String 24 | public let heavy: String 25 | public let heavyItalic: String 26 | public let extraheavy: String 27 | public let extraheavyItalic: String 28 | 29 | public init( 30 | extralight: String = "", 31 | extralightItalic: String = "", 32 | light: String = "", 33 | lightItalic: String = "", 34 | regular: String = "", 35 | italic: String = "", 36 | medium: String = "", 37 | mediumItalic: String = "", 38 | bold: String = "", 39 | boldItalic: String = "", 40 | heavy: String = "", 41 | heavyItalic: String = "", 42 | extraheavy: String = "", 43 | extraheavyItalic: String = "" 44 | ) { 45 | self.extralight = extralight 46 | self.extralightItalic = extralightItalic 47 | self.light = light 48 | self.lightItalic = lightItalic 49 | self.regular = regular 50 | self.italic = italic 51 | self.medium = medium 52 | self.mediumItalic = mediumItalic 53 | self.bold = bold 54 | self.boldItalic = boldItalic 55 | self.heavy = heavy 56 | self.heavyItalic = heavyItalic 57 | self.extraheavy = extraheavy 58 | self.extraheavyItalic = extraheavyItalic 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /HandyText/NSAttributedString+TextStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSAttributedString+TextStyle.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | public func +(left: NSAttributedString, right: NSAttributedString) -> NSAttributedString { 11 | let result = NSMutableAttributedString(attributedString: left) 12 | result.append(right) 13 | 14 | return result.copy() as! NSAttributedString 15 | } 16 | 17 | extension NSAttributedString { 18 | 19 | public func applyStyle(_ style: TextStyle, toOccurencesOf substring: String, ignoringCase: Bool = false) -> NSAttributedString { 20 | guard let range = rangeOf(substring, ignoringCase: ignoringCase) else { return self } 21 | 22 | let head = attributedSubstring(from: NSRange.init(location: 0, length: range.location)) 23 | let foundString = attributedSubstring(from: range) 24 | let rest = attributedSubstring(from: NSMakeRange(range.length + range.location, self.length - (range.length + range.location))) 25 | 26 | return head + foundString.string.withStyle(style) + rest.applyStyle(style, toOccurencesOf: substring, ignoringCase: ignoringCase) 27 | } 28 | 29 | public func applyStyle(_ style: TextStyle, in range: NSRange?) -> NSAttributedString { 30 | guard let range = range else { return self } 31 | let head = attributedSubstring(from: NSMakeRange(0, range.location)) 32 | let substringInRange = attributedSubstring(from: range) 33 | let rest = attributedSubstring(from: NSMakeRange(range.length + range.location, self.length - (range.length + range.location))) 34 | 35 | return head + substringInRange.string.withStyle(style) + rest 36 | } 37 | 38 | func rangeOf(_ string: String, ignoringCase: Bool) -> NSRange? { 39 | let aString = self.string as NSString 40 | let range = aString.range(of: string, options: ignoringCase ? [NSString.CompareOptions.caseInsensitive] : []) 41 | 42 | return range.location == NSNotFound ? nil : range 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /HandyText/String+TagScheme.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String+TagScheme.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | extension String { 11 | 12 | public func withStyle(_ style: TextStyle, tagScheme: TagScheme) -> NSAttributedString { 13 | let result = NSMutableAttributedString() 14 | 15 | for (tag, substring) in decompose() { 16 | if let tag = tag, let substring = substring { 17 | result.append(substring.withStyle(tagScheme.modifier(for: tag)(style), tagScheme: tagScheme)) 18 | } else if let substring = substring { 19 | result.append(substring.withStyle(style)) 20 | } 21 | } 22 | 23 | return result 24 | } 25 | 26 | private func decompose() -> [(tag: String?, text: String?)] { 27 | if isEmpty { return [] } 28 | 29 | let components = self.components(separatedBy: "<") 30 | if components.count == 1 { 31 | return [(nil, self)] 32 | } else { 33 | let tag = components[1].components(separatedBy: ">").first! 34 | let head = components[0] 35 | let body = self.components(separatedBy: "<\(tag)>")[1].components(separatedBy: "").first 36 | let tail = String(suffix(from: range(of: "")!.upperBound)) 37 | var result = [(tag: String?, text: String?)]() 38 | result.append((nil, head)) 39 | result.append((tag, body)) 40 | result += tail.decompose() 41 | 42 | return result 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /HandyText/String+TextStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String+TextStyle.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | extension String { 11 | 12 | public func withStyle(_ style: TextStyle) -> NSAttributedString { 13 | var string: String 14 | 15 | switch style.caseTrait { 16 | case .capitalized: 17 | string = self.capitalized 18 | case .lowercase: 19 | string = self.lowercased() 20 | case .uppercase: 21 | string = self.uppercased() 22 | case .none: 23 | string = self 24 | } 25 | 26 | return NSAttributedString(string: string, attributes: style.textAttributes) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /HandyText/TagScheme.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TagScheme.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | public typealias TextStyleModifier = (TextStyle) -> TextStyle 11 | 12 | public class TagScheme { 13 | 14 | private var map = [String: TextStyleModifier]() 15 | 16 | public init() {} 17 | 18 | public func forTag(_ tag: String, use modifier: @escaping TextStyleModifier) { 19 | map[tag] = modifier 20 | } 21 | 22 | func modifier(for tag: String) -> TextStyleModifier { 23 | return map[tag] ?? { $0 } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /HandyText/TextStyle+Modifiers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextStyle+Modifiers.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | extension TextStyle { 11 | 12 | //MARK: - Based on 13 | 14 | public class func based(on style: TextStyle) -> TextStyle { 15 | return style.copy() 16 | } 17 | 18 | //MARK: - Fill color 19 | 20 | public func withForegroundColor(_ color: UIColor) -> TextStyle { 21 | let copy = self.copy() 22 | copy.foregroundColor = color 23 | return copy 24 | } 25 | 26 | public func withBackgroundColor(_ color: UIColor) -> TextStyle { 27 | let copy = self.copy() 28 | copy.backgroundColor = color 29 | return copy 30 | } 31 | 32 | //MARK: - Size 33 | 34 | public func withSize(_ size: CGFloat) -> TextStyle { 35 | let copy = self.copy() 36 | copy.size = size 37 | return copy 38 | } 39 | 40 | public func withSizeIncremented(by increment: CGFloat) -> TextStyle { 41 | let copy = self.copy() 42 | copy.size += increment 43 | return copy 44 | } 45 | 46 | public func withSizeMultiplied(by multiplicator: CGFloat) -> TextStyle { 47 | let copy = self.copy() 48 | copy.size *= multiplicator 49 | return copy 50 | } 51 | 52 | public func withDynamicFontStyle(_ style: DynamicFontStyle) -> TextStyle { 53 | let copy = self.copy() 54 | copy.size = UIFont.preferredFont(forTextStyle: UIFont.TextStyle(rawValue: style.literal)).pointSize 55 | return copy 56 | } 57 | 58 | //MARK: - Thickness 59 | 60 | public func extralight() -> TextStyle { 61 | let copy = self.copy() 62 | copy.thickness = .extralight 63 | return copy 64 | } 65 | 66 | public func light() -> TextStyle { 67 | let copy = self.copy() 68 | copy.thickness = .light 69 | return copy 70 | } 71 | 72 | public func regular() -> TextStyle { 73 | let copy = self.copy() 74 | copy.thickness = .regular 75 | return copy 76 | } 77 | 78 | public func medium() -> TextStyle { 79 | let copy = self.copy() 80 | copy.thickness = .medium 81 | return copy 82 | } 83 | 84 | public func bold() -> TextStyle { 85 | let copy = self.copy() 86 | copy.thickness = .bold 87 | return copy 88 | } 89 | 90 | public func heavy() -> TextStyle { 91 | let copy = self.copy() 92 | copy.thickness = .heavy 93 | return copy 94 | } 95 | 96 | public func extraheavy() -> TextStyle { 97 | let copy = self.copy() 98 | copy.thickness = .extraheavy 99 | return copy 100 | } 101 | 102 | //MARK: - Slant 103 | 104 | public func italic() -> TextStyle { 105 | let copy = self.copy() 106 | copy.isItalic = true 107 | return copy 108 | } 109 | 110 | public func roman() -> TextStyle { 111 | let copy = self.copy() 112 | copy.isItalic = false 113 | return copy 114 | } 115 | 116 | //MARK: - Case Trait, mutually exclusive 117 | 118 | public func capitalized() -> TextStyle { 119 | let copy = self.copy() 120 | copy.caseTrait = .capitalized 121 | return copy 122 | } 123 | 124 | public func lowercase() -> TextStyle { 125 | let copy = self.copy() 126 | copy.caseTrait = .lowercase 127 | return copy 128 | } 129 | 130 | public func uppercase() -> TextStyle { 131 | let copy = self.copy() 132 | copy.caseTrait = .uppercase 133 | return copy 134 | } 135 | 136 | //MARK: - Underline 137 | 138 | public func withUnderline(_ style: NSUnderlineStyle) -> TextStyle { 139 | let copy = self.copy() 140 | copy.underlineStyle = style 141 | return copy 142 | } 143 | 144 | public func withUnderlineColor(_ color: UIColor?) -> TextStyle { 145 | let copy = self.copy() 146 | copy.underlineColor = color 147 | return copy 148 | } 149 | 150 | //MARK: - Strikethrough 151 | 152 | public func withStrikethrough(_ strikethrough: Bool) -> TextStyle { 153 | let copy = self.copy() 154 | copy.strikethrough = strikethrough 155 | return copy 156 | } 157 | 158 | public func withStrikethroughColor(_ color: UIColor?) -> TextStyle { 159 | let copy = self.copy() 160 | copy.strikeThroughColor = color 161 | return copy 162 | } 163 | 164 | //MARK: - Ligatures 165 | 166 | public func withLigatures(enabled: Bool) -> TextStyle { 167 | let copy = self.copy() 168 | copy.ligaturesEnabled = enabled 169 | return copy 170 | } 171 | 172 | //MARK: - Stroke 173 | 174 | public func withStrokeWidth(_ width: CGFloat) -> TextStyle { 175 | let copy = self.copy() 176 | copy.strokeWidth = width 177 | return copy 178 | } 179 | 180 | public func withStrokeColor(_ color: UIColor?) -> TextStyle { 181 | let copy = self.copy() 182 | copy.strokeColor = color 183 | return copy 184 | } 185 | 186 | //MARK: - Shadow 187 | 188 | public func withShadow(_ shadow: NSShadow?) -> TextStyle { 189 | let copy = self.copy() 190 | copy.shadow = shadow 191 | return copy 192 | } 193 | 194 | // MARK: - Opacity 195 | 196 | public func withOpacity(_ opacity: CGFloat) -> TextStyle { 197 | let copy = self.copy() 198 | copy.opacity = opacity 199 | return copy 200 | } 201 | 202 | //MARK: - Link 203 | 204 | public func withLink(_ link: String?) -> TextStyle { 205 | let copy = self.copy() 206 | copy.link = link 207 | return copy 208 | } 209 | 210 | //MARK: - Offset 211 | 212 | public func withBaselineOffset(absolute offset: CGFloat) -> TextStyle { 213 | let copy = self.copy() 214 | copy.baselineOffset = .absolute(offset) 215 | return copy 216 | } 217 | 218 | func withBaselineOffset(relative ratio: CGFloat) -> TextStyle { 219 | let copy = self.copy() 220 | copy.baselineOffset = .relative(ratio) 221 | return copy 222 | } 223 | 224 | //MARK: - Paragraph style options 225 | 226 | public func withParagraphStyle(_ style: NSParagraphStyle) -> TextStyle { 227 | let copy = self.copy() 228 | copy.paragraphStyle = style.mutableCopy() as! NSMutableParagraphStyle 229 | return copy 230 | } 231 | 232 | public func withLineBreakMode(_ mode: NSLineBreakMode) -> TextStyle { 233 | let copy = self.copy() 234 | copy.paragraphStyle.lineBreakMode = mode 235 | return copy 236 | } 237 | 238 | public func withHeadIndent(_ indent: CGFloat) -> TextStyle { 239 | let copy = self.copy() 240 | copy.paragraphStyle.headIndent = indent 241 | return copy 242 | } 243 | 244 | public func withFirstLineIndent(_ indent: CGFloat) -> TextStyle { 245 | let copy = self.copy() 246 | copy.paragraphStyle.firstLineHeadIndent = indent 247 | return copy 248 | } 249 | 250 | public func withParagraphSpacing(_ spacing: CGFloat) -> TextStyle { 251 | let copy = self.copy() 252 | copy.paragraphStyle.paragraphSpacing = spacing 253 | return copy 254 | } 255 | 256 | public func withParagraphSpacingBefore(_ spacing: CGFloat) -> TextStyle { 257 | let copy = self.copy() 258 | copy.paragraphStyle.paragraphSpacingBefore = spacing 259 | return copy 260 | } 261 | 262 | public func withAlignment(_ alignment: NSTextAlignment) -> TextStyle { 263 | let copy = self.copy() 264 | copy.paragraphStyle.alignment = alignment 265 | return copy 266 | } 267 | 268 | public func withLineSpacing(_ spacing: CGFloat) -> TextStyle { 269 | let copy = self.copy() 270 | copy.paragraphStyle.lineSpacing = spacing 271 | return copy 272 | } 273 | 274 | // MARK: - Letter spacing 275 | 276 | public func withLetterSpacing(_ spacing: CGFloat) -> TextStyle { 277 | let copy = self.copy() 278 | copy.letterSpacing = spacing 279 | return copy 280 | } 281 | 282 | } 283 | -------------------------------------------------------------------------------- /HandyText/TextStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextStyle.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | //TODO: generate attributes on demand to avoid recalculations 11 | 12 | public class TextStyle { 13 | 14 | public enum BaselineOffset { 15 | case none 16 | case absolute(CGFloat) 17 | case relative(CGFloat) 18 | } 19 | 20 | public enum CaseTrait { 21 | case none, capitalized, lowercase, uppercase 22 | } 23 | 24 | public var textAttributes: [NSAttributedString.Key: AnyObject] { 25 | get { 26 | var attributes = [NSAttributedString.Key: AnyObject]() 27 | attributes[.foregroundColor] = foregroundColor.withAlphaComponent(opacity) 28 | attributes[.backgroundColor] = backgroundColor?.withAlphaComponent(opacity) 29 | attributes[.strikethroughColor] = strikeThroughColor?.withAlphaComponent(opacity) 30 | attributes[.strokeColor] = strokeColor?.withAlphaComponent(opacity) 31 | attributes[.strokeWidth] = strokeWidth as AnyObject? 32 | attributes[.paragraphStyle] = paragraphStyle 33 | attributes[.font] = UIFont(name: typeface, size: size) 34 | attributes[.ligature] = ligaturesEnabled as AnyObject? 35 | attributes[.strikethroughStyle] = Int(strikethrough ? 1 : 0) as AnyObject? 36 | attributes[.underlineStyle] = underlineStyle.rawValue as AnyObject? 37 | attributes[.underlineColor] = underlineColor?.withAlphaComponent(opacity) 38 | attributes[.shadow] = shadow 39 | attributes[.link] = link as AnyObject? 40 | attributes[.kern] = letterSpacing as AnyObject? 41 | 42 | let calculatedOffset: CGFloat 43 | switch baselineOffset { 44 | case .absolute(let offset): 45 | calculatedOffset = offset 46 | case .relative(let offset): 47 | calculatedOffset = offset * size 48 | case .none: 49 | calculatedOffset = 0.0 50 | } 51 | 52 | attributes[.baselineOffset] = calculatedOffset as AnyObject? 53 | 54 | return attributes 55 | } 56 | } 57 | 58 | public var paragraphStyle = NSMutableParagraphStyle() 59 | 60 | /// STATE 61 | 62 | public var font: Font 63 | public var size: CGFloat = UIFont.preferredFont(forTextStyle: .body).pointSize 64 | public var thickness = Font.Thickness.regular 65 | public var caseTrait = CaseTrait.none 66 | public var isItalic = false 67 | public var opacity: CGFloat = 1.0 68 | public var foregroundColor = UIColor.black 69 | public var backgroundColor: UIColor? 70 | public var underlineColor: UIColor? 71 | public var strikeThroughColor: UIColor? 72 | public var strokeColor: UIColor? 73 | public var underlineStyle = NSUnderlineStyle(rawValue: 0) 74 | public var strikethrough = false 75 | public var ligaturesEnabled = false 76 | public var strokeWidth: CGFloat = 0.0 77 | public var shadow: NSShadow? 78 | public var link: String? 79 | public var baselineOffset = BaselineOffset.none 80 | public var letterSpacing: CGFloat? 81 | 82 | public var typeface: String { 83 | get { 84 | switch thickness { 85 | case .extralight: 86 | return isItalic ? font.extralightItalic : font.extralight 87 | case .light: 88 | return isItalic ? font.lightItalic : font.light 89 | case .regular: 90 | return isItalic ? font.italic : font.regular 91 | case .medium: 92 | return isItalic ? font.mediumItalic : font.medium 93 | case .bold: 94 | return isItalic ? font.boldItalic : font.bold 95 | case .heavy: 96 | return isItalic ? font.heavyItalic : font.heavy 97 | case .extraheavy: 98 | return isItalic ? font.extraheavyItalic : font.extraheavy 99 | } 100 | } 101 | } 102 | 103 | public enum DynamicFontStyle { 104 | 105 | case title1, title2, title3, headline, subheadline, body, callout, footnote, caption1, caption2 106 | 107 | var literal: String { 108 | switch self { 109 | case .title1: 110 | return UIFont.TextStyle.title1.rawValue 111 | case .title2: 112 | return UIFont.TextStyle.title2.rawValue 113 | case .title3: 114 | return UIFont.TextStyle.title3.rawValue 115 | case .headline: 116 | return UIFont.TextStyle.headline.rawValue 117 | case .subheadline: 118 | return UIFont.TextStyle.subheadline.rawValue 119 | case .body: 120 | return UIFont.TextStyle.body.rawValue 121 | case .callout: 122 | return UIFont.TextStyle.callout.rawValue 123 | case .footnote: 124 | return UIFont.TextStyle.footnote.rawValue 125 | case .caption1: 126 | return UIFont.TextStyle.caption1.rawValue 127 | case .caption2: 128 | return UIFont.TextStyle.caption2.rawValue 129 | } 130 | } 131 | } 132 | 133 | public init(font: Font) { 134 | self.font = font 135 | } 136 | 137 | public func copy() -> TextStyle { 138 | let copy = TextStyle(font: font) 139 | copy.size = size 140 | copy.thickness = thickness 141 | copy.caseTrait = caseTrait 142 | copy.isItalic = isItalic 143 | copy.paragraphStyle = paragraphStyle 144 | copy.opacity = opacity 145 | copy.foregroundColor = foregroundColor 146 | copy.backgroundColor = backgroundColor 147 | copy.strikeThroughColor = strikeThroughColor 148 | copy.underlineColor = underlineColor 149 | copy.underlineStyle = underlineStyle 150 | copy.strikethrough = strikethrough 151 | copy.ligaturesEnabled = ligaturesEnabled 152 | copy.strokeColor = strokeColor 153 | copy.strokeWidth = strokeWidth 154 | copy.shadow = shadow 155 | copy.link = link 156 | copy.letterSpacing = letterSpacing 157 | copy.baselineOffset = baselineOffset 158 | 159 | return copy 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /HandyText/TextStyleApplicable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextStyleApplicable.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | public protocol TextStyleApplicable {} 11 | 12 | public extension TextStyleApplicable where Self: NSObject { 13 | 14 | func applyAttributes(from style: TextStyle) { 15 | let font = style.textAttributes[.font] as? UIFont 16 | let color = style.textAttributes[.foregroundColor] as? UIColor 17 | setValue(font, forKey: "font") 18 | setValue(color, forKey: "textColor") 19 | } 20 | 21 | } 22 | 23 | extension UILabel: TextStyleApplicable {} 24 | extension UITextView: TextStyleApplicable {} 25 | extension UITextField: TextStyleApplicable {} 26 | -------------------------------------------------------------------------------- /HandyText/UIBarButtonItem+TextStyleApplicable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+TextStyleApplicable.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | extension UIBarButtonItem: TextStyleApplicable { 11 | 12 | public func applyAttributes(from style: TextStyle) { 13 | setTitleTextAttributes(style.textAttributes, for: .normal) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /HandyText/UINavigationBar+TextStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBar+TextStyle.swift 3 | // HandyText 4 | // 5 | // Copyright © 2016 aleksey chernish. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | extension UINavigationBar: TextStyleApplicable { 11 | 12 | public func applyAttributes(from style: TextStyle) { 13 | titleTextAttributes = style.textAttributes 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 mmrmmlrr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HandyText 2 | -------------- 3 | 4 | Purpose 5 | -------------- 6 | HandyText is a helper library that allows to create and manage text styles in a clear declarative manner. 7 | 8 | Problem solved 9 | -------------- 10 | 11 | Work on UI tasks is full of repetition when it goes about defining text appearance. You have to refer to mockups all the time, or to search and copy elements of same appearance. Both ways leave many ways for errors, and both make late changes in design quite painful. Amount of work for changing a font in typical elements is proportional to project's size. 12 | The alternative way is in avoiding the use of IB for defining text appearance, but handling it in code. 13 | 14 | 15 | Supported OS & SDK Versions 16 | ----------------------------- 17 | 18 | Swift 5.0 19 | * Supported build target - iOS 10.1 and up (Xcode 10) 20 | 21 | Installation 22 | -------------- 23 | 24 | ```ruby 25 | # In your Podfile 26 | 27 | pod 'HandyText' 28 | ``` 29 | 30 | Declare own text styles as static functions or properties of TextStyle class. 31 | 32 | Version 1.4.5 33 | 34 | - Release version. 35 | 36 | Usage 37 | -------------- 38 | 39 | First, let's define some text styles: 40 | 41 | ```swift 42 | extension TextStyle { 43 | static var plainText: TextStyle { 44 | return TextStyle(font: .avenir) 45 | } 46 | } 47 | ``` 48 | 49 | The Font is only required parameter for creating a brand new style, all other params are set to defaults. Instead of copying instances and modifying properties the library proposes more declarative 'cascade' style. Think you need a style for headers based on plain text: 50 | 51 | ```swift 52 | static var header1: TextStyle { 53 | return plainText.withSizeMultiplied(by: 1.4).uppercase().bold() 54 | } 55 | ``` 56 | 57 | It's remarkable that styles are chained, in other words based on each other. Changing basic style font to .georgia makes all style scheme look different, but still well fitted. 58 | 59 | Attributed strings 60 | ---------------- 61 | 62 | The costs of using text styles is switching to attributed text, which is supported by the most of UIKit classes. 63 | ```swift 64 | label.attributedText = "Hello, World!".withStyle(.plainText) 65 | ``` 66 | 67 | 68 | ### Merging attributed strings 69 | Attributed strings can be combined to achieve more complex appearance: 70 | ```swift 71 | let title = "First name: ".withStyle(.placeholder) 72 | let name = "Michael".withStyle(.plainText) 73 | label.attributedText = title + name 74 | ``` 75 | 76 | 77 | ### Highlighting words 78 | You can highlight specific substrings with a different text style: 79 | ```swift 80 | let text = "There are three species of zebras: the plains zebra, the Grévy's zebra and the mountain zebra" 81 | label.attributedText = text.withStyle(.plainText).applyStyle(.header1, toOccurencesOf: "zebra") 82 | ``` 83 | 84 | 85 | 86 | For displaying strings with tags you define a tag scheme: 87 | ```swift 88 | let scheme = TagScheme() 89 | scheme.forTag("b") { $0.bold() } 90 | scheme.forTag("i") { $0.italic() } 91 | ``` 92 | In the scheme for each custom tag you register a block defining the modification of the initial text style. 93 | Nested tags are supported. Text marked as following ```"lions"``` will be bold italic. 94 | To convert a string into an attributed string: 95 | ```swift 96 | let result = "about zebras".withStyle(.plainText, tagScheme: scheme) 97 | ``` 98 | 99 | 100 | 101 | FAQ 102 | -------------- 103 | ### How many styles do I need? 104 | As little as possible. Average application has 2-3 basic and several complementary text styles. It's not necessary to create a new style if it differs with only the color or alignment. Better to extend the style at place. 105 | 106 | ### Absolute or relative size? 107 | You are used to define text size in points: 10 for plain text, 15 for heading and so on. But let's look from another angle: what this numbers mean? I guess, the designer could think something like 'let headers be a half times more than normal text'. Due to method ```withSizeMultiplied(by:)``` you can define text sizes proportionally. In this case, when the base style changes its size, the whole text scheme scales proportionally. Baseline offset can also be defined relative, which will keep proportions in custom superscripts like below: 108 | 109 | 110 | 111 | ### What can make the text size change? 112 | Here are some ideas. By using Dynamic Text Size in the base style, you will make your app sensitive to the Accessibility preferences of the device. For large devices it's reasonable to use slightly larger fonts. Some apps allow users to change appearance themes. With HandyText updating fonts becomes a simple task. 113 | 114 | 115 | 116 | ### Too many outlets! 117 | To use HandyText effectively you must create an outlet for every text containing view. Is it that bad? In well-designed projects all strings are kept in the single file: Localizable.strings. Not in storyboards, not in the code. With this approach the whole app can be translated into a new language without changing a line of code. HandyText lib encourages you to use this approach: fetch a localized string, apply a style, display the result in the corresponding outlet. 118 | 119 | ### How to add links to my attributed text? 120 | The library doesn't add any new abilities to UIKit classes. For assigning a link to a chunk of text it uses NSLinkAttributeName. For more info refer to the [official docs](https://developer.apple.com/reference/uikit/uitextviewdelegate/1649337-textview). 121 | 122 | ### How do I call my text styles? 123 | Avoid giving names based on specific usage, try to keep it more generic. For instance, 'screenHeading' is a good name, 'orangeHeaderInFriendsList' – is not. 124 | 125 | ### Can HandyText help me improve my design specs? 126 | Of course. As a developer, together with design team you can define a table of common text styles and rules for describing modifiers. Instead of "HelveticaNeue-Bold, 15 pt, color: FF0000" it can be "style: header, color: tomatoRed". 127 | 128 | 129 | License 130 | ---------------- 131 | 132 | The MIT License (MIT) 133 | 134 | Copyright © 2016 Aleksey Chernish 135 | 136 | Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 137 | 138 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 139 | 140 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 141 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 142 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 143 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 144 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 145 | THE SOFTWARE. 146 | 147 | -------------------------------------------------------------------------------- /img/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/01.png -------------------------------------------------------------------------------- /img/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/02.png -------------------------------------------------------------------------------- /img/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/03.png -------------------------------------------------------------------------------- /img/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/04.png -------------------------------------------------------------------------------- /img/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/05.png -------------------------------------------------------------------------------- /img/06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksey-ios-dev/HandyText/19ec4e40fdbaccad1bfe5652b583e6628003dfa6/img/06.jpg --------------------------------------------------------------------------------