├── Demo.gif ├── Example ├── SBMessageInputView.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── Sacha.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── SBMessageInputView │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── ok.imageset │ │ ├── Contents.json │ │ ├── oval8.png │ │ ├── oval8@2x.png │ │ └── oval8@3x.png │ └── send.imageset │ │ ├── Contents.json │ │ ├── send.png │ │ ├── send@2x.png │ │ └── send@3x.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SBMessageInputView.swift │ └── ViewController.swift ├── Installation.gif ├── LICENSE ├── README.md ├── SBMessageInputView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── Sacha.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── SBMessageInputView ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── ok.imageset │ │ ├── Contents.json │ │ ├── oval8.png │ │ ├── oval8@2x.png │ │ └── oval8@3x.png │ └── send.imageset │ │ ├── Contents.json │ │ ├── send.png │ │ ├── send@2x.png │ │ └── send@3x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── SBMessageInputView.swift └── ViewController.swift └── Source └── SBMessageInputView.swift /Demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Demo.gif -------------------------------------------------------------------------------- /Example/SBMessageInputView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 996D90B020855C2A00C8D367 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90AF20855C2A00C8D367 /* AppDelegate.swift */; }; 11 | 996D90B220855C2A00C8D367 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90B120855C2A00C8D367 /* ViewController.swift */; }; 12 | 996D90B520855C2A00C8D367 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B320855C2A00C8D367 /* Main.storyboard */; }; 13 | 996D90B720855C2C00C8D367 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B620855C2C00C8D367 /* Assets.xcassets */; }; 14 | 996D90BA20855C2C00C8D367 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */; }; 15 | 996D90C220855C3E00C8D367 /* SBMessageInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SBMessageInputView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 996D90AF20855C2A00C8D367 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 996D90B120855C2A00C8D367 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 996D90B420855C2A00C8D367 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 996D90B620855C2C00C8D367 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 996D90B920855C2C00C8D367 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 996D90BB20855C2C00C8D367 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBMessageInputView.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 996D90A920855C2A00C8D367 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 996D90A320855C2A00C8D367 = { 41 | isa = PBXGroup; 42 | children = ( 43 | 996D90AE20855C2A00C8D367 /* SBMessageInputView */, 44 | 996D90AD20855C2A00C8D367 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 996D90AD20855C2A00C8D367 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 996D90AE20855C2A00C8D367 /* SBMessageInputView */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 996D90AF20855C2A00C8D367 /* AppDelegate.swift */, 60 | 996D90B120855C2A00C8D367 /* ViewController.swift */, 61 | 996D90B320855C2A00C8D367 /* Main.storyboard */, 62 | 996D90B620855C2C00C8D367 /* Assets.xcassets */, 63 | 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */, 64 | 996D90BB20855C2C00C8D367 /* Info.plist */, 65 | 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */, 66 | ); 67 | path = SBMessageInputView; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 996D90AB20855C2A00C8D367 /* SBMessageInputView */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 996D90BE20855C2C00C8D367 /* Build configuration list for PBXNativeTarget "SBMessageInputView" */; 76 | buildPhases = ( 77 | 996D90A820855C2A00C8D367 /* Sources */, 78 | 996D90A920855C2A00C8D367 /* Frameworks */, 79 | 996D90AA20855C2A00C8D367 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = SBMessageInputView; 86 | productName = SBMessageInputView; 87 | productReference = 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 996D90A420855C2A00C8D367 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0930; 97 | LastUpgradeCheck = 0930; 98 | ORGANIZATIONNAME = SB; 99 | TargetAttributes = { 100 | 996D90AB20855C2A00C8D367 = { 101 | CreatedOnToolsVersion = 9.3; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = 996D90A720855C2A00C8D367 /* Build configuration list for PBXProject "SBMessageInputView" */; 106 | compatibilityVersion = "Xcode 9.3"; 107 | developmentRegion = en; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | Base, 112 | ); 113 | mainGroup = 996D90A320855C2A00C8D367; 114 | productRefGroup = 996D90AD20855C2A00C8D367 /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | 996D90AB20855C2A00C8D367 /* SBMessageInputView */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | 996D90AA20855C2A00C8D367 /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | 996D90BA20855C2C00C8D367 /* LaunchScreen.storyboard in Resources */, 129 | 996D90B720855C2C00C8D367 /* Assets.xcassets in Resources */, 130 | 996D90B520855C2A00C8D367 /* Main.storyboard in Resources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXResourcesBuildPhase section */ 135 | 136 | /* Begin PBXSourcesBuildPhase section */ 137 | 996D90A820855C2A00C8D367 /* Sources */ = { 138 | isa = PBXSourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | 996D90B220855C2A00C8D367 /* ViewController.swift in Sources */, 142 | 996D90B020855C2A00C8D367 /* AppDelegate.swift in Sources */, 143 | 996D90C220855C3E00C8D367 /* SBMessageInputView.swift in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXVariantGroup section */ 150 | 996D90B320855C2A00C8D367 /* Main.storyboard */ = { 151 | isa = PBXVariantGroup; 152 | children = ( 153 | 996D90B420855C2A00C8D367 /* Base */, 154 | ); 155 | name = Main.storyboard; 156 | sourceTree = ""; 157 | }; 158 | 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | 996D90B920855C2C00C8D367 /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | 996D90BC20855C2C00C8D367 /* Debug */ = { 170 | isa = XCBuildConfiguration; 171 | buildSettings = { 172 | ALWAYS_SEARCH_USER_PATHS = NO; 173 | CLANG_ANALYZER_NONNULL = YES; 174 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_ENABLE_OBJC_WEAK = YES; 180 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_COMMA = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INFINITE_RECURSION = YES; 190 | CLANG_WARN_INT_CONVERSION = YES; 191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 193 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 195 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 196 | CLANG_WARN_STRICT_PROTOTYPES = YES; 197 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 198 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | CODE_SIGN_IDENTITY = "iPhone Developer"; 202 | COPY_PHASE_STRIP = NO; 203 | DEBUG_INFORMATION_FORMAT = dwarf; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | ENABLE_TESTABILITY = YES; 206 | GCC_C_LANGUAGE_STANDARD = gnu11; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_NO_COMMON_BLOCKS = YES; 209 | GCC_OPTIMIZATION_LEVEL = 0; 210 | GCC_PREPROCESSOR_DEFINITIONS = ( 211 | "DEBUG=1", 212 | "$(inherited)", 213 | ); 214 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 215 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 216 | GCC_WARN_UNDECLARED_SELECTOR = YES; 217 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 218 | GCC_WARN_UNUSED_FUNCTION = YES; 219 | GCC_WARN_UNUSED_VARIABLE = YES; 220 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 221 | MTL_ENABLE_DEBUG_INFO = YES; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | }; 227 | name = Debug; 228 | }; 229 | 996D90BD20855C2C00C8D367 /* Release */ = { 230 | isa = XCBuildConfiguration; 231 | buildSettings = { 232 | ALWAYS_SEARCH_USER_PATHS = NO; 233 | CLANG_ANALYZER_NONNULL = YES; 234 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_ENABLE_OBJC_WEAK = YES; 240 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_COMMA = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 253 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 256 | CLANG_WARN_STRICT_PROTOTYPES = YES; 257 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 258 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 259 | CLANG_WARN_UNREACHABLE_CODE = YES; 260 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 261 | CODE_SIGN_IDENTITY = "iPhone Developer"; 262 | COPY_PHASE_STRIP = NO; 263 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 264 | ENABLE_NS_ASSERTIONS = NO; 265 | ENABLE_STRICT_OBJC_MSGSEND = YES; 266 | GCC_C_LANGUAGE_STANDARD = gnu11; 267 | GCC_NO_COMMON_BLOCKS = YES; 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 275 | MTL_ENABLE_DEBUG_INFO = NO; 276 | SDKROOT = iphoneos; 277 | SWIFT_COMPILATION_MODE = wholemodule; 278 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 279 | VALIDATE_PRODUCT = YES; 280 | }; 281 | name = Release; 282 | }; 283 | 996D90BF20855C2C00C8D367 /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | CODE_SIGN_STYLE = Automatic; 288 | DEVELOPMENT_TEAM = S33B8MQWQ5; 289 | INFOPLIST_FILE = SBMessageInputView/Info.plist; 290 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 291 | LD_RUNPATH_SEARCH_PATHS = ( 292 | "$(inherited)", 293 | "@executable_path/Frameworks", 294 | ); 295 | PRODUCT_BUNDLE_IDENTIFIER = sb.SBMessageInputView; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | SWIFT_VERSION = 4.0; 298 | TARGETED_DEVICE_FAMILY = "1,2"; 299 | }; 300 | name = Debug; 301 | }; 302 | 996D90C020855C2C00C8D367 /* Release */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 306 | CODE_SIGN_STYLE = Automatic; 307 | DEVELOPMENT_TEAM = S33B8MQWQ5; 308 | INFOPLIST_FILE = SBMessageInputView/Info.plist; 309 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 310 | LD_RUNPATH_SEARCH_PATHS = ( 311 | "$(inherited)", 312 | "@executable_path/Frameworks", 313 | ); 314 | PRODUCT_BUNDLE_IDENTIFIER = sb.SBMessageInputView; 315 | PRODUCT_NAME = "$(TARGET_NAME)"; 316 | SWIFT_VERSION = 4.0; 317 | TARGETED_DEVICE_FAMILY = "1,2"; 318 | }; 319 | name = Release; 320 | }; 321 | /* End XCBuildConfiguration section */ 322 | 323 | /* Begin XCConfigurationList section */ 324 | 996D90A720855C2A00C8D367 /* Build configuration list for PBXProject "SBMessageInputView" */ = { 325 | isa = XCConfigurationList; 326 | buildConfigurations = ( 327 | 996D90BC20855C2C00C8D367 /* Debug */, 328 | 996D90BD20855C2C00C8D367 /* Release */, 329 | ); 330 | defaultConfigurationIsVisible = 0; 331 | defaultConfigurationName = Release; 332 | }; 333 | 996D90BE20855C2C00C8D367 /* Build configuration list for PBXNativeTarget "SBMessageInputView" */ = { 334 | isa = XCConfigurationList; 335 | buildConfigurations = ( 336 | 996D90BF20855C2C00C8D367 /* Debug */, 337 | 996D90C020855C2C00C8D367 /* Release */, 338 | ); 339 | defaultConfigurationIsVisible = 0; 340 | defaultConfigurationName = Release; 341 | }; 342 | /* End XCConfigurationList section */ 343 | }; 344 | rootObject = 996D90A420855C2A00C8D367 /* Project object */; 345 | } 346 | -------------------------------------------------------------------------------- /Example/SBMessageInputView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/SBMessageInputView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/SBMessageInputView.xcodeproj/xcuserdata/Sacha.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Example/SBMessageInputView.xcodeproj/xcuserdata/Sacha.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SBMessageInputView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/ok.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "oval8.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "oval8@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "oval8@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@2x.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@3x.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/send.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "send.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "send@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "send@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/send.imageset/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/send.imageset/send.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/send.imageset/send@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/send.imageset/send@2x.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/Assets.xcassets/send.imageset/send@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Example/SBMessageInputView/Assets.xcassets/send.imageset/send@3x.png -------------------------------------------------------------------------------- /Example/SBMessageInputView/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 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/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 | 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 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/SBMessageInputView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SBMessageInputView.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol SBMessageInputViewDelegate: class { 12 | 13 | // TextViewDelegate methods 14 | func inputView(textView: UITextView, shouldChangeTextInRange: NSRange, replacementText: String) -> Bool 15 | func inputViewDidChange(textView: UITextView) 16 | func inputViewDidBeginEditing(textView: UITextView) 17 | func inputViewShouldBeginEditing(textView: UITextView) -> Bool 18 | 19 | // Button tap callback methods 20 | func inputViewDidTapButton(button: UIButton) 21 | } 22 | 23 | @IBDesignable 24 | class SBMessageInputView: UIView { 25 | 26 | @IBInspectable var buttonImage: UIImage = SBMessageInputView.getDefaultImage() { 27 | didSet { 28 | button.setImage(buttonImage, for: .normal) 29 | } 30 | } 31 | 32 | @IBInspectable var viewBorderColor: UIColor = .gray { 33 | didSet { 34 | mainView.layer.borderColor = viewBorderColor.cgColor 35 | } 36 | } 37 | 38 | @IBInspectable var viewBorderWidth: CGFloat = 0.5 { 39 | didSet { 40 | mainView.layer.borderWidth = viewBorderWidth 41 | } 42 | } 43 | 44 | @IBInspectable var maxLines: CGFloat = 5.0 45 | 46 | @IBInspectable var textViewTopInset: CGFloat = 0.0 { 47 | didSet { 48 | textView.contentInset = UIEdgeInsets(top: textViewTopInset, left: textView.contentInset.left, bottom: textView.contentInset.bottom, right: textView.contentInset.right) 49 | } 50 | } 51 | 52 | @IBInspectable var textViewLeftInset: CGFloat = 8.0 { 53 | didSet { 54 | textView.contentInset = UIEdgeInsets(top: textView.contentInset.top, left: textViewLeftInset, bottom: textView.contentInset.bottom, right: textView.contentInset.right) 55 | } 56 | } 57 | 58 | var numberOfLines: CGFloat = 1.0 { 59 | didSet { 60 | if numberOfLines > oldValue && numberOfLines <= maxLines { 61 | increaseSize() 62 | } else if numberOfLines < oldValue && numberOfLines <= maxLines { 63 | reduceSize() 64 | } else { 65 | // do nothing 66 | } 67 | } 68 | } 69 | 70 | // Views 71 | var mainView = UIView() 72 | var textView = UITextView(frame: .zero) 73 | var button = UIButton() 74 | var heightConstraint: NSLayoutConstraint? 75 | 76 | // Heights 77 | var originalViewHeight: CGFloat = 0.0 78 | var containerViewHeight: CGFloat { 79 | let top: CGFloat = 4.0 80 | let bottom: CGFloat = 4.0 81 | return originalViewHeight - (top + bottom) 82 | } 83 | var buttonViewHeight: CGFloat = 26.0 84 | var lineHeight: CGFloat = 0.0 85 | 86 | // Delegate 87 | var delegate: SBMessageInputViewDelegate? 88 | 89 | override init(frame: CGRect) { 90 | super.init(frame: frame) 91 | setupView() 92 | } 93 | 94 | required init?(coder aDecoder: NSCoder) { 95 | super.init(coder: aDecoder) 96 | setupView() 97 | } 98 | 99 | class func getDefaultImage()-> UIImage { 100 | if let defaultImage = UIImage(named: "send") { 101 | return defaultImage 102 | } else { 103 | return UIImage() 104 | } 105 | } 106 | 107 | override func layoutSubviews() { 108 | super.layoutSubviews() 109 | 110 | if originalViewHeight == 0 { 111 | originalViewHeight = frame.height 112 | } 113 | 114 | mainView.layer.cornerRadius = containerViewHeight / 2.0 115 | setTextView() 116 | textView.setContentOffset(CGPoint(x: -textViewLeftInset - 20, y: -textViewTopInset), animated: false) 117 | } 118 | 119 | fileprivate func setupView() { 120 | setContainerView() 121 | } 122 | 123 | func increaseSize() { 124 | 125 | let newConstant = containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 126 | if let c = heightConstraint { 127 | c.constant = newConstant 128 | } else { 129 | for constraint in constraints { 130 | if constraint.firstAttribute == .height { 131 | constraint.constant = newConstant 132 | break 133 | } 134 | } 135 | } 136 | } 137 | 138 | func reduceSize() { 139 | 140 | let newConstant = numberOfLines == 1 ? containerViewHeight + 8.0 : containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 141 | if let c = heightConstraint { 142 | c.constant = newConstant 143 | } else { 144 | for constraint in constraints { 145 | if constraint.firstAttribute == .height { 146 | constraint.constant = newConstant 147 | break 148 | } 149 | } 150 | } 151 | } 152 | 153 | fileprivate func setContainerView() { 154 | mainView = UIView(frame: .zero) 155 | addSubview(mainView) 156 | 157 | mainView.translatesAutoresizingMaskIntoConstraints = false 158 | let leadingConstraint = NSLayoutConstraint(item: mainView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1, constant: 16) 159 | let trailingConstraint = NSLayoutConstraint(item: self, attribute: .trailing, relatedBy: .equal, toItem: mainView, attribute: .trailing, multiplier: 1, constant: 16) 160 | let topConstraint = NSLayoutConstraint(item: mainView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1, constant: 4) 161 | let bottomConstraint = NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: mainView, attribute: .bottom, multiplier: 1, constant: 4) 162 | 163 | addConstraints([topConstraint, bottomConstraint, leadingConstraint, trailingConstraint]) 164 | } 165 | 166 | fileprivate func setTextView() { 167 | 168 | if textView.delegate == nil { 169 | textView = UITextView(frame: .zero) 170 | textView.delegate = self 171 | 172 | button = UIButton(type: .custom) 173 | button.setImage(buttonImage, for: .normal) 174 | button.addTarget(self, action: #selector(didTapButton(sender:)), for: .touchUpInside) 175 | 176 | textView.clipsToBounds = true 177 | textView.layer.cornerRadius = containerViewHeight / 2.0 178 | textView.contentInset = UIEdgeInsets(top: textViewTopInset, left: 0.0, bottom: 0.0, right: 0.0) 179 | textView.font = UIFont.systemFont(ofSize: 18.0) 180 | 181 | mainView.addSubview(textView) 182 | mainView.addSubview(button) 183 | 184 | textView.translatesAutoresizingMaskIntoConstraints = false 185 | textView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor, constant: textViewLeftInset).isActive = true 186 | textView.topAnchor.constraint(equalTo: mainView.topAnchor, constant: 0.0).isActive = true 187 | textView.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: 0.0).isActive = true 188 | 189 | button.translatesAutoresizingMaskIntoConstraints = false 190 | button.heightAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 191 | button.widthAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 192 | button.leadingAnchor.constraint(equalTo: textView.trailingAnchor, constant: 5.0).isActive = true 193 | button.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: -5.0).isActive = true 194 | button.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: -5.5).isActive = true 195 | } 196 | } 197 | 198 | @objc fileprivate func didTapButton(sender: UIButton) { 199 | if let delegate = delegate { 200 | delegate.inputViewDidTapButton(button: sender) 201 | } 202 | } 203 | } 204 | 205 | extension SBMessageInputView: UITextViewDelegate { 206 | 207 | func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { 208 | if let delegate = delegate { 209 | return delegate.inputViewShouldBeginEditing(textView: textView) 210 | } 211 | return true 212 | } 213 | 214 | func textViewDidBeginEditing(_ textView: UITextView) { 215 | if let delegate = delegate { 216 | delegate.inputViewDidBeginEditing(textView: textView) 217 | } 218 | } 219 | 220 | func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { 221 | 222 | if let delegate = delegate { 223 | return delegate.inputView(textView: textView, shouldChangeTextInRange: range, replacementText: text) 224 | } 225 | return true 226 | } 227 | 228 | func textViewDidChange(_ textView: UITextView) { 229 | guard let font = textView.font else { return } 230 | let fontLineHeight = font.lineHeight 231 | 232 | let lines = round((textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / fontLineHeight) 233 | lineHeight = fontLineHeight 234 | numberOfLines = lines 235 | 236 | if let delegate = delegate { 237 | delegate.inputViewDidChange(textView: textView) 238 | } 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /Example/SBMessageInputView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Installation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/Installation.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2018 Google, Inc. http://angularjs.org 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SBMessageInputView 2 | 3 | A home made iMessage textview with an accessory button. 4 | Written using Swift 4.0. 5 | 6 | ![SBMessageInputView demo](https://github.com/KeiroMidori/SBMessageInputView/blob/master/Demo.gif) 7 | 8 | ### Prerequisites 9 | 10 | - Xcode 11 | - Swift 12 | 13 | ### Installing 14 | 15 | Just copy the file SBMessageInputView.swift into your project. 16 | 17 | - Create a view in your XIB or Storyboard. 18 | - Attach a 45 height constraint and a bottom constraint to where the text view must stick. 19 | - Implement the SBMessageInputViewDelegate methods for textview callbacks and send button callback. 20 | 21 | ![SBMessageInputView install](https://github.com/KeiroMidori/SBMessageInputView/blob/master/Installation.gif) 22 | 23 | ## Built With 24 | 25 | * [Xcode](https://developer.apple.com/xcode/downloads/) - IDE used 26 | 27 | ## Authors 28 | 29 | * **Sacha Becourt** - *Initial work* - [KeiroMidori](https://github.com/KeiroMidori) 30 | 31 | See also the list of [contributors](https://github.com/KeiroMidori/SBMessageInputView/graphs/contributors) who participated in this project. 32 | 33 | ## License 34 | 35 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 36 | 37 | ## Acknowledgments 38 | 39 | * Inspired by the iMessage app. 40 | -------------------------------------------------------------------------------- /SBMessageInputView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 996D90B020855C2A00C8D367 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90AF20855C2A00C8D367 /* AppDelegate.swift */; }; 11 | 996D90B220855C2A00C8D367 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90B120855C2A00C8D367 /* ViewController.swift */; }; 12 | 996D90B520855C2A00C8D367 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B320855C2A00C8D367 /* Main.storyboard */; }; 13 | 996D90B720855C2C00C8D367 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B620855C2C00C8D367 /* Assets.xcassets */; }; 14 | 996D90BA20855C2C00C8D367 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */; }; 15 | 996D90C220855C3E00C8D367 /* SBMessageInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SBMessageInputView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 996D90AF20855C2A00C8D367 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 996D90B120855C2A00C8D367 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 996D90B420855C2A00C8D367 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 996D90B620855C2C00C8D367 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 996D90B920855C2C00C8D367 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 996D90BB20855C2C00C8D367 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SBMessageInputView.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 996D90A920855C2A00C8D367 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 996D90A320855C2A00C8D367 = { 41 | isa = PBXGroup; 42 | children = ( 43 | 996D90AE20855C2A00C8D367 /* SBMessageInputView */, 44 | 996D90AD20855C2A00C8D367 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 996D90AD20855C2A00C8D367 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 996D90AE20855C2A00C8D367 /* SBMessageInputView */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 996D90AF20855C2A00C8D367 /* AppDelegate.swift */, 60 | 996D90B120855C2A00C8D367 /* ViewController.swift */, 61 | 996D90B320855C2A00C8D367 /* Main.storyboard */, 62 | 996D90B620855C2C00C8D367 /* Assets.xcassets */, 63 | 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */, 64 | 996D90BB20855C2C00C8D367 /* Info.plist */, 65 | 996D90C120855C3E00C8D367 /* SBMessageInputView.swift */, 66 | ); 67 | path = SBMessageInputView; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 996D90AB20855C2A00C8D367 /* SBMessageInputView */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 996D90BE20855C2C00C8D367 /* Build configuration list for PBXNativeTarget "SBMessageInputView" */; 76 | buildPhases = ( 77 | 996D90A820855C2A00C8D367 /* Sources */, 78 | 996D90A920855C2A00C8D367 /* Frameworks */, 79 | 996D90AA20855C2A00C8D367 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = SBMessageInputView; 86 | productName = SBMessageInputView; 87 | productReference = 996D90AC20855C2A00C8D367 /* SBMessageInputView.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 996D90A420855C2A00C8D367 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0930; 97 | LastUpgradeCheck = 0930; 98 | ORGANIZATIONNAME = SB; 99 | TargetAttributes = { 100 | 996D90AB20855C2A00C8D367 = { 101 | CreatedOnToolsVersion = 9.3; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = 996D90A720855C2A00C8D367 /* Build configuration list for PBXProject "SBMessageInputView" */; 106 | compatibilityVersion = "Xcode 9.3"; 107 | developmentRegion = en; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | Base, 112 | ); 113 | mainGroup = 996D90A320855C2A00C8D367; 114 | productRefGroup = 996D90AD20855C2A00C8D367 /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | 996D90AB20855C2A00C8D367 /* SBMessageInputView */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | 996D90AA20855C2A00C8D367 /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | 996D90BA20855C2C00C8D367 /* LaunchScreen.storyboard in Resources */, 129 | 996D90B720855C2C00C8D367 /* Assets.xcassets in Resources */, 130 | 996D90B520855C2A00C8D367 /* Main.storyboard in Resources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXResourcesBuildPhase section */ 135 | 136 | /* Begin PBXSourcesBuildPhase section */ 137 | 996D90A820855C2A00C8D367 /* Sources */ = { 138 | isa = PBXSourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | 996D90B220855C2A00C8D367 /* ViewController.swift in Sources */, 142 | 996D90B020855C2A00C8D367 /* AppDelegate.swift in Sources */, 143 | 996D90C220855C3E00C8D367 /* SBMessageInputView.swift in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXVariantGroup section */ 150 | 996D90B320855C2A00C8D367 /* Main.storyboard */ = { 151 | isa = PBXVariantGroup; 152 | children = ( 153 | 996D90B420855C2A00C8D367 /* Base */, 154 | ); 155 | name = Main.storyboard; 156 | sourceTree = ""; 157 | }; 158 | 996D90B820855C2C00C8D367 /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | 996D90B920855C2C00C8D367 /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | 996D90BC20855C2C00C8D367 /* Debug */ = { 170 | isa = XCBuildConfiguration; 171 | buildSettings = { 172 | ALWAYS_SEARCH_USER_PATHS = NO; 173 | CLANG_ANALYZER_NONNULL = YES; 174 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_ENABLE_OBJC_WEAK = YES; 180 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_COMMA = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INFINITE_RECURSION = YES; 190 | CLANG_WARN_INT_CONVERSION = YES; 191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 193 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 195 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 196 | CLANG_WARN_STRICT_PROTOTYPES = YES; 197 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 198 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | CODE_SIGN_IDENTITY = "iPhone Developer"; 202 | COPY_PHASE_STRIP = NO; 203 | DEBUG_INFORMATION_FORMAT = dwarf; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | ENABLE_TESTABILITY = YES; 206 | GCC_C_LANGUAGE_STANDARD = gnu11; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_NO_COMMON_BLOCKS = YES; 209 | GCC_OPTIMIZATION_LEVEL = 0; 210 | GCC_PREPROCESSOR_DEFINITIONS = ( 211 | "DEBUG=1", 212 | "$(inherited)", 213 | ); 214 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 215 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 216 | GCC_WARN_UNDECLARED_SELECTOR = YES; 217 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 218 | GCC_WARN_UNUSED_FUNCTION = YES; 219 | GCC_WARN_UNUSED_VARIABLE = YES; 220 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 221 | MTL_ENABLE_DEBUG_INFO = YES; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | }; 227 | name = Debug; 228 | }; 229 | 996D90BD20855C2C00C8D367 /* Release */ = { 230 | isa = XCBuildConfiguration; 231 | buildSettings = { 232 | ALWAYS_SEARCH_USER_PATHS = NO; 233 | CLANG_ANALYZER_NONNULL = YES; 234 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_ENABLE_OBJC_WEAK = YES; 240 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_COMMA = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 253 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 256 | CLANG_WARN_STRICT_PROTOTYPES = YES; 257 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 258 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 259 | CLANG_WARN_UNREACHABLE_CODE = YES; 260 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 261 | CODE_SIGN_IDENTITY = "iPhone Developer"; 262 | COPY_PHASE_STRIP = NO; 263 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 264 | ENABLE_NS_ASSERTIONS = NO; 265 | ENABLE_STRICT_OBJC_MSGSEND = YES; 266 | GCC_C_LANGUAGE_STANDARD = gnu11; 267 | GCC_NO_COMMON_BLOCKS = YES; 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 275 | MTL_ENABLE_DEBUG_INFO = NO; 276 | SDKROOT = iphoneos; 277 | SWIFT_COMPILATION_MODE = wholemodule; 278 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 279 | VALIDATE_PRODUCT = YES; 280 | }; 281 | name = Release; 282 | }; 283 | 996D90BF20855C2C00C8D367 /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | CODE_SIGN_STYLE = Automatic; 288 | DEVELOPMENT_TEAM = S33B8MQWQ5; 289 | INFOPLIST_FILE = SBMessageInputView/Info.plist; 290 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 291 | LD_RUNPATH_SEARCH_PATHS = ( 292 | "$(inherited)", 293 | "@executable_path/Frameworks", 294 | ); 295 | PRODUCT_BUNDLE_IDENTIFIER = sb.SBMessageInputView; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | SWIFT_VERSION = 4.0; 298 | TARGETED_DEVICE_FAMILY = "1,2"; 299 | }; 300 | name = Debug; 301 | }; 302 | 996D90C020855C2C00C8D367 /* Release */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 306 | CODE_SIGN_STYLE = Automatic; 307 | DEVELOPMENT_TEAM = S33B8MQWQ5; 308 | INFOPLIST_FILE = SBMessageInputView/Info.plist; 309 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 310 | LD_RUNPATH_SEARCH_PATHS = ( 311 | "$(inherited)", 312 | "@executable_path/Frameworks", 313 | ); 314 | PRODUCT_BUNDLE_IDENTIFIER = sb.SBMessageInputView; 315 | PRODUCT_NAME = "$(TARGET_NAME)"; 316 | SWIFT_VERSION = 4.0; 317 | TARGETED_DEVICE_FAMILY = "1,2"; 318 | }; 319 | name = Release; 320 | }; 321 | /* End XCBuildConfiguration section */ 322 | 323 | /* Begin XCConfigurationList section */ 324 | 996D90A720855C2A00C8D367 /* Build configuration list for PBXProject "SBMessageInputView" */ = { 325 | isa = XCConfigurationList; 326 | buildConfigurations = ( 327 | 996D90BC20855C2C00C8D367 /* Debug */, 328 | 996D90BD20855C2C00C8D367 /* Release */, 329 | ); 330 | defaultConfigurationIsVisible = 0; 331 | defaultConfigurationName = Release; 332 | }; 333 | 996D90BE20855C2C00C8D367 /* Build configuration list for PBXNativeTarget "SBMessageInputView" */ = { 334 | isa = XCConfigurationList; 335 | buildConfigurations = ( 336 | 996D90BF20855C2C00C8D367 /* Debug */, 337 | 996D90C020855C2C00C8D367 /* Release */, 338 | ); 339 | defaultConfigurationIsVisible = 0; 340 | defaultConfigurationName = Release; 341 | }; 342 | /* End XCConfigurationList section */ 343 | }; 344 | rootObject = 996D90A420855C2A00C8D367 /* Project object */; 345 | } 346 | -------------------------------------------------------------------------------- /SBMessageInputView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SBMessageInputView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SBMessageInputView.xcodeproj/xcuserdata/Sacha.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /SBMessageInputView.xcodeproj/xcuserdata/Sacha.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SBMessageInputView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | SBMessageInputView.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /SBMessageInputView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/ok.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "oval8.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "oval8@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "oval8@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/ok.imageset/oval8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/ok.imageset/oval8.png -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/ok.imageset/oval8@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@2x.png -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/ok.imageset/oval8@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/ok.imageset/oval8@3x.png -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/send.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "send.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "send@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "send@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/send.imageset/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/send.imageset/send.png -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/send.imageset/send@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/send.imageset/send@2x.png -------------------------------------------------------------------------------- /SBMessageInputView/Assets.xcassets/send.imageset/send@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeiroMidori/SBMessageInputView/8a8be1cfd4bbcb436cedf5677a48d7e7e7723fb6/SBMessageInputView/Assets.xcassets/send.imageset/send@3x.png -------------------------------------------------------------------------------- /SBMessageInputView/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 | -------------------------------------------------------------------------------- /SBMessageInputView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /SBMessageInputView/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 | 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 | -------------------------------------------------------------------------------- /SBMessageInputView/SBMessageInputView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SBMessageInputView.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol SBMessageInputViewDelegate: AnyObject { 12 | 13 | // TextViewDelegate methods 14 | func inputView(textView: UITextView, shouldChangeTextInRange: NSRange, replacementText: String) -> Bool 15 | func inputViewDidChange(textView: UITextView) 16 | func inputViewDidBeginEditing(textView: UITextView) 17 | func inputViewShouldBeginEditing(textView: UITextView) -> Bool 18 | 19 | // Button tap callback methods 20 | func inputViewDidTapButton(button: UIButton) 21 | } 22 | 23 | @IBDesignable 24 | class SBMessageInputView: UIView { 25 | 26 | @IBInspectable var placeholder: String = "" 27 | @IBInspectable var placeholderColor: UIColor = .lightGray 28 | @IBInspectable var textColor: UIColor = .black 29 | 30 | @IBInspectable var buttonImage: UIImage = SBMessageInputView.getDefaultImage() { 31 | didSet { 32 | guard let b = button else { return } 33 | b.setImage(buttonImage, for: .normal) 34 | } 35 | } 36 | 37 | @IBInspectable var viewBorderColor: UIColor = .gray { 38 | didSet { 39 | guard let mv = mainView else { return } 40 | mv.layer.borderColor = viewBorderColor.cgColor 41 | } 42 | } 43 | 44 | @IBInspectable var viewBorderWidth: CGFloat = 0.5 { 45 | didSet { 46 | guard let mv = mainView else { return } 47 | mv.layer.borderWidth = viewBorderWidth 48 | } 49 | } 50 | 51 | @IBInspectable var maxLines: CGFloat = 5.0 52 | 53 | @IBInspectable var textViewTopInset: CGFloat = 0.0 { 54 | didSet { 55 | guard let tv = textView else { return } 56 | tv.contentInset = UIEdgeInsets(top: textViewTopInset, left: tv.contentInset.left, bottom: tv.contentInset.bottom, right: tv.contentInset.right) 57 | } 58 | } 59 | 60 | @IBInspectable var textViewLeftInset: CGFloat = 8.0 { 61 | didSet { 62 | guard let tv = textView else { return } 63 | tv.contentInset = UIEdgeInsets(top: tv.contentInset.top, left: textViewLeftInset, bottom: tv.contentInset.bottom, right: tv.contentInset.right) 64 | } 65 | } 66 | 67 | var numberOfLines: CGFloat = 1.0 { 68 | didSet { 69 | if numberOfLines > oldValue && numberOfLines <= maxLines { 70 | increaseSize() 71 | } else if numberOfLines < oldValue && numberOfLines <= maxLines { 72 | reduceSize() 73 | } else { 74 | // do nothing 75 | } 76 | } 77 | } 78 | 79 | // Views 80 | var mainView: UIView? 81 | var textView: UITextView? 82 | var button: UIButton? 83 | var heightConstraint: NSLayoutConstraint? 84 | 85 | // Heights 86 | var originalViewHeight: CGFloat = 0.0 87 | var containerViewHeight: CGFloat { 88 | let top: CGFloat = 4.0 89 | let bottom: CGFloat = 4.0 90 | return originalViewHeight - (top + bottom) 91 | } 92 | var buttonViewHeight: CGFloat = 26.0 93 | var lineHeight: CGFloat = 0.0 94 | 95 | // Delegate 96 | var delegate: SBMessageInputViewDelegate? 97 | 98 | override init(frame: CGRect) { 99 | super.init(frame: frame) 100 | setupView() 101 | } 102 | 103 | required init?(coder aDecoder: NSCoder) { 104 | super.init(coder: aDecoder) 105 | setupView() 106 | } 107 | 108 | class func getDefaultImage()-> UIImage { 109 | if let defaultImage = UIImage(named: "send") { 110 | return defaultImage 111 | } else { 112 | return UIImage() 113 | } 114 | } 115 | 116 | override func layoutSubviews() { 117 | super.layoutSubviews() 118 | 119 | if originalViewHeight == 0 { originalViewHeight = frame.height } 120 | if let mv = mainView { mv.layer.cornerRadius = containerViewHeight / 2.0 } 121 | setTextView() 122 | if let tv = textView { tv.setContentOffset(CGPoint(x: -textViewLeftInset - 20, y: -textViewTopInset), animated: false) } 123 | } 124 | 125 | fileprivate func setupView() { 126 | setContainerView() 127 | } 128 | 129 | func increaseSize() { 130 | 131 | let newConstant = containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 132 | if let c = heightConstraint { 133 | c.constant = newConstant 134 | } else { 135 | for constraint in constraints { 136 | if constraint.firstAttribute == .height { 137 | constraint.constant = newConstant 138 | break 139 | } 140 | } 141 | } 142 | } 143 | 144 | func reduceSize() { 145 | 146 | let newConstant = numberOfLines == 1 ? containerViewHeight + 8.0 : containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 147 | if let c = heightConstraint { 148 | c.constant = newConstant 149 | } else { 150 | for constraint in constraints { 151 | if constraint.firstAttribute == .height { 152 | constraint.constant = newConstant 153 | break 154 | } 155 | } 156 | } 157 | } 158 | 159 | fileprivate func setContainerView() { 160 | if mainView == nil { 161 | mainView = UIView(frame: .zero) 162 | guard let mainView = self.mainView else { return } 163 | addSubview(mainView) 164 | 165 | mainView.translatesAutoresizingMaskIntoConstraints = false 166 | let leadingConstraint = NSLayoutConstraint(item: mainView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1, constant: 16) 167 | let trailingConstraint = NSLayoutConstraint(item: self, attribute: .trailing, relatedBy: .equal, toItem: mainView, attribute: .trailing, multiplier: 1, constant: 16) 168 | let topConstraint = NSLayoutConstraint(item: mainView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1, constant: 4) 169 | let bottomConstraint = NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: mainView, attribute: .bottom, multiplier: 1, constant: 4) 170 | 171 | addConstraints([topConstraint, bottomConstraint, leadingConstraint, trailingConstraint]) 172 | } 173 | } 174 | 175 | fileprivate func setTextView() { 176 | 177 | if textView == nil { 178 | textView = UITextView(frame: .zero) 179 | button = UIButton(type: .custom) 180 | 181 | guard let button = self.button, let textView = self.textView, let mainView = self.mainView else { return } 182 | textView.delegate = self 183 | 184 | if !placeholder.isEmpty { 185 | textView.text = placeholder 186 | textView.textColor = placeholderColor 187 | } 188 | 189 | button.setImage(buttonImage, for: .normal) 190 | button.addTarget(self, action: #selector(didTapButton(sender:)), for: .touchUpInside) 191 | 192 | textView.clipsToBounds = true 193 | textView.layer.cornerRadius = containerViewHeight / 2.0 194 | textView.contentInset = UIEdgeInsets(top: textViewTopInset, left: 0.0, bottom: 0.0, right: 0.0) 195 | textView.font = UIFont.systemFont(ofSize: 18.0) 196 | 197 | mainView.addSubview(textView) 198 | mainView.addSubview(button) 199 | 200 | textView.translatesAutoresizingMaskIntoConstraints = false 201 | textView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor, constant: textViewLeftInset).isActive = true 202 | textView.topAnchor.constraint(equalTo: mainView.topAnchor, constant: 0.0).isActive = true 203 | textView.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: 0.0).isActive = true 204 | 205 | button.translatesAutoresizingMaskIntoConstraints = false 206 | button.heightAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 207 | button.widthAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 208 | button.leadingAnchor.constraint(equalTo: textView.trailingAnchor, constant: 5.0).isActive = true 209 | button.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: -5.0).isActive = true 210 | button.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: -5.5).isActive = true 211 | } 212 | } 213 | 214 | @objc fileprivate func didTapButton(sender: UIButton) { 215 | if let delegate = delegate { 216 | delegate.inputViewDidTapButton(button: sender) 217 | } 218 | } 219 | } 220 | 221 | extension SBMessageInputView: UITextViewDelegate { 222 | 223 | func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { 224 | if let delegate = delegate { 225 | return delegate.inputViewShouldBeginEditing(textView: textView) 226 | } 227 | return true 228 | } 229 | 230 | func textViewDidBeginEditing(_ textView: UITextView) { 231 | 232 | if (textView.text == placeholder && textView.textColor == placeholderColor) { 233 | textView.text = "" 234 | textView.textColor = textColor 235 | } 236 | 237 | if let delegate = delegate { 238 | delegate.inputViewDidBeginEditing(textView: textView) 239 | } 240 | } 241 | 242 | func textViewDidEndEditing(_ textView: UITextView) { 243 | if (textView.text.isEmpty) { 244 | textView.text = placeholder 245 | textView.textColor = placeholderColor 246 | } 247 | } 248 | 249 | func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { 250 | 251 | if let delegate = delegate { 252 | return delegate.inputView(textView: textView, shouldChangeTextInRange: range, replacementText: text) 253 | } 254 | return true 255 | } 256 | 257 | func textViewDidChange(_ textView: UITextView) { 258 | guard let font = textView.font else { return } 259 | let fontLineHeight = font.lineHeight 260 | 261 | let lines = round((textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / fontLineHeight) 262 | lineHeight = fontLineHeight 263 | numberOfLines = lines 264 | 265 | if let delegate = delegate { 266 | delegate.inputViewDidChange(textView: textView) 267 | } 268 | } 269 | } 270 | -------------------------------------------------------------------------------- /SBMessageInputView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Source/SBMessageInputView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SBMessageInputView.swift 3 | // SBMessageInputView 4 | // 5 | // Created by Sacha BECOURT on 4/16/18. 6 | // Copyright © 2018 SB. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol SBMessageInputViewDelegate: AnyObject { 12 | 13 | // TextViewDelegate methods 14 | func inputView(textView: UITextView, shouldChangeTextInRange: NSRange, replacementText: String) -> Bool 15 | func inputViewDidChange(textView: UITextView) 16 | func inputViewDidBeginEditing(textView: UITextView) 17 | func inputViewShouldBeginEditing(textView: UITextView) -> Bool 18 | 19 | // Button tap callback methods 20 | func inputViewDidTapButton(button: UIButton) 21 | } 22 | 23 | @IBDesignable 24 | class SBMessageInputView: UIView { 25 | 26 | @IBInspectable var placeholder: String = "" 27 | @IBInspectable var placeholderColor: UIColor = .lightGray 28 | @IBInspectable var textColor: UIColor = .black 29 | 30 | @IBInspectable var buttonImage: UIImage = SBMessageInputView.getDefaultImage() { 31 | didSet { 32 | guard let b = button else { return } 33 | b.setImage(buttonImage, for: .normal) 34 | } 35 | } 36 | 37 | @IBInspectable var viewBorderColor: UIColor = .gray { 38 | didSet { 39 | guard let mv = mainView else { return } 40 | mv.layer.borderColor = viewBorderColor.cgColor 41 | } 42 | } 43 | 44 | @IBInspectable var viewBorderWidth: CGFloat = 0.5 { 45 | didSet { 46 | guard let mv = mainView else { return } 47 | mv.layer.borderWidth = viewBorderWidth 48 | } 49 | } 50 | 51 | @IBInspectable var maxLines: CGFloat = 5.0 52 | 53 | @IBInspectable var textViewTopInset: CGFloat = 0.0 { 54 | didSet { 55 | guard let tv = textView else { return } 56 | tv.contentInset = UIEdgeInsets(top: textViewTopInset, left: tv.contentInset.left, bottom: tv.contentInset.bottom, right: tv.contentInset.right) 57 | } 58 | } 59 | 60 | @IBInspectable var textViewLeftInset: CGFloat = 8.0 { 61 | didSet { 62 | guard let tv = textView else { return } 63 | tv.contentInset = UIEdgeInsets(top: tv.contentInset.top, left: textViewLeftInset, bottom: tv.contentInset.bottom, right: tv.contentInset.right) 64 | } 65 | } 66 | 67 | var numberOfLines: CGFloat = 1.0 { 68 | didSet { 69 | if numberOfLines > oldValue && numberOfLines <= maxLines { 70 | increaseSize() 71 | } else if numberOfLines < oldValue && numberOfLines <= maxLines { 72 | reduceSize() 73 | } else { 74 | // do nothing 75 | } 76 | } 77 | } 78 | 79 | // Views 80 | var mainView: UIView? 81 | var textView: UITextView? 82 | var button: UIButton? 83 | var heightConstraint: NSLayoutConstraint? 84 | 85 | // Heights 86 | var originalViewHeight: CGFloat = 0.0 87 | var containerViewHeight: CGFloat { 88 | let top: CGFloat = 4.0 89 | let bottom: CGFloat = 4.0 90 | return originalViewHeight - (top + bottom) 91 | } 92 | var buttonViewHeight: CGFloat = 26.0 93 | var lineHeight: CGFloat = 0.0 94 | 95 | // Delegate 96 | var delegate: SBMessageInputViewDelegate? 97 | 98 | override init(frame: CGRect) { 99 | super.init(frame: frame) 100 | setupView() 101 | } 102 | 103 | required init?(coder aDecoder: NSCoder) { 104 | super.init(coder: aDecoder) 105 | setupView() 106 | } 107 | 108 | class func getDefaultImage()-> UIImage { 109 | if let defaultImage = UIImage(named: "send") { 110 | return defaultImage 111 | } else { 112 | return UIImage() 113 | } 114 | } 115 | 116 | override func layoutSubviews() { 117 | super.layoutSubviews() 118 | 119 | if originalViewHeight == 0 { originalViewHeight = frame.height } 120 | if let mv = mainView { mv.layer.cornerRadius = containerViewHeight / 2.0 } 121 | setTextView() 122 | if let tv = textView { tv.setContentOffset(CGPoint(x: -textViewLeftInset - 20, y: -textViewTopInset), animated: false) } 123 | } 124 | 125 | fileprivate func setupView() { 126 | setContainerView() 127 | } 128 | 129 | func increaseSize() { 130 | 131 | let newConstant = containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 132 | if let c = heightConstraint { 133 | c.constant = newConstant 134 | } else { 135 | for constraint in constraints { 136 | if constraint.firstAttribute == .height { 137 | constraint.constant = newConstant 138 | break 139 | } 140 | } 141 | } 142 | } 143 | 144 | func reduceSize() { 145 | 146 | let newConstant = numberOfLines == 1 ? containerViewHeight + 8.0 : containerViewHeight + ((numberOfLines - 1) * lineHeight) + 8.0 147 | if let c = heightConstraint { 148 | c.constant = newConstant 149 | } else { 150 | for constraint in constraints { 151 | if constraint.firstAttribute == .height { 152 | constraint.constant = newConstant 153 | break 154 | } 155 | } 156 | } 157 | } 158 | 159 | fileprivate func setContainerView() { 160 | if mainView == nil { 161 | mainView = UIView(frame: .zero) 162 | guard let mainView = self.mainView else { return } 163 | addSubview(mainView) 164 | 165 | mainView.translatesAutoresizingMaskIntoConstraints = false 166 | let leadingConstraint = NSLayoutConstraint(item: mainView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1, constant: 16) 167 | let trailingConstraint = NSLayoutConstraint(item: self, attribute: .trailing, relatedBy: .equal, toItem: mainView, attribute: .trailing, multiplier: 1, constant: 16) 168 | let topConstraint = NSLayoutConstraint(item: mainView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1, constant: 4) 169 | let bottomConstraint = NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: mainView, attribute: .bottom, multiplier: 1, constant: 4) 170 | 171 | addConstraints([topConstraint, bottomConstraint, leadingConstraint, trailingConstraint]) 172 | } 173 | } 174 | 175 | fileprivate func setTextView() { 176 | if textView == nil { 177 | textView = UITextView(frame: .zero) 178 | button = UIButton(type: .custom) 179 | 180 | guard let button = self.button, let textView = self.textView, let mainView = self.mainView else { return } 181 | textView.delegate = self 182 | 183 | if !placeholder.isEmpty { 184 | textView.text = placeholder 185 | textView.textColor = placeholderColor 186 | } 187 | 188 | button.setImage(buttonImage, for: .normal) 189 | button.addTarget(self, action: #selector(didTapButton(sender:)), for: .touchUpInside) 190 | 191 | textView.clipsToBounds = true 192 | textView.layer.cornerRadius = containerViewHeight / 2.0 193 | textView.contentInset = UIEdgeInsets(top: textViewTopInset, left: 0.0, bottom: 0.0, right: 0.0) 194 | textView.font = UIFont.systemFont(ofSize: 18.0) 195 | 196 | mainView.addSubview(textView) 197 | mainView.addSubview(button) 198 | 199 | textView.translatesAutoresizingMaskIntoConstraints = false 200 | textView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor, constant: textViewLeftInset).isActive = true 201 | textView.topAnchor.constraint(equalTo: mainView.topAnchor, constant: 0.0).isActive = true 202 | textView.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: 0.0).isActive = true 203 | 204 | button.translatesAutoresizingMaskIntoConstraints = false 205 | button.heightAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 206 | button.widthAnchor.constraint(equalToConstant: buttonViewHeight).isActive = true 207 | button.leadingAnchor.constraint(equalTo: textView.trailingAnchor, constant: 5.0).isActive = true 208 | button.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: -5.0).isActive = true 209 | button.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: -5.5).isActive = true 210 | } 211 | } 212 | 213 | @objc fileprivate func didTapButton(sender: UIButton) { 214 | if let delegate = delegate { 215 | delegate.inputViewDidTapButton(button: sender) 216 | } 217 | } 218 | } 219 | 220 | extension SBMessageInputView: UITextViewDelegate { 221 | 222 | func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { 223 | if let delegate = delegate { 224 | return delegate.inputViewShouldBeginEditing(textView: textView) 225 | } 226 | return true 227 | } 228 | 229 | func textViewDidBeginEditing(_ textView: UITextView) { 230 | 231 | if (textView.text == placeholder && textView.textColor == placeholderColor) { 232 | textView.text = "" 233 | textView.textColor = textColor 234 | } 235 | 236 | if let delegate = delegate { 237 | delegate.inputViewDidBeginEditing(textView: textView) 238 | } 239 | } 240 | 241 | func textViewDidEndEditing(_ textView: UITextView) { 242 | if (textView.text.isEmpty) { 243 | textView.text = placeholder 244 | textView.textColor = placeholderColor 245 | } 246 | } 247 | 248 | func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { 249 | 250 | if let delegate = delegate { 251 | return delegate.inputView(textView: textView, shouldChangeTextInRange: range, replacementText: text) 252 | } 253 | return true 254 | } 255 | 256 | func textViewDidChange(_ textView: UITextView) { 257 | guard let font = textView.font else { return } 258 | let fontLineHeight = font.lineHeight 259 | 260 | let lines = round((textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / fontLineHeight) 261 | lineHeight = fontLineHeight 262 | numberOfLines = lines 263 | 264 | if let delegate = delegate { 265 | delegate.inputViewDidChange(textView: textView) 266 | } 267 | } 268 | } 269 | --------------------------------------------------------------------------------