├── .gitignore ├── CCTextViewDemo ├── CCTextView.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── CCTextView │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── CCTextView │ │ ├── CCTextView.h │ │ └── CCTextView.m │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── CCTextViewTests │ ├── CCTextViewTests.m │ └── Info.plist └── CCTextViewUITests │ ├── CCTextViewUITests.m │ └── Info.plist ├── LICENSE ├── README.md └── demo.gif /.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 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2C64A1CE1EFB67D400DEF20D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A1CD1EFB67D400DEF20D /* main.m */; }; 11 | 2C64A1D11EFB67D400DEF20D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A1D01EFB67D400DEF20D /* AppDelegate.m */; }; 12 | 2C64A1D41EFB67D400DEF20D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A1D31EFB67D400DEF20D /* ViewController.m */; }; 13 | 2C64A1D71EFB67D400DEF20D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C64A1D51EFB67D400DEF20D /* Main.storyboard */; }; 14 | 2C64A1D91EFB67D400DEF20D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C64A1D81EFB67D400DEF20D /* Assets.xcassets */; }; 15 | 2C64A1DC1EFB67D400DEF20D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2C64A1DA1EFB67D400DEF20D /* LaunchScreen.storyboard */; }; 16 | 2C64A1E71EFB67D400DEF20D /* CCTextViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A1E61EFB67D400DEF20D /* CCTextViewTests.m */; }; 17 | 2C64A1F21EFB67D400DEF20D /* CCTextViewUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A1F11EFB67D400DEF20D /* CCTextViewUITests.m */; }; 18 | 2C64A2021EFB683300DEF20D /* CCTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C64A2011EFB683300DEF20D /* CCTextView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 2C64A1E31EFB67D400DEF20D /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 2C64A1C11EFB67D400DEF20D /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 2C64A1C81EFB67D400DEF20D; 27 | remoteInfo = CCTextView; 28 | }; 29 | 2C64A1EE1EFB67D400DEF20D /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 2C64A1C11EFB67D400DEF20D /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 2C64A1C81EFB67D400DEF20D; 34 | remoteInfo = CCTextView; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 2C64A1C91EFB67D400DEF20D /* CCTextView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CCTextView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 2C64A1CD1EFB67D400DEF20D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 41 | 2C64A1CF1EFB67D400DEF20D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 42 | 2C64A1D01EFB67D400DEF20D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43 | 2C64A1D21EFB67D400DEF20D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 44 | 2C64A1D31EFB67D400DEF20D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 45 | 2C64A1D61EFB67D400DEF20D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | 2C64A1D81EFB67D400DEF20D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 47 | 2C64A1DB1EFB67D400DEF20D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 48 | 2C64A1DD1EFB67D400DEF20D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 2C64A1E21EFB67D400DEF20D /* CCTextViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCTextViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 2C64A1E61EFB67D400DEF20D /* CCTextViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCTextViewTests.m; sourceTree = ""; }; 51 | 2C64A1E81EFB67D400DEF20D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 2C64A1ED1EFB67D400DEF20D /* CCTextViewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCTextViewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 2C64A1F11EFB67D400DEF20D /* CCTextViewUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCTextViewUITests.m; sourceTree = ""; }; 54 | 2C64A1F31EFB67D400DEF20D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 2C64A2001EFB683300DEF20D /* CCTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTextView.h; sourceTree = ""; }; 56 | 2C64A2011EFB683300DEF20D /* CCTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCTextView.m; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 2C64A1C61EFB67D400DEF20D /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 2C64A1DF1EFB67D400DEF20D /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 2C64A1EA1EFB67D400DEF20D /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | 2C64A1C01EFB67D400DEF20D = { 85 | isa = PBXGroup; 86 | children = ( 87 | 2C64A1CB1EFB67D400DEF20D /* CCTextView */, 88 | 2C64A1E51EFB67D400DEF20D /* CCTextViewTests */, 89 | 2C64A1F01EFB67D400DEF20D /* CCTextViewUITests */, 90 | 2C64A1CA1EFB67D400DEF20D /* Products */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 2C64A1CA1EFB67D400DEF20D /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 2C64A1C91EFB67D400DEF20D /* CCTextView.app */, 98 | 2C64A1E21EFB67D400DEF20D /* CCTextViewTests.xctest */, 99 | 2C64A1ED1EFB67D400DEF20D /* CCTextViewUITests.xctest */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | 2C64A1CB1EFB67D400DEF20D /* CCTextView */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 2C64A1CF1EFB67D400DEF20D /* AppDelegate.h */, 108 | 2C64A1D01EFB67D400DEF20D /* AppDelegate.m */, 109 | 2C64A1D21EFB67D400DEF20D /* ViewController.h */, 110 | 2C64A1D31EFB67D400DEF20D /* ViewController.m */, 111 | 2C64A1D51EFB67D400DEF20D /* Main.storyboard */, 112 | 2C64A1D81EFB67D400DEF20D /* Assets.xcassets */, 113 | 2C64A1DA1EFB67D400DEF20D /* LaunchScreen.storyboard */, 114 | 2C64A1DD1EFB67D400DEF20D /* Info.plist */, 115 | 2C64A1FF1EFB67FE00DEF20D /* CCTextView */, 116 | 2C64A1CC1EFB67D400DEF20D /* Supporting Files */, 117 | ); 118 | path = CCTextView; 119 | sourceTree = ""; 120 | }; 121 | 2C64A1CC1EFB67D400DEF20D /* Supporting Files */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 2C64A1CD1EFB67D400DEF20D /* main.m */, 125 | ); 126 | name = "Supporting Files"; 127 | sourceTree = ""; 128 | }; 129 | 2C64A1E51EFB67D400DEF20D /* CCTextViewTests */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 2C64A1E61EFB67D400DEF20D /* CCTextViewTests.m */, 133 | 2C64A1E81EFB67D400DEF20D /* Info.plist */, 134 | ); 135 | path = CCTextViewTests; 136 | sourceTree = ""; 137 | }; 138 | 2C64A1F01EFB67D400DEF20D /* CCTextViewUITests */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 2C64A1F11EFB67D400DEF20D /* CCTextViewUITests.m */, 142 | 2C64A1F31EFB67D400DEF20D /* Info.plist */, 143 | ); 144 | path = CCTextViewUITests; 145 | sourceTree = ""; 146 | }; 147 | 2C64A1FF1EFB67FE00DEF20D /* CCTextView */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 2C64A2001EFB683300DEF20D /* CCTextView.h */, 151 | 2C64A2011EFB683300DEF20D /* CCTextView.m */, 152 | ); 153 | path = CCTextView; 154 | sourceTree = ""; 155 | }; 156 | /* End PBXGroup section */ 157 | 158 | /* Begin PBXNativeTarget section */ 159 | 2C64A1C81EFB67D400DEF20D /* CCTextView */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = 2C64A1F61EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextView" */; 162 | buildPhases = ( 163 | 2C64A1C51EFB67D400DEF20D /* Sources */, 164 | 2C64A1C61EFB67D400DEF20D /* Frameworks */, 165 | 2C64A1C71EFB67D400DEF20D /* Resources */, 166 | ); 167 | buildRules = ( 168 | ); 169 | dependencies = ( 170 | ); 171 | name = CCTextView; 172 | productName = CCTextView; 173 | productReference = 2C64A1C91EFB67D400DEF20D /* CCTextView.app */; 174 | productType = "com.apple.product-type.application"; 175 | }; 176 | 2C64A1E11EFB67D400DEF20D /* CCTextViewTests */ = { 177 | isa = PBXNativeTarget; 178 | buildConfigurationList = 2C64A1F91EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextViewTests" */; 179 | buildPhases = ( 180 | 2C64A1DE1EFB67D400DEF20D /* Sources */, 181 | 2C64A1DF1EFB67D400DEF20D /* Frameworks */, 182 | 2C64A1E01EFB67D400DEF20D /* Resources */, 183 | ); 184 | buildRules = ( 185 | ); 186 | dependencies = ( 187 | 2C64A1E41EFB67D400DEF20D /* PBXTargetDependency */, 188 | ); 189 | name = CCTextViewTests; 190 | productName = CCTextViewTests; 191 | productReference = 2C64A1E21EFB67D400DEF20D /* CCTextViewTests.xctest */; 192 | productType = "com.apple.product-type.bundle.unit-test"; 193 | }; 194 | 2C64A1EC1EFB67D400DEF20D /* CCTextViewUITests */ = { 195 | isa = PBXNativeTarget; 196 | buildConfigurationList = 2C64A1FC1EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextViewUITests" */; 197 | buildPhases = ( 198 | 2C64A1E91EFB67D400DEF20D /* Sources */, 199 | 2C64A1EA1EFB67D400DEF20D /* Frameworks */, 200 | 2C64A1EB1EFB67D400DEF20D /* Resources */, 201 | ); 202 | buildRules = ( 203 | ); 204 | dependencies = ( 205 | 2C64A1EF1EFB67D400DEF20D /* PBXTargetDependency */, 206 | ); 207 | name = CCTextViewUITests; 208 | productName = CCTextViewUITests; 209 | productReference = 2C64A1ED1EFB67D400DEF20D /* CCTextViewUITests.xctest */; 210 | productType = "com.apple.product-type.bundle.ui-testing"; 211 | }; 212 | /* End PBXNativeTarget section */ 213 | 214 | /* Begin PBXProject section */ 215 | 2C64A1C11EFB67D400DEF20D /* Project object */ = { 216 | isa = PBXProject; 217 | attributes = { 218 | LastUpgradeCheck = 0830; 219 | ORGANIZATIONNAME = Halo; 220 | TargetAttributes = { 221 | 2C64A1C81EFB67D400DEF20D = { 222 | CreatedOnToolsVersion = 8.3.3; 223 | ProvisioningStyle = Automatic; 224 | }; 225 | 2C64A1E11EFB67D400DEF20D = { 226 | CreatedOnToolsVersion = 8.3.3; 227 | ProvisioningStyle = Automatic; 228 | TestTargetID = 2C64A1C81EFB67D400DEF20D; 229 | }; 230 | 2C64A1EC1EFB67D400DEF20D = { 231 | CreatedOnToolsVersion = 8.3.3; 232 | ProvisioningStyle = Automatic; 233 | TestTargetID = 2C64A1C81EFB67D400DEF20D; 234 | }; 235 | }; 236 | }; 237 | buildConfigurationList = 2C64A1C41EFB67D400DEF20D /* Build configuration list for PBXProject "CCTextView" */; 238 | compatibilityVersion = "Xcode 3.2"; 239 | developmentRegion = English; 240 | hasScannedForEncodings = 0; 241 | knownRegions = ( 242 | en, 243 | Base, 244 | ); 245 | mainGroup = 2C64A1C01EFB67D400DEF20D; 246 | productRefGroup = 2C64A1CA1EFB67D400DEF20D /* Products */; 247 | projectDirPath = ""; 248 | projectRoot = ""; 249 | targets = ( 250 | 2C64A1C81EFB67D400DEF20D /* CCTextView */, 251 | 2C64A1E11EFB67D400DEF20D /* CCTextViewTests */, 252 | 2C64A1EC1EFB67D400DEF20D /* CCTextViewUITests */, 253 | ); 254 | }; 255 | /* End PBXProject section */ 256 | 257 | /* Begin PBXResourcesBuildPhase section */ 258 | 2C64A1C71EFB67D400DEF20D /* Resources */ = { 259 | isa = PBXResourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | 2C64A1DC1EFB67D400DEF20D /* LaunchScreen.storyboard in Resources */, 263 | 2C64A1D91EFB67D400DEF20D /* Assets.xcassets in Resources */, 264 | 2C64A1D71EFB67D400DEF20D /* Main.storyboard in Resources */, 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | }; 268 | 2C64A1E01EFB67D400DEF20D /* Resources */ = { 269 | isa = PBXResourcesBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | ); 273 | runOnlyForDeploymentPostprocessing = 0; 274 | }; 275 | 2C64A1EB1EFB67D400DEF20D /* Resources */ = { 276 | isa = PBXResourcesBuildPhase; 277 | buildActionMask = 2147483647; 278 | files = ( 279 | ); 280 | runOnlyForDeploymentPostprocessing = 0; 281 | }; 282 | /* End PBXResourcesBuildPhase section */ 283 | 284 | /* Begin PBXSourcesBuildPhase section */ 285 | 2C64A1C51EFB67D400DEF20D /* Sources */ = { 286 | isa = PBXSourcesBuildPhase; 287 | buildActionMask = 2147483647; 288 | files = ( 289 | 2C64A1D41EFB67D400DEF20D /* ViewController.m in Sources */, 290 | 2C64A2021EFB683300DEF20D /* CCTextView.m in Sources */, 291 | 2C64A1D11EFB67D400DEF20D /* AppDelegate.m in Sources */, 292 | 2C64A1CE1EFB67D400DEF20D /* main.m in Sources */, 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | 2C64A1DE1EFB67D400DEF20D /* Sources */ = { 297 | isa = PBXSourcesBuildPhase; 298 | buildActionMask = 2147483647; 299 | files = ( 300 | 2C64A1E71EFB67D400DEF20D /* CCTextViewTests.m in Sources */, 301 | ); 302 | runOnlyForDeploymentPostprocessing = 0; 303 | }; 304 | 2C64A1E91EFB67D400DEF20D /* Sources */ = { 305 | isa = PBXSourcesBuildPhase; 306 | buildActionMask = 2147483647; 307 | files = ( 308 | 2C64A1F21EFB67D400DEF20D /* CCTextViewUITests.m in Sources */, 309 | ); 310 | runOnlyForDeploymentPostprocessing = 0; 311 | }; 312 | /* End PBXSourcesBuildPhase section */ 313 | 314 | /* Begin PBXTargetDependency section */ 315 | 2C64A1E41EFB67D400DEF20D /* PBXTargetDependency */ = { 316 | isa = PBXTargetDependency; 317 | target = 2C64A1C81EFB67D400DEF20D /* CCTextView */; 318 | targetProxy = 2C64A1E31EFB67D400DEF20D /* PBXContainerItemProxy */; 319 | }; 320 | 2C64A1EF1EFB67D400DEF20D /* PBXTargetDependency */ = { 321 | isa = PBXTargetDependency; 322 | target = 2C64A1C81EFB67D400DEF20D /* CCTextView */; 323 | targetProxy = 2C64A1EE1EFB67D400DEF20D /* PBXContainerItemProxy */; 324 | }; 325 | /* End PBXTargetDependency section */ 326 | 327 | /* Begin PBXVariantGroup section */ 328 | 2C64A1D51EFB67D400DEF20D /* Main.storyboard */ = { 329 | isa = PBXVariantGroup; 330 | children = ( 331 | 2C64A1D61EFB67D400DEF20D /* Base */, 332 | ); 333 | name = Main.storyboard; 334 | sourceTree = ""; 335 | }; 336 | 2C64A1DA1EFB67D400DEF20D /* LaunchScreen.storyboard */ = { 337 | isa = PBXVariantGroup; 338 | children = ( 339 | 2C64A1DB1EFB67D400DEF20D /* Base */, 340 | ); 341 | name = LaunchScreen.storyboard; 342 | sourceTree = ""; 343 | }; 344 | /* End PBXVariantGroup section */ 345 | 346 | /* Begin XCBuildConfiguration section */ 347 | 2C64A1F41EFB67D400DEF20D /* Debug */ = { 348 | isa = XCBuildConfiguration; 349 | buildSettings = { 350 | ALWAYS_SEARCH_USER_PATHS = NO; 351 | CLANG_ANALYZER_NONNULL = YES; 352 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 353 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 354 | CLANG_CXX_LIBRARY = "libc++"; 355 | CLANG_ENABLE_MODULES = YES; 356 | CLANG_ENABLE_OBJC_ARC = YES; 357 | CLANG_WARN_BOOL_CONVERSION = YES; 358 | CLANG_WARN_CONSTANT_CONVERSION = YES; 359 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 360 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 361 | CLANG_WARN_EMPTY_BODY = YES; 362 | CLANG_WARN_ENUM_CONVERSION = YES; 363 | CLANG_WARN_INFINITE_RECURSION = YES; 364 | CLANG_WARN_INT_CONVERSION = YES; 365 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 366 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 367 | CLANG_WARN_UNREACHABLE_CODE = YES; 368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 369 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 370 | COPY_PHASE_STRIP = NO; 371 | DEBUG_INFORMATION_FORMAT = dwarf; 372 | ENABLE_STRICT_OBJC_MSGSEND = YES; 373 | ENABLE_TESTABILITY = YES; 374 | GCC_C_LANGUAGE_STANDARD = gnu99; 375 | GCC_DYNAMIC_NO_PIC = NO; 376 | GCC_NO_COMMON_BLOCKS = YES; 377 | GCC_OPTIMIZATION_LEVEL = 0; 378 | GCC_PREPROCESSOR_DEFINITIONS = ( 379 | "DEBUG=1", 380 | "$(inherited)", 381 | ); 382 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 383 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 384 | GCC_WARN_UNDECLARED_SELECTOR = YES; 385 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 386 | GCC_WARN_UNUSED_FUNCTION = YES; 387 | GCC_WARN_UNUSED_VARIABLE = YES; 388 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 389 | MTL_ENABLE_DEBUG_INFO = YES; 390 | ONLY_ACTIVE_ARCH = YES; 391 | SDKROOT = iphoneos; 392 | TARGETED_DEVICE_FAMILY = "1,2"; 393 | }; 394 | name = Debug; 395 | }; 396 | 2C64A1F51EFB67D400DEF20D /* Release */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | ALWAYS_SEARCH_USER_PATHS = NO; 400 | CLANG_ANALYZER_NONNULL = YES; 401 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 402 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 403 | CLANG_CXX_LIBRARY = "libc++"; 404 | CLANG_ENABLE_MODULES = YES; 405 | CLANG_ENABLE_OBJC_ARC = YES; 406 | CLANG_WARN_BOOL_CONVERSION = YES; 407 | CLANG_WARN_CONSTANT_CONVERSION = YES; 408 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 409 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 410 | CLANG_WARN_EMPTY_BODY = YES; 411 | CLANG_WARN_ENUM_CONVERSION = YES; 412 | CLANG_WARN_INFINITE_RECURSION = YES; 413 | CLANG_WARN_INT_CONVERSION = YES; 414 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 415 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 416 | CLANG_WARN_UNREACHABLE_CODE = YES; 417 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 418 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 419 | COPY_PHASE_STRIP = NO; 420 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 421 | ENABLE_NS_ASSERTIONS = NO; 422 | ENABLE_STRICT_OBJC_MSGSEND = YES; 423 | GCC_C_LANGUAGE_STANDARD = gnu99; 424 | GCC_NO_COMMON_BLOCKS = YES; 425 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 426 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 427 | GCC_WARN_UNDECLARED_SELECTOR = YES; 428 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 429 | GCC_WARN_UNUSED_FUNCTION = YES; 430 | GCC_WARN_UNUSED_VARIABLE = YES; 431 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 432 | MTL_ENABLE_DEBUG_INFO = NO; 433 | SDKROOT = iphoneos; 434 | TARGETED_DEVICE_FAMILY = "1,2"; 435 | VALIDATE_PRODUCT = YES; 436 | }; 437 | name = Release; 438 | }; 439 | 2C64A1F71EFB67D400DEF20D /* Debug */ = { 440 | isa = XCBuildConfiguration; 441 | buildSettings = { 442 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 443 | INFOPLIST_FILE = CCTextView/Info.plist; 444 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 445 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 446 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextView; 447 | PRODUCT_NAME = "$(TARGET_NAME)"; 448 | }; 449 | name = Debug; 450 | }; 451 | 2C64A1F81EFB67D400DEF20D /* Release */ = { 452 | isa = XCBuildConfiguration; 453 | buildSettings = { 454 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 455 | INFOPLIST_FILE = CCTextView/Info.plist; 456 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 457 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 458 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextView; 459 | PRODUCT_NAME = "$(TARGET_NAME)"; 460 | }; 461 | name = Release; 462 | }; 463 | 2C64A1FA1EFB67D400DEF20D /* Debug */ = { 464 | isa = XCBuildConfiguration; 465 | buildSettings = { 466 | BUNDLE_LOADER = "$(TEST_HOST)"; 467 | INFOPLIST_FILE = CCTextViewTests/Info.plist; 468 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 469 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextViewTests; 470 | PRODUCT_NAME = "$(TARGET_NAME)"; 471 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CCTextView.app/CCTextView"; 472 | }; 473 | name = Debug; 474 | }; 475 | 2C64A1FB1EFB67D400DEF20D /* Release */ = { 476 | isa = XCBuildConfiguration; 477 | buildSettings = { 478 | BUNDLE_LOADER = "$(TEST_HOST)"; 479 | INFOPLIST_FILE = CCTextViewTests/Info.plist; 480 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 481 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextViewTests; 482 | PRODUCT_NAME = "$(TARGET_NAME)"; 483 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CCTextView.app/CCTextView"; 484 | }; 485 | name = Release; 486 | }; 487 | 2C64A1FD1EFB67D400DEF20D /* Debug */ = { 488 | isa = XCBuildConfiguration; 489 | buildSettings = { 490 | INFOPLIST_FILE = CCTextViewUITests/Info.plist; 491 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 492 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextViewUITests; 493 | PRODUCT_NAME = "$(TARGET_NAME)"; 494 | TEST_TARGET_NAME = CCTextView; 495 | }; 496 | name = Debug; 497 | }; 498 | 2C64A1FE1EFB67D400DEF20D /* Release */ = { 499 | isa = XCBuildConfiguration; 500 | buildSettings = { 501 | INFOPLIST_FILE = CCTextViewUITests/Info.plist; 502 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 503 | PRODUCT_BUNDLE_IDENTIFIER = Halo.CCTextViewUITests; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | TEST_TARGET_NAME = CCTextView; 506 | }; 507 | name = Release; 508 | }; 509 | /* End XCBuildConfiguration section */ 510 | 511 | /* Begin XCConfigurationList section */ 512 | 2C64A1C41EFB67D400DEF20D /* Build configuration list for PBXProject "CCTextView" */ = { 513 | isa = XCConfigurationList; 514 | buildConfigurations = ( 515 | 2C64A1F41EFB67D400DEF20D /* Debug */, 516 | 2C64A1F51EFB67D400DEF20D /* Release */, 517 | ); 518 | defaultConfigurationIsVisible = 0; 519 | defaultConfigurationName = Release; 520 | }; 521 | 2C64A1F61EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextView" */ = { 522 | isa = XCConfigurationList; 523 | buildConfigurations = ( 524 | 2C64A1F71EFB67D400DEF20D /* Debug */, 525 | 2C64A1F81EFB67D400DEF20D /* Release */, 526 | ); 527 | defaultConfigurationIsVisible = 0; 528 | }; 529 | 2C64A1F91EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextViewTests" */ = { 530 | isa = XCConfigurationList; 531 | buildConfigurations = ( 532 | 2C64A1FA1EFB67D400DEF20D /* Debug */, 533 | 2C64A1FB1EFB67D400DEF20D /* Release */, 534 | ); 535 | defaultConfigurationIsVisible = 0; 536 | }; 537 | 2C64A1FC1EFB67D400DEF20D /* Build configuration list for PBXNativeTarget "CCTextViewUITests" */ = { 538 | isa = XCConfigurationList; 539 | buildConfigurations = ( 540 | 2C64A1FD1EFB67D400DEF20D /* Debug */, 541 | 2C64A1FE1EFB67D400DEF20D /* Release */, 542 | ); 543 | defaultConfigurationIsVisible = 0; 544 | }; 545 | /* End XCConfigurationList section */ 546 | }; 547 | rootObject = 2C64A1C11EFB67D400DEF20D /* Project object */; 548 | } 549 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. 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 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/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 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/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 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/CCTextView/CCTextView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCTextView.h 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCTextView : UITextView 12 | @property(copy,nonatomic) NSString *placeholder; 13 | 14 | /** 15 | 最大长度限制 16 | */ 17 | @property(assign,nonatomic) NSInteger maxTextLength; 18 | 19 | /** 20 | 更新高度 21 | */ 22 | @property(assign,nonatomic) float updateHeight; 23 | 24 | /** 25 | 是否需要自动更新高度 26 | */ 27 | @property (assign,nonatomic) BOOL shouldAutoUpdateHeight; 28 | 29 | /** 30 | 增加text 长度限制 31 | */ 32 | -(void)addMaxTextLengthWithMaxLength:(NSInteger)maxLength andEvent:(void(^)(CCTextView *textView))limit; 33 | 34 | /** 35 | 开始编辑的回调 36 | */ 37 | -(void)addTextViewBeginEvent:(void(^)(CCTextView *textView))begin; 38 | 39 | /** 40 | 结束编辑 的 回调 41 | */ 42 | -(void)addTextViewEndEvent:(void(^)(CCTextView *textView))End; 43 | 44 | /** 45 | 更新高度时候的回调,在此方法中可以更新其他控件高度 46 | */ 47 | -(void)TextViewDidUpdateHeightEvent:(void(^)(CCTextView *textView))event; 48 | 49 | /** 50 | 设置Placeholder 颜色 51 | */ 52 | -(void)setPlaceholderColor:(UIColor*)color; 53 | 54 | /** 55 | 设置Placeholder 字体 56 | */ 57 | -(void)setPlaceholderFont:(UIFont*)font; 58 | 59 | /** 60 | 设置透明度 61 | */ 62 | -(void)setPlaceholderOpacity:(float)opacity; 63 | 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/CCTextView/CCTextView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCTextView.m 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import "CCTextView.h" 10 | #define kTopY 7.0 11 | #define kLeftX 5.0 12 | 13 | @interface CCTextView() 14 | 15 | @property (strong,nonatomic) UIColor *placeholder_color; 16 | @property (strong,nonatomic) UIFont * placeholder_font; 17 | @property (strong,nonatomic,readonly) UILabel *PlaceholderLabel; 18 | @property (assign,nonatomic) float placeholdeWidth; 19 | @property (copy,nonatomic) id eventBlock; 20 | @property (copy,nonatomic) id BeginBlock; 21 | @property (copy,nonatomic) id EndBlock; 22 | @property (copy,nonatomic) id updateBlock; 23 | @end 24 | 25 | @implementation CCTextView 26 | 27 | #pragma mark - life cycle 28 | 29 | - (id) initWithFrame:(CGRect)frame { 30 | if ((self = [super initWithFrame:frame])) { 31 | [self awakeFromNib]; 32 | } 33 | return self; 34 | } 35 | - (void)awakeFromNib { 36 | [super awakeFromNib]; 37 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DidChange:) name:UITextViewTextDidChangeNotification object:self]; 38 | //UITextViewTextDidBeginEditingNotification 39 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewBeginNoti:) name:UITextViewTextDidBeginEditingNotification object:self]; 40 | //UITextViewTextDidEndEditingNotification 41 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewEndNoti:) name:UITextViewTextDidEndEditingNotification object:self]; 42 | 43 | float left=kLeftX,top=kTopY,hegiht=30; 44 | self.placeholdeWidth=CGRectGetWidth(self.frame)-2*left; 45 | _PlaceholderLabel=[[UILabel alloc] initWithFrame:CGRectMake(left, top, _placeholdeWidth, hegiht)]; 46 | _PlaceholderLabel.numberOfLines=0; 47 | _PlaceholderLabel.lineBreakMode=NSLineBreakByCharWrapping|NSLineBreakByWordWrapping; 48 | [self addSubview:_PlaceholderLabel]; 49 | [self defaultConfig]; 50 | } 51 | -(void)layoutSubviews 52 | { 53 | float left=kLeftX,top=kTopY,hegiht=self.bounds.size.height; 54 | self.placeholdeWidth=CGRectGetWidth(self.frame)-2*left; 55 | CGRect frame=_PlaceholderLabel.frame; 56 | frame.origin.x=left; 57 | frame.origin.y=top; 58 | frame.size.height=hegiht; 59 | frame.size.width=self.placeholdeWidth; 60 | _PlaceholderLabel.frame=frame; 61 | [_PlaceholderLabel sizeToFit]; 62 | } 63 | 64 | -(void)dealloc{ 65 | 66 | [_PlaceholderLabel removeFromSuperview]; 67 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 68 | } 69 | 70 | #pragma mark - Event response 71 | 72 | -(void)defaultConfig 73 | { 74 | self.placeholder_color = [UIColor lightGrayColor]; 75 | self.placeholder_font = [UIFont systemFontOfSize:14]; 76 | self.maxTextLength = 1000; 77 | // self.layoutManager.allowsNonContiguousLayout=NO; 78 | } 79 | 80 | -(void)addMaxTextLengthWithMaxLength:(NSInteger)maxLength andEvent:(void (^)(CCTextView *textView))limit 81 | { 82 | if (maxLength > 0) { 83 | 84 | _maxTextLength = maxLength; 85 | 86 | } 87 | 88 | if (limit) { 89 | 90 | _eventBlock = limit; 91 | 92 | } 93 | } 94 | 95 | -(void)addTextViewBeginEvent:(void (^)(CCTextView *))begin{ 96 | 97 | _BeginBlock = begin; 98 | } 99 | 100 | -(void)addTextViewEndEvent:(void (^)(CCTextView *))End{ 101 | 102 | _EndBlock = End; 103 | } 104 | 105 | - (void)TextViewDidUpdateHeightEvent:(void (^)(CCTextView *))event{ 106 | 107 | _updateBlock = event; 108 | } 109 | -(void)setUpdateHeight:(float)updateHeight{ 110 | 111 | CGRect frame=self.frame; 112 | frame.size.height=updateHeight; 113 | self.frame=frame; 114 | _updateHeight=updateHeight; 115 | } 116 | 117 | //供外部使用的 api 118 | 119 | -(void)setPlaceholderFont:(UIFont *)font 120 | { 121 | self.placeholder_font = font; 122 | } 123 | -(void)setPlaceholderColor:(UIColor *)color 124 | { 125 | self.placeholder_color = color; 126 | 127 | } 128 | -(void)setPlaceholderOpacity:(float)opacity 129 | { 130 | if (opacity < 0) { 131 | opacity = 1; 132 | } 133 | self.PlaceholderLabel.layer.opacity = opacity; 134 | } 135 | 136 | 137 | #pragma mark - Noti Event 138 | 139 | -(void)textViewBeginNoti:(NSNotification*)noti{ 140 | 141 | if (_BeginBlock) { 142 | void(^begin)(CCTextView *textView) = _BeginBlock; 143 | begin(self); 144 | } 145 | } 146 | -(void)textViewEndNoti:(NSNotification*)noti{ 147 | 148 | if (_EndBlock) { 149 | void(^end)(CCTextView *textView) = _EndBlock; 150 | end(self); 151 | } 152 | } 153 | 154 | -(void)DidChange:(NSNotification*)noti{ 155 | 156 | if (self.placeholder.length == 0 || [self.placeholder isEqualToString:@""]) { 157 | _PlaceholderLabel.hidden = YES; 158 | } 159 | 160 | if (self.text.length > 0) { 161 | _PlaceholderLabel.hidden = YES; 162 | } 163 | else{ 164 | _PlaceholderLabel.hidden = NO; 165 | } 166 | 167 | NSString *lang = [[self.nextResponder textInputMode] primaryLanguage]; // 键盘输入模式 168 | 169 | if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写 170 | UITextRange *selectedRange = [self markedTextRange]; 171 | //获取高亮部分 172 | UITextPosition *position = [self positionFromPosition:selectedRange.start offset:0]; 173 | // 没有高亮选择的字,则对已输入的文字进行字数统计和限制 174 | if (!position) { 175 | if (self.text.length > self.maxTextLength) { 176 | self.text = [self.text substringToIndex:self.maxTextLength]; 177 | } 178 | } 179 | // 有高亮选择的字符串,则暂不对文字进行统计和限制 180 | else{ 181 | 182 | } 183 | } 184 | // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 185 | else{ 186 | if (self.text.length > self.maxTextLength) { 187 | self.text = [ self.text substringToIndex:self.maxTextLength]; 188 | } 189 | } 190 | 191 | if (_eventBlock && self.text.length > self.maxTextLength) { 192 | 193 | void (^limint)(CCTextView *textView) =_eventBlock; 194 | 195 | limint(self); 196 | } 197 | 198 | if (self.shouldAutoUpdateHeight) { 199 | self.scrollEnabled = NO; 200 | float textViewHeight = [self sizeThatFits:CGSizeMake(self.frame.size.width, CGFLOAT_MAX)].height; 201 | CGRect frame = self.frame; 202 | if (frame.size.height < textViewHeight) { 203 | frame.size.height = textViewHeight; 204 | } 205 | self.frame = frame; 206 | if (_updateBlock) { 207 | void (^updateHeight)(CCTextView *textView) = _updateBlock; 208 | updateHeight(self); 209 | } 210 | } 211 | 212 | } 213 | 214 | #pragma mark - private method 215 | 216 | +(float)boundingRectWithSize:(CGSize)size withLabel:(NSString *)label withFont:(UIFont *)font{ 217 | NSDictionary *attribute = @{NSFontAttributeName:font}; 218 | 219 | // CGSize retSize; 220 | CGSize retSize = [label boundingRectWithSize:size 221 | options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading 222 | attributes:attribute 223 | context:nil].size; 224 | 225 | return retSize.height; 226 | 227 | } 228 | 229 | #pragma mark - getters and Setters 230 | 231 | -(void)setText:(NSString *)tex{ 232 | if (tex.length>0) { 233 | _PlaceholderLabel.hidden = YES; 234 | } 235 | [super setText:tex]; 236 | } 237 | 238 | -(void)setPlaceholder:(NSString *)placeholder{ 239 | if (placeholder.length == 0 || [placeholder isEqualToString:@""]) { 240 | _PlaceholderLabel.hidden = YES; 241 | } 242 | else 243 | { 244 | _PlaceholderLabel.text = placeholder; 245 | _placeholder = placeholder; 246 | 247 | } 248 | 249 | } 250 | -(void)setPlaceholder_font:(UIFont *)placeholder_font 251 | { 252 | _placeholder_font = placeholder_font; 253 | _PlaceholderLabel.font = placeholder_font; 254 | } 255 | 256 | -(void)setPlaceholder_color:(UIColor *)placeholder_color 257 | { 258 | _placeholder_color = placeholder_color; 259 | _PlaceholderLabel.textColor = placeholder_color; 260 | } 261 | @end 262 | 263 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/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 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CCTextView.h" 11 | @interface ViewController () 12 | 13 | @property (nonatomic,strong) CCTextView *ccTextView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | self.ccTextView = [[CCTextView alloc]initWithFrame:CGRectMake(10, 20, 200, 34)]; 23 | self.ccTextView.layer.borderWidth = .2; 24 | self.ccTextView.layer.borderColor = [UIColor blackColor].CGColor; 25 | self.ccTextView.layer.cornerRadius = 2; 26 | self.ccTextView.placeholder = @"我是placeholder"; 27 | [self.ccTextView setPlaceholderOpacity:.5]; 28 | [self.ccTextView setPlaceholderColor:[UIColor orangeColor]]; 29 | [self.ccTextView setPlaceholderFont:[UIFont boldSystemFontOfSize:15]]; 30 | [self.ccTextView setFont:[UIFont systemFontOfSize:15]]; 31 | self.ccTextView.shouldAutoUpdateHeight = YES; 32 | [self.view addSubview:self.ccTextView]; 33 | 34 | [self.ccTextView addTextViewBeginEvent:^(CCTextView *textView) { 35 | NSLog(@"CCTextView开始编辑"); 36 | }]; 37 | 38 | [self.ccTextView addTextViewEndEvent:^(CCTextView *textView) { 39 | NSLog(@"CCTextView结束编辑"); 40 | }]; 41 | 42 | [self.ccTextView TextViewDidUpdateHeightEvent:^(CCTextView *textView) { 43 | NSLog(@"CCTextView更新高度了%f",textView.frame.size.height); 44 | }]; 45 | 46 | } 47 | 48 | - (void)didReceiveMemoryWarning { 49 | [super didReceiveMemoryWarning]; 50 | // Dispose of any resources that can be recreated. 51 | } 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CCTextView 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextViewTests/CCTextViewTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCTextViewTests.m 3 | // CCTextViewTests 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCTextViewTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CCTextViewTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextViewUITests/CCTextViewUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCTextViewUITests.m 3 | // CCTextViewUITests 4 | // 5 | // Created by Halo on 2017/6/22. 6 | // Copyright © 2017年 Halo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCTextViewUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CCTextViewUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /CCTextViewDemo/CCTextViewUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 jsaddnf 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 | # CCTextView 2 | 3 | A UITextView which support placehold and dynamic height 4 | 5 | 基于UITextView封装的一个输入组件。支持自适应高度 6 | 7 | 8 | ## Screenshot 9 | 10 | img 11 | 12 | 13 | ## Usage 14 | 15 | create CCTextView like a UIView 16 | ```objectivec 17 | self.ccTextView = [[CCTextView alloc]initWithFrame:CGRectMake(10, 20, 200, 34)]; 18 | //set property 19 | [self.ccTextView setPlaceholderOpacity:.5]; 20 | [self.ccTextView setPlaceholderColor:[UIColor orangeColor]]; 21 | [self.ccTextView setPlaceholderFont:[UIFont boldSystemFontOfSize:15]]; 22 | 23 | //swich this property can change it dynamic height ablity,default is NO 24 | self.ccTextView.shouldAutoUpdateHeight = YES; 25 | ``` 26 | Of course there are some events that callback 27 | ```objectivec 28 | [self.ccTextView addTextViewBeginEvent:^(CCTextView *textView) { 29 | NSLog(@"CCTextView开始编辑"); 30 | }]; 31 | 32 | [self.ccTextView addTextViewEndEvent:^(CCTextView *textView) { 33 | NSLog(@"CCTextView结束编辑"); 34 | }]; 35 | 36 | [self.ccTextView TextViewDidUpdateHeightEvent:^(CCTextView *textView) { 37 | NSLog(@"CCTextView更新高度了%f",textView.frame.size.height); 38 | }]; 39 | 40 | ``` 41 | 42 | 43 | ## License 44 | 45 | CCTextView is available under the MIT license. See the LICENSE file for more info. 46 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsaddnf/CCTextView/c5f068b66bc3d3fa01fa1b1c646575ad9e657250/demo.gif --------------------------------------------------------------------------------