├── LICENSE ├── README.md ├── YsyRichTextDemo ├── YsyRichTextDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── lh.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── lh.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── YsyRichTextDemo │ ├── 10.jpg │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.h │ ├── SceneDelegate.m │ ├── ViewController.h │ ├── ViewController.m │ ├── YsyRichText │ ├── AttributedMaker.h │ ├── AttributedMaker.m │ ├── NSString+ysy_Attributed.h │ ├── NSString+ysy_Attributed.m │ └── YsyRichText.h │ └── main.m └── manifest.plist /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 牧羊的诗人 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 | # YsyRichText 2 | 模仿Masonry,封装了富文本的一些常用操作,简化富文本的使用,使用简单,即插即用,具体用法可以参照demo。 3 | 4 | 简书地址:https://www.jianshu.com/p/4ef50f862347 5 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | EB6A600024CEBB1500469A29 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A5FFF24CEBB1500469A29 /* AppDelegate.m */; }; 11 | EB6A600324CEBB1500469A29 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A600224CEBB1500469A29 /* SceneDelegate.m */; }; 12 | EB6A600624CEBB1500469A29 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A600524CEBB1500469A29 /* ViewController.m */; }; 13 | EB6A600924CEBB1500469A29 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB6A600724CEBB1500469A29 /* Main.storyboard */; }; 14 | EB6A600B24CEBB1900469A29 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EB6A600A24CEBB1900469A29 /* Assets.xcassets */; }; 15 | EB6A600E24CEBB1900469A29 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB6A600C24CEBB1900469A29 /* LaunchScreen.storyboard */; }; 16 | EB6A601124CEBB1900469A29 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A601024CEBB1900469A29 /* main.m */; }; 17 | EB6A601D24CEBB2F00469A29 /* NSString+ysy_Attributed.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A601824CEBB2F00469A29 /* NSString+ysy_Attributed.m */; }; 18 | EB6A601E24CEBB2F00469A29 /* AttributedMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = EB6A601B24CEBB2F00469A29 /* AttributedMaker.m */; }; 19 | EB6A602024CEBBEA00469A29 /* 10.jpg in Resources */ = {isa = PBXBuildFile; fileRef = EB6A601F24CEBBEA00469A29 /* 10.jpg */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | EB6A5FFB24CEBB1500469A29 /* YsyRichTextDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YsyRichTextDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | EB6A5FFE24CEBB1500469A29 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | EB6A5FFF24CEBB1500469A29 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | EB6A600124CEBB1500469A29 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = ""; }; 27 | EB6A600224CEBB1500469A29 /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = ""; }; 28 | EB6A600424CEBB1500469A29 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 29 | EB6A600524CEBB1500469A29 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 30 | EB6A600824CEBB1500469A29 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 31 | EB6A600A24CEBB1900469A29 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | EB6A600D24CEBB1900469A29 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | EB6A600F24CEBB1900469A29 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | EB6A601024CEBB1900469A29 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | EB6A601824CEBB2F00469A29 /* NSString+ysy_Attributed.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+ysy_Attributed.m"; sourceTree = ""; }; 36 | EB6A601924CEBB2F00469A29 /* AttributedMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttributedMaker.h; sourceTree = ""; }; 37 | EB6A601A24CEBB2F00469A29 /* YsyRichText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YsyRichText.h; sourceTree = ""; }; 38 | EB6A601B24CEBB2F00469A29 /* AttributedMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttributedMaker.m; sourceTree = ""; }; 39 | EB6A601C24CEBB2F00469A29 /* NSString+ysy_Attributed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+ysy_Attributed.h"; sourceTree = ""; }; 40 | EB6A601F24CEBBEA00469A29 /* 10.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 10.jpg; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | EB6A5FF824CEBB1500469A29 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | EB6A5FF224CEBB1500469A29 = { 55 | isa = PBXGroup; 56 | children = ( 57 | EB6A5FFD24CEBB1500469A29 /* YsyRichTextDemo */, 58 | EB6A5FFC24CEBB1500469A29 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | EB6A5FFC24CEBB1500469A29 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | EB6A5FFB24CEBB1500469A29 /* YsyRichTextDemo.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | EB6A5FFD24CEBB1500469A29 /* YsyRichTextDemo */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | EB6A601724CEBB2F00469A29 /* YsyRichText */, 74 | EB6A5FFE24CEBB1500469A29 /* AppDelegate.h */, 75 | EB6A5FFF24CEBB1500469A29 /* AppDelegate.m */, 76 | EB6A600124CEBB1500469A29 /* SceneDelegate.h */, 77 | EB6A600224CEBB1500469A29 /* SceneDelegate.m */, 78 | EB6A600424CEBB1500469A29 /* ViewController.h */, 79 | EB6A600524CEBB1500469A29 /* ViewController.m */, 80 | EB6A600724CEBB1500469A29 /* Main.storyboard */, 81 | EB6A601F24CEBBEA00469A29 /* 10.jpg */, 82 | EB6A600A24CEBB1900469A29 /* Assets.xcassets */, 83 | EB6A600C24CEBB1900469A29 /* LaunchScreen.storyboard */, 84 | EB6A600F24CEBB1900469A29 /* Info.plist */, 85 | EB6A601024CEBB1900469A29 /* main.m */, 86 | ); 87 | path = YsyRichTextDemo; 88 | sourceTree = ""; 89 | }; 90 | EB6A601724CEBB2F00469A29 /* YsyRichText */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | EB6A601A24CEBB2F00469A29 /* YsyRichText.h */, 94 | EB6A601924CEBB2F00469A29 /* AttributedMaker.h */, 95 | EB6A601B24CEBB2F00469A29 /* AttributedMaker.m */, 96 | EB6A601C24CEBB2F00469A29 /* NSString+ysy_Attributed.h */, 97 | EB6A601824CEBB2F00469A29 /* NSString+ysy_Attributed.m */, 98 | ); 99 | path = YsyRichText; 100 | sourceTree = ""; 101 | }; 102 | /* End PBXGroup section */ 103 | 104 | /* Begin PBXNativeTarget section */ 105 | EB6A5FFA24CEBB1500469A29 /* YsyRichTextDemo */ = { 106 | isa = PBXNativeTarget; 107 | buildConfigurationList = EB6A601424CEBB1900469A29 /* Build configuration list for PBXNativeTarget "YsyRichTextDemo" */; 108 | buildPhases = ( 109 | EB6A5FF724CEBB1500469A29 /* Sources */, 110 | EB6A5FF824CEBB1500469A29 /* Frameworks */, 111 | EB6A5FF924CEBB1500469A29 /* Resources */, 112 | ); 113 | buildRules = ( 114 | ); 115 | dependencies = ( 116 | ); 117 | name = YsyRichTextDemo; 118 | productName = YsyRichTextDemo; 119 | productReference = EB6A5FFB24CEBB1500469A29 /* YsyRichTextDemo.app */; 120 | productType = "com.apple.product-type.application"; 121 | }; 122 | /* End PBXNativeTarget section */ 123 | 124 | /* Begin PBXProject section */ 125 | EB6A5FF324CEBB1500469A29 /* Project object */ = { 126 | isa = PBXProject; 127 | attributes = { 128 | LastUpgradeCheck = 1150; 129 | ORGANIZATIONNAME = ysyplay; 130 | TargetAttributes = { 131 | EB6A5FFA24CEBB1500469A29 = { 132 | CreatedOnToolsVersion = 11.5; 133 | }; 134 | }; 135 | }; 136 | buildConfigurationList = EB6A5FF624CEBB1500469A29 /* Build configuration list for PBXProject "YsyRichTextDemo" */; 137 | compatibilityVersion = "Xcode 9.3"; 138 | developmentRegion = en; 139 | hasScannedForEncodings = 0; 140 | knownRegions = ( 141 | en, 142 | Base, 143 | ); 144 | mainGroup = EB6A5FF224CEBB1500469A29; 145 | productRefGroup = EB6A5FFC24CEBB1500469A29 /* Products */; 146 | projectDirPath = ""; 147 | projectRoot = ""; 148 | targets = ( 149 | EB6A5FFA24CEBB1500469A29 /* YsyRichTextDemo */, 150 | ); 151 | }; 152 | /* End PBXProject section */ 153 | 154 | /* Begin PBXResourcesBuildPhase section */ 155 | EB6A5FF924CEBB1500469A29 /* Resources */ = { 156 | isa = PBXResourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | EB6A602024CEBBEA00469A29 /* 10.jpg in Resources */, 160 | EB6A600E24CEBB1900469A29 /* LaunchScreen.storyboard in Resources */, 161 | EB6A600B24CEBB1900469A29 /* Assets.xcassets in Resources */, 162 | EB6A600924CEBB1500469A29 /* Main.storyboard in Resources */, 163 | ); 164 | runOnlyForDeploymentPostprocessing = 0; 165 | }; 166 | /* End PBXResourcesBuildPhase section */ 167 | 168 | /* Begin PBXSourcesBuildPhase section */ 169 | EB6A5FF724CEBB1500469A29 /* Sources */ = { 170 | isa = PBXSourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | EB6A600624CEBB1500469A29 /* ViewController.m in Sources */, 174 | EB6A601D24CEBB2F00469A29 /* NSString+ysy_Attributed.m in Sources */, 175 | EB6A600024CEBB1500469A29 /* AppDelegate.m in Sources */, 176 | EB6A601124CEBB1900469A29 /* main.m in Sources */, 177 | EB6A601E24CEBB2F00469A29 /* AttributedMaker.m in Sources */, 178 | EB6A600324CEBB1500469A29 /* SceneDelegate.m in Sources */, 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | }; 182 | /* End PBXSourcesBuildPhase section */ 183 | 184 | /* Begin PBXVariantGroup section */ 185 | EB6A600724CEBB1500469A29 /* Main.storyboard */ = { 186 | isa = PBXVariantGroup; 187 | children = ( 188 | EB6A600824CEBB1500469A29 /* Base */, 189 | ); 190 | name = Main.storyboard; 191 | sourceTree = ""; 192 | }; 193 | EB6A600C24CEBB1900469A29 /* LaunchScreen.storyboard */ = { 194 | isa = PBXVariantGroup; 195 | children = ( 196 | EB6A600D24CEBB1900469A29 /* Base */, 197 | ); 198 | name = LaunchScreen.storyboard; 199 | sourceTree = ""; 200 | }; 201 | /* End PBXVariantGroup section */ 202 | 203 | /* Begin XCBuildConfiguration section */ 204 | EB6A601224CEBB1900469A29 /* Debug */ = { 205 | isa = XCBuildConfiguration; 206 | buildSettings = { 207 | ALWAYS_SEARCH_USER_PATHS = NO; 208 | CLANG_ANALYZER_NONNULL = YES; 209 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 210 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 211 | CLANG_CXX_LIBRARY = "libc++"; 212 | CLANG_ENABLE_MODULES = YES; 213 | CLANG_ENABLE_OBJC_ARC = YES; 214 | CLANG_ENABLE_OBJC_WEAK = YES; 215 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 216 | CLANG_WARN_BOOL_CONVERSION = YES; 217 | CLANG_WARN_COMMA = YES; 218 | CLANG_WARN_CONSTANT_CONVERSION = YES; 219 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 220 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 221 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 222 | CLANG_WARN_EMPTY_BODY = YES; 223 | CLANG_WARN_ENUM_CONVERSION = YES; 224 | CLANG_WARN_INFINITE_RECURSION = YES; 225 | CLANG_WARN_INT_CONVERSION = YES; 226 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 227 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 228 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 229 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 230 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 231 | CLANG_WARN_STRICT_PROTOTYPES = YES; 232 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 233 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 234 | CLANG_WARN_UNREACHABLE_CODE = YES; 235 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 236 | COPY_PHASE_STRIP = NO; 237 | DEBUG_INFORMATION_FORMAT = dwarf; 238 | ENABLE_STRICT_OBJC_MSGSEND = YES; 239 | ENABLE_TESTABILITY = YES; 240 | GCC_C_LANGUAGE_STANDARD = gnu11; 241 | GCC_DYNAMIC_NO_PIC = NO; 242 | GCC_NO_COMMON_BLOCKS = YES; 243 | GCC_OPTIMIZATION_LEVEL = 0; 244 | GCC_PREPROCESSOR_DEFINITIONS = ( 245 | "DEBUG=1", 246 | "$(inherited)", 247 | ); 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 255 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 256 | MTL_FAST_MATH = YES; 257 | ONLY_ACTIVE_ARCH = YES; 258 | SDKROOT = iphoneos; 259 | }; 260 | name = Debug; 261 | }; 262 | EB6A601324CEBB1900469A29 /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ALWAYS_SEARCH_USER_PATHS = NO; 266 | CLANG_ANALYZER_NONNULL = YES; 267 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_ENABLE_OBJC_WEAK = YES; 273 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 274 | CLANG_WARN_BOOL_CONVERSION = YES; 275 | CLANG_WARN_COMMA = YES; 276 | CLANG_WARN_CONSTANT_CONVERSION = YES; 277 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 280 | CLANG_WARN_EMPTY_BODY = YES; 281 | CLANG_WARN_ENUM_CONVERSION = YES; 282 | CLANG_WARN_INFINITE_RECURSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 285 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 286 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 287 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 288 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 289 | CLANG_WARN_STRICT_PROTOTYPES = YES; 290 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 291 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 292 | CLANG_WARN_UNREACHABLE_CODE = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | COPY_PHASE_STRIP = NO; 295 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 296 | ENABLE_NS_ASSERTIONS = NO; 297 | ENABLE_STRICT_OBJC_MSGSEND = YES; 298 | GCC_C_LANGUAGE_STANDARD = gnu11; 299 | GCC_NO_COMMON_BLOCKS = YES; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 307 | MTL_ENABLE_DEBUG_INFO = NO; 308 | MTL_FAST_MATH = YES; 309 | SDKROOT = iphoneos; 310 | VALIDATE_PRODUCT = YES; 311 | }; 312 | name = Release; 313 | }; 314 | EB6A601524CEBB1900469A29 /* Debug */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | CODE_SIGN_STYLE = Automatic; 319 | INFOPLIST_FILE = YsyRichTextDemo/Info.plist; 320 | LD_RUNPATH_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "@executable_path/Frameworks", 323 | ); 324 | PRODUCT_BUNDLE_IDENTIFIER = ysyplay.YsyRichTextDemo; 325 | PRODUCT_NAME = "$(TARGET_NAME)"; 326 | TARGETED_DEVICE_FAMILY = "1,2"; 327 | }; 328 | name = Debug; 329 | }; 330 | EB6A601624CEBB1900469A29 /* Release */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 334 | CODE_SIGN_STYLE = Automatic; 335 | INFOPLIST_FILE = YsyRichTextDemo/Info.plist; 336 | LD_RUNPATH_SEARCH_PATHS = ( 337 | "$(inherited)", 338 | "@executable_path/Frameworks", 339 | ); 340 | PRODUCT_BUNDLE_IDENTIFIER = ysyplay.YsyRichTextDemo; 341 | PRODUCT_NAME = "$(TARGET_NAME)"; 342 | TARGETED_DEVICE_FAMILY = "1,2"; 343 | }; 344 | name = Release; 345 | }; 346 | /* End XCBuildConfiguration section */ 347 | 348 | /* Begin XCConfigurationList section */ 349 | EB6A5FF624CEBB1500469A29 /* Build configuration list for PBXProject "YsyRichTextDemo" */ = { 350 | isa = XCConfigurationList; 351 | buildConfigurations = ( 352 | EB6A601224CEBB1900469A29 /* Debug */, 353 | EB6A601324CEBB1900469A29 /* Release */, 354 | ); 355 | defaultConfigurationIsVisible = 0; 356 | defaultConfigurationName = Release; 357 | }; 358 | EB6A601424CEBB1900469A29 /* Build configuration list for PBXNativeTarget "YsyRichTextDemo" */ = { 359 | isa = XCConfigurationList; 360 | buildConfigurations = ( 361 | EB6A601524CEBB1900469A29 /* Debug */, 362 | EB6A601624CEBB1900469A29 /* Release */, 363 | ); 364 | defaultConfigurationIsVisible = 0; 365 | defaultConfigurationName = Release; 366 | }; 367 | /* End XCConfigurationList section */ 368 | }; 369 | rootObject = EB6A5FF324CEBB1500469A29 /* Project object */; 370 | } 371 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo.xcodeproj/project.xcworkspace/xcuserdata/lh.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ysyplay/YsyRichText/57f69c12471f3ff3942dcaf7dc13f9b7c5ebbb1f/YsyRichTextDemo/YsyRichTextDemo.xcodeproj/project.xcworkspace/xcuserdata/lh.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo.xcodeproj/xcuserdata/lh.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | YsyRichTextDemo.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ysyplay/YsyRichText/57f69c12471f3ff3942dcaf7dc13f9b7c5ebbb1f/YsyRichTextDemo/YsyRichTextDemo/10.jpg -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | #pragma mark - UISceneSession lifecycle 25 | 26 | 27 | - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; 31 | } 32 | 33 | 34 | - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { 35 | // Called when the user discards a scene session. 36 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 37 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 38 | } 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/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 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/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 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/SceneDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.h 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SceneDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow * window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/SceneDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.m 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import "SceneDelegate.h" 10 | 11 | @interface SceneDelegate () 12 | 13 | @end 14 | 15 | @implementation SceneDelegate 16 | 17 | 18 | - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { 19 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 20 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 21 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 22 | } 23 | 24 | 25 | - (void)sceneDidDisconnect:(UIScene *)scene { 26 | // Called as the scene is being released by the system. 27 | // This occurs shortly after the scene enters the background, or when its session is discarded. 28 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 29 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 30 | } 31 | 32 | 33 | - (void)sceneDidBecomeActive:(UIScene *)scene { 34 | // Called when the scene has moved from an inactive state to an active state. 35 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 36 | } 37 | 38 | 39 | - (void)sceneWillResignActive:(UIScene *)scene { 40 | // Called when the scene will move from an active state to an inactive state. 41 | // This may occur due to temporary interruptions (ex. an incoming phone call). 42 | } 43 | 44 | 45 | - (void)sceneWillEnterForeground:(UIScene *)scene { 46 | // Called as the scene transitions from the background to the foreground. 47 | // Use this method to undo the changes made on entering the background. 48 | } 49 | 50 | 51 | - (void)sceneDidEnterBackground:(UIScene *)scene { 52 | // Called as the scene transitions from the foreground to the background. 53 | // Use this method to save data, release shared resources, and store enough scene-specific state information 54 | // to restore the scene back to its current state. 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "YsyRichText.h" 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | UITextView *textView = [UITextView new]; 21 | [self.view addSubview:textView]; 22 | textView.frame = CGRectMake(100, 100, 200, 100); 23 | textView.backgroundColor = [UIColor orangeColor]; 24 | textView.attributedText = [@"富文本:" ysy_Attributed:^(AttributedMaker *make) { 25 | make.font([UIFont systemFontOfSize:12]).foregroundColor([UIColor blueColor]).obliqueness(0.5); 26 | make.append(@"追加文字追加文字追加文字追加文字").font([UIFont systemFontOfSize:17]).foregroundColor([UIColor redColor]); 27 | make.merge.backgroundColor([UIColor yellowColor]); 28 | make.strikethroughStyle(1).strikethroughColor([UIColor whiteColor]).lineSpacing(15).textAlignment(NSTextAlignmentLeft); 29 | make.underlineStyle(2).underlineColor([UIColor blueColor]); 30 | make.insertImage([UIImage imageNamed:@"10.jpg"],CGRectMake(0, -5, 20, 20),10); 31 | }]; 32 | 33 | } 34 | 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/YsyRichText/AttributedMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // AttributedMaker.h 3 | // AttributedDemo 4 | // 5 | // Created by LH on 7/25/20. 6 | // Copyright © 2020 ysy. All rights reserved. 7 | // 8 | #import 9 | #import 10 | //工具类 11 | @interface AttributedMaker : NSObject 12 | @property (nonatomic, strong,readonly) NSMutableArray *stringArr; 13 | @property (nonatomic, strong,readonly) NSMutableArray *attributedStringArr; 14 | 15 | 16 | ///设置font 17 | - (AttributedMaker *(^)(UIFont *value))font; 18 | ///设置斜体 19 | - (AttributedMaker *(^)(float value))obliqueness; 20 | ///设置文字颜色 21 | - (AttributedMaker *(^)(UIColor *value))foregroundColor; 22 | ///设置背景颜色 23 | - (AttributedMaker *(^)(UIColor *value))backgroundColor; 24 | ///删除线高度 25 | - (AttributedMaker *(^)(NSInteger value))strikethroughStyle; 26 | ///删除线颜色 27 | - (AttributedMaker *(^)(UIColor *value))strikethroughColor; 28 | ///删除线基线偏移属性(有bug) 29 | //- (AttributedMaker *(^)(NSInteger value))baselineOffset; 30 | ///下滑线粗度 31 | - (AttributedMaker *(^)(NSInteger value))underlineStyle; 32 | ///下滑线颜色 33 | - (AttributedMaker *(^)(UIColor *value))underlineColor; 34 | ///字体描边宽度 35 | - (AttributedMaker *(^)(float value))strokeWidth; 36 | ///字体描边颜 37 | - (AttributedMaker *(^)(UIColor *value))strokeColor; 38 | ///字体阴影 39 | - (AttributedMaker *(^)(NSShadow *value))shadow; 40 | ///字间距 41 | - (AttributedMaker *(^)(float value))kern; 42 | ///行间距 43 | - (AttributedMaker *(^)(float value))lineSpacing; 44 | ///对齐方式 45 | - (AttributedMaker *(^)(NSTextAlignment value))textAlignment; 46 | ///字符截断类型 47 | - (AttributedMaker *(^)(NSLineBreakMode value))lineBreakMode; 48 | ///设置URL跳转 UITextView才有效,UILabel和UITextField里面无效 49 | - (AttributedMaker *(^)(NSString *value))link; 50 | ///插入图片(图片,尺寸,位置) 51 | - (AttributedMaker *(^)(UIImage *image,CGRect bounds,NSInteger index))insertImage; 52 | 53 | 54 | ///追加文字 55 | - (AttributedMaker *(^)(NSString *string))append; 56 | ///合并(例如追加完文字以后,来个总设置) 57 | - (AttributedMaker *)merge; 58 | @end 59 | 60 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/YsyRichText/AttributedMaker.m: -------------------------------------------------------------------------------- 1 | // 2 | // AttributedMaker.m 3 | // AttributedDemo 4 | // 5 | // Created by LH on 7/25/20. 6 | // Copyright © 2020 ysy. All rights reserved. 7 | // 8 | #import "AttributedMaker.h" 9 | 10 | @interface AttributedMaker() 11 | @property (nonatomic, strong) NSMutableArray *stringArr; 12 | @property (nonatomic, strong) NSMutableArray *attributedStringArr; 13 | 14 | @property (nonatomic, assign) float pLineSpacing; 15 | @property (nonatomic, assign) NSLineBreakMode pLineBreakMode; 16 | @property (nonatomic, assign) NSTextAlignment pAlignment; 17 | 18 | @end 19 | 20 | //工具类 21 | @implementation AttributedMaker 22 | 23 | - (instancetype)init { 24 | self = [super init]; 25 | if (self) { 26 | _stringArr = [[NSMutableArray alloc] initWithCapacity:0]; 27 | _attributedStringArr = [[NSMutableArray alloc] initWithCapacity:0]; 28 | } 29 | return self; 30 | } 31 | - (AttributedMaker *(^)(UIFont *value))font { 32 | __weak typeof (self) weakSelf = self; 33 | return ^(UIFont *value ) 34 | { 35 | NSString *string = weakSelf.stringArr.lastObject; 36 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 37 | [attributedString addAttribute:NSFontAttributeName 38 | value:value 39 | range:NSMakeRange(0, string.length)]; 40 | return weakSelf; 41 | }; 42 | } 43 | - (AttributedMaker *(^)(UIColor *value))foregroundColor { 44 | __weak typeof (self) weakSelf = self; 45 | return ^(UIColor *value ) 46 | { 47 | NSString *string = weakSelf.stringArr.lastObject; 48 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 49 | [attributedString addAttribute: NSForegroundColorAttributeName 50 | value:value 51 | range:NSMakeRange(0, string.length)]; 52 | return weakSelf; 53 | }; 54 | } 55 | - (AttributedMaker *(^)(UIColor *value))backgroundColor { 56 | __weak typeof (self) weakSelf = self; 57 | return ^(UIColor *value ) 58 | { 59 | NSString *string = weakSelf.stringArr.lastObject; 60 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 61 | [attributedString addAttribute: NSBackgroundColorAttributeName 62 | value:value 63 | range:NSMakeRange(0, string.length)]; 64 | return weakSelf; 65 | }; 66 | } 67 | - (AttributedMaker *(^)(NSInteger value))strikethroughStyle { 68 | __weak typeof (self) weakSelf = self; 69 | return ^(NSInteger value ) 70 | { 71 | NSString *string = weakSelf.stringArr.lastObject; 72 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 73 | [attributedString addAttribute: NSStrikethroughStyleAttributeName 74 | value:@(value) 75 | range:NSMakeRange(0, string.length)]; 76 | return weakSelf; 77 | }; 78 | } 79 | - (AttributedMaker *(^)(NSInteger value))baselineOffset { 80 | __weak typeof (self) weakSelf = self; 81 | return ^(NSInteger value ) 82 | { 83 | NSString *string = weakSelf.stringArr.lastObject; 84 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 85 | [attributedString addAttribute: NSBaselineOffsetAttributeName 86 | value:@(value) 87 | range:NSMakeRange(0, string.length)]; 88 | return weakSelf; 89 | }; 90 | } 91 | - (AttributedMaker *(^)(UIColor *value))strikethroughColor { 92 | __weak typeof (self) weakSelf = self; 93 | return ^(UIColor *value ) 94 | { 95 | NSString *string = weakSelf.stringArr.lastObject; 96 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 97 | [attributedString addAttribute: NSStrikethroughColorAttributeName 98 | value:value 99 | range:NSMakeRange(0, string.length)]; 100 | return weakSelf; 101 | }; 102 | } 103 | - (AttributedMaker *(^)(NSInteger value))underlineStyle { 104 | __weak typeof (self) weakSelf = self; 105 | return ^(NSInteger value ) 106 | { 107 | NSString *string = weakSelf.stringArr.lastObject; 108 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 109 | [attributedString addAttribute: NSUnderlineStyleAttributeName 110 | value:@(value) 111 | range:NSMakeRange(0, string.length)]; 112 | return weakSelf; 113 | }; 114 | } 115 | - (AttributedMaker *(^)(UIColor *value))underlineColor { 116 | __weak typeof (self) weakSelf = self; 117 | return ^(UIColor *value) 118 | { 119 | NSString *string = weakSelf.stringArr.lastObject; 120 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 121 | [attributedString addAttribute: NSUnderlineColorAttributeName 122 | value:value 123 | range:NSMakeRange(0, string.length)]; 124 | return weakSelf; 125 | }; 126 | } 127 | - (AttributedMaker *(^)(UIColor *value))strokeColor { 128 | __weak typeof (self) weakSelf = self; 129 | return ^(UIColor *value) 130 | { 131 | NSString *string = weakSelf.stringArr.lastObject; 132 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 133 | [attributedString addAttribute: NSStrokeColorAttributeName 134 | value:value 135 | range:NSMakeRange(0, string.length)]; 136 | return weakSelf; 137 | }; 138 | } 139 | - (AttributedMaker *(^)(float value))strokeWidth { 140 | __weak typeof (self) weakSelf = self; 141 | return ^(float value) 142 | { 143 | NSString *string = weakSelf.stringArr.lastObject; 144 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 145 | [attributedString addAttribute: NSStrokeWidthAttributeName 146 | value:@(value) 147 | range:NSMakeRange(0, string.length)]; 148 | return weakSelf; 149 | }; 150 | } 151 | - (AttributedMaker *(^)(NSShadow *value))shadow { 152 | __weak typeof (self) weakSelf = self; 153 | return ^(NSShadow *value) 154 | { 155 | NSString *string = weakSelf.stringArr.lastObject; 156 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 157 | [attributedString addAttribute: NSShadowAttributeName 158 | value:value 159 | range:NSMakeRange(0, string.length)]; 160 | return weakSelf; 161 | }; 162 | } 163 | - (AttributedMaker *(^)(float value))obliqueness { 164 | __weak typeof (self) weakSelf = self; 165 | return ^(float value) 166 | { 167 | NSString *string = weakSelf.stringArr.lastObject; 168 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 169 | [attributedString addAttribute: NSObliquenessAttributeName 170 | value:@(value) 171 | range:NSMakeRange(0, string.length)]; 172 | return weakSelf; 173 | }; 174 | } 175 | - (AttributedMaker *(^)(NSString *value))link { 176 | __weak typeof (self) weakSelf = self; 177 | return ^(NSString *value) 178 | { 179 | NSString *string = weakSelf.stringArr.lastObject; 180 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 181 | [attributedString addAttribute: NSLinkAttributeName 182 | value:[NSURL URLWithString:value] 183 | range:NSMakeRange(0, string.length)]; 184 | return weakSelf; 185 | }; 186 | } 187 | - (AttributedMaker *(^)(UIImage *image,CGRect bounds,NSInteger index))insertImage { 188 | __weak typeof (self) weakSelf = self; 189 | return ^(UIImage *image,CGRect bounds,NSInteger index) 190 | { 191 | NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; 192 | textAttachment.image = image; //设置图片源 193 | textAttachment.bounds = bounds; //设置图片位置和大小 194 | NSAttributedString *coreText2 = [NSAttributedString attributedStringWithAttachment: textAttachment]; 195 | 196 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 197 | [attributedString insertAttributedString:coreText2 atIndex:index]; 198 | return weakSelf; 199 | }; 200 | } 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | - (AttributedMaker *(^)(float value))kern { 209 | __weak typeof (self) weakSelf = self; 210 | return ^(float value) 211 | { 212 | NSString *string = weakSelf.stringArr.lastObject; 213 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 214 | [attributedString addAttribute: NSKernAttributeName 215 | value:@(value) 216 | range:NSMakeRange(0, string.length)]; 217 | return weakSelf; 218 | }; 219 | } 220 | - (AttributedMaker *(^)(float value))lineSpacing { 221 | __weak typeof (self) weakSelf = self; 222 | return ^(float value) 223 | { 224 | NSString *string = weakSelf.stringArr.lastObject; 225 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 226 | NSMutableParagraphStyle *style = [NSMutableParagraphStyle new]; 227 | style.lineSpacing = value; 228 | weakSelf.pLineSpacing = value; 229 | if (weakSelf.pLineBreakMode) { 230 | style.lineBreakMode = weakSelf.pLineBreakMode; 231 | } 232 | if (weakSelf.pAlignment) { 233 | style.alignment = weakSelf.pAlignment; 234 | } 235 | [attributedString addAttribute: NSParagraphStyleAttributeName 236 | value:style 237 | range:NSMakeRange(0, string.length)]; 238 | return weakSelf; 239 | }; 240 | } 241 | - (AttributedMaker *(^)(NSTextAlignment value))textAlignment { 242 | __weak typeof (self) weakSelf = self; 243 | return ^(NSTextAlignment value) 244 | { 245 | NSString *string = weakSelf.stringArr.lastObject; 246 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 247 | NSMutableParagraphStyle *style = [NSMutableParagraphStyle new]; 248 | style.alignment = value; 249 | weakSelf.pAlignment = value; 250 | if (weakSelf.pLineSpacing) { 251 | style.lineSpacing = weakSelf.pLineSpacing; 252 | } 253 | if (weakSelf.pLineBreakMode) { 254 | style.lineBreakMode = weakSelf.pLineBreakMode; 255 | } 256 | [attributedString addAttribute: NSParagraphStyleAttributeName 257 | value:style 258 | range:NSMakeRange(0, string.length)]; 259 | return weakSelf; 260 | }; 261 | } 262 | - (AttributedMaker *(^)(NSLineBreakMode value))lineBreakMode { 263 | __weak typeof (self) weakSelf = self; 264 | return ^(NSLineBreakMode value) 265 | { 266 | NSString *string = weakSelf.stringArr.lastObject; 267 | NSMutableAttributedString *attributedString = weakSelf.attributedStringArr.lastObject; 268 | NSMutableParagraphStyle *style = [NSMutableParagraphStyle new]; 269 | style.lineBreakMode = value; 270 | weakSelf.pLineBreakMode = value; 271 | if (weakSelf.pLineSpacing) { 272 | style.lineSpacing = weakSelf.pLineSpacing; 273 | } 274 | if (weakSelf.pAlignment) { 275 | style.alignment = weakSelf.pAlignment; 276 | } 277 | [attributedString addAttribute: NSParagraphStyleAttributeName 278 | value:style 279 | range:NSMakeRange(0, string.length)]; 280 | return weakSelf; 281 | }; 282 | } 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | - (AttributedMaker *(^)(NSString *string))append { 304 | __weak typeof (self) weakSelf = self; 305 | return ^(NSString *string) 306 | { 307 | [weakSelf.stringArr addObject:string]; 308 | [weakSelf.attributedStringArr addObject:[[NSMutableAttributedString alloc] initWithString:string]]; 309 | return weakSelf; 310 | }; 311 | } 312 | - (AttributedMaker *)merge{ 313 | __block NSString *string = @""; 314 | [self.stringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 315 | string = [string stringByAppendingString:obj]; 316 | }]; 317 | [self.stringArr removeAllObjects]; 318 | [self.stringArr addObject:string]; 319 | 320 | NSMutableAttributedString *attributedString = \ 321 | [[NSMutableAttributedString alloc] init]; 322 | [self.attributedStringArr enumerateObjectsUsingBlock:^(NSMutableAttributedString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 323 | [attributedString appendAttributedString:obj]; 324 | }]; 325 | [self.attributedStringArr removeAllObjects]; 326 | [self.attributedStringArr addObject:attributedString]; 327 | return self; 328 | } 329 | @end 330 | 331 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/YsyRichText/NSString+ysy_Attributed.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ysy_Attributed.h 3 | // AttributedDemo 4 | // 5 | // Created by LH on 7/25/20. 6 | // Copyright © 2020 ysy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | @class AttributedMaker; 12 | 13 | @interface NSString (ysy_Attributed) 14 | - (NSMutableAttributedString *)ysy_Attributed:(void(^)(AttributedMaker *make))attributed; 15 | @end 16 | 17 | 18 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/YsyRichText/NSString+ysy_Attributed.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ysy_Attributed.m 3 | // AttributedDemo 4 | // 5 | // Created by LH on 7/25/20. 6 | // Copyright © 2020 ysy. All rights reserved. 7 | // 8 | 9 | #import "NSString+ysy_Attributed.h" 10 | #import "AttributedMaker.h" 11 | @implementation NSString (ysy_Attributed) 12 | - (NSMutableAttributedString *)ysy_Attributed:(void(^)(AttributedMaker *make))attributed{ 13 | AttributedMaker *make = [[AttributedMaker alloc]init]; 14 | [make.stringArr addObject:self]; 15 | [make.attributedStringArr addObject:[[NSMutableAttributedString alloc] initWithString:self]]; 16 | attributed(make); 17 | NSMutableAttributedString *attributedString = \ 18 | [[NSMutableAttributedString alloc] init]; 19 | [make.attributedStringArr enumerateObjectsUsingBlock:^(NSMutableAttributedString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 20 | [attributedString appendAttributedString:obj]; 21 | }]; 22 | return attributedString;; 23 | } 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/YsyRichText/YsyRichText.h: -------------------------------------------------------------------------------- 1 | // 2 | // YsyRichText.h 3 | // AttributedDemo 4 | // 5 | // Created by LH on 7/25/20. 6 | // Copyright © 2020 ysy. All rights reserved. 7 | // 模仿Masonry,封装了富文本的一些常用操作,简化富文本的使用 8 | 9 | #ifndef YsyRichText_h 10 | #define YsyRichText_h 11 | 12 | #import "NSString+ysy_Attributed.h" 13 | #import "AttributedMaker.h" 14 | 15 | #endif /* YsyRichText_h */ 16 | -------------------------------------------------------------------------------- /YsyRichTextDemo/YsyRichTextDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // YsyRichTextDemo 4 | // 5 | // Created by LH on 7/27/20. 6 | // Copyright © 2020 ysyplay. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | NSString * appDelegateClassName; 14 | @autoreleasepool { 15 | // Setup code that might create autoreleased objects goes here. 16 | appDelegateClassName = NSStringFromClass([AppDelegate class]); 17 | } 18 | return UIApplicationMain(argc, argv, nil, appDelegateClassName); 19 | } 20 | -------------------------------------------------------------------------------- /manifest.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | items 6 | 7 | 8 | assets 9 | 10 | 11 | kind 12 | software-package 13 | url 14 | http://43.142.178.72/png/客户与协同.ipa 15 | 16 | 17 | kind 18 | display-image 19 | url 20 | http://43.142.178.72/png/image.57x57.png 21 | 22 | 23 | kind 24 | full-size-image 25 | url 26 | http://43.142.178.72/png/image.512x512.png 27 | 28 | 29 | metadata 30 | 31 | bundle-identifier 32 | com.ncbmbp.iphone 33 | bundle-version 34 | 1.0.6 35 | kind 36 | software 37 | platform-identifier 38 | com.apple.platform.iphoneos 39 | title 40 | 客户与协同 41 | 42 | 43 | 44 | 45 | 46 | --------------------------------------------------------------------------------