A UITextView subclass that adds support for multiline placeholder written in Swift.

Overview

KMPlaceholderTextView

A UITextView subclass that adds support for multiline placeholder written in Swift.

PlaceholderTextView

Usage

You can set the value of the placeholder property just like using UITextField.

Interface Builder

Storyboard

  1. Drag a UITextView object onto the canvas.
  2. In the Identity inspector, set the Custom Class name to KMPlaceholderTextView.
  3. In the Attributes inspector, you can change the value of the placeholder property directly.

Code

let placeholderTextView = KMPlaceholderTextView(frame: view.bounds)
placeholderTextView.placeholder = "What's on your mind?"
view.addSubview(placeholderTextView)

Installation

CocoaPods

You can install the latest release version of CocoaPods with the following command:

$ gem install cocoapods

Simply add the following line to your Podfile:

platform :ios, '8.0' 
use_frameworks!

target '<Your Target Name>' do
  pod 'KMPlaceholderTextView', '~> 1.4.0'
end

Then, run the following command:

$ pod install

If you are encountering the following warning when using Xcode 8, please make sure to set the Module in the identity inspector of your KMPlaceholderTextView in the interface builder to KMPlaceholderTextView as well:

warning: IB Designables: Using class UITextView for object with custom class because the class KMPlaceholderTextView does not exist

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate KMPlaceholderTextView into your Xcode project using Carthage, specify it in your Cartfile:

github "MoZhouqi/KMPlaceholderTextView" >= 1.4

Requirements

  • iOS 7.0+
  • Xcode 10

License

KMPlaceholderTextView is released under the MIT license. See LICENSE for details.

Comments
  • Fixes AutoLayout

    Fixes AutoLayout

    If the priority of the width constraint isn't reduced it is automatically broken. Running this without the priority lowered generates a string of warnings in the console log, meaning that this is being over constrained.

    opened by k3zi 10
  • Layout fix: labels doesn't need constraints on booth sides.

    Layout fix: labels doesn't need constraints on booth sides.

    Labels requires only one horizontal and one vertical constraint. Try replace textview's bottom constraint with height constraint, and IB will generate warning. Removing tail and bottom constraints will fix that.

    opened by RealBonus 4
  • Rendering Performance

    Rendering Performance

    Hi The KMPlaceholderTextView won't give access to the UILabel used, so it's really difficult to setup the backgroundColor. Why do we care about it if it's transparent?. One of the slowest operations is rendering. In my case I'm using a lot of instances of KMPlaceholderTextView so if you use “Color Blended Layers" in the iPhone Simulator, you will see a lot of red areas.

    It would be really useful to have access to the background color of the UILabel - through a method- or the UILabel. Right now it's marked as private.

    opened by nicarq 3
  • Feature request: Separate fonts of placeholder and text?

    Feature request: Separate fonts of placeholder and text?

    Other than color, it's very common to have a bolded or italic font for the placeholder, which is different from the regular text the user input. Can you add an option to set the placeholder font? thanks!

    opened by karadis 3
  • IB Designables Failure

    IB Designables Failure

    Hello!

    I'm getting this issue with the latest version...

    file:///Users/sulkuatam/src/app/app-ios/Base.lproj/Main.storyboard: error: IB Designables: Failed to update auto layout status: The bundle “$(PRODUCT_NAME)” couldn’t be loaded because its executable couldn’t be located.

    Not sure what the issue is... thanks in advance for any help!

    screen shot 2016-05-31 at 11 36 52 am
    opened by sinanku 3
  • IB Designables error

    IB Designables error

    error: IB Designables: Failed to render instance of KMPlaceholderTextView: Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.

    how can i figure that error?

    opened by misuqian 3
  • Compiling has a error.

    Compiling has a error.

    I use the text view in storyboard named "Mine".And I have the other storyboard. It is normal if I didn't click the Mine storyboard. It will show a Error when I clicked Mine storyboard. It is bad. Error info: Failed to render and update auto layout status for SuggestionViewController (EBX-d9-iDK): dlopen(KMPlaceholderTextView.framework, 1): no suitable image found. Did find: KMPlaceholderTextView.framework: required code signature missing for 'KMPlaceholderTextView.framework'

    opened by XiaoJianXiaoXu 2
  • Can't see placeholder after set in Storyboard

    Can't see placeholder after set in Storyboard

    Hi,

    I have add UITextView and set to KMPlaceholderTextView and set the placeholder property but whenever I run the app placeholder value can't see and getting the below warning.

    Can you please help me asap?

    Unknown class KMPlaceholderTextView in Interface Builder file. Failed to set (placeholder) user defined inspected property on (UITextView): [<UITextView 0x799c5000> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key placeholder. ] Failed to set (placeholder) user defined inspected property on (UITextView): [<UITextView 0x79a17800> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key placeholder.

    opened by Nik20112 2
  • Has ambiguous scrollable content height

    Has ambiguous scrollable content height

    Thank you for useful pod!

    We have an issue using it in a storyboard. When adding a height constraint to the it Storyboard shows the warning: Has ambiguous scrollable content height.

    Is there a workaround for that? Or way to fix it?

    After investigation and StackOverflow research we think it's because IBDesignable KMPlaceholderTextView has placeholder subview, which UITextView UIScrollView probably takes as content and cause ambiguity.

    opened by paulz 2
  • No such module KMPlaceholderTextView

    No such module KMPlaceholderTextView

    We use your library as pod, but pulling from master branch, since pod spec was last updated 2 years ago. Recently we started getting this error. It seems that it is a result of moving source files to Sources folder. Podspec file was not change to accommodate this change.

    opened by OneSman7 1
  • clang: error: no such file or directory: 'KMPlaceholderTextView'

    clang: error: no such file or directory: 'KMPlaceholderTextView'

    I tried to deintegrate Pod and install it again also clean derived data and clean project but no way get the same error in Xcode 10.3

    clang: error: no such file or directory: 'KMPlaceholderTextView' Command Ld failed with a nonzero exit code

    opened by MoElnaggar14 1
  • Update label constraints when textContainer.lineFragmentPadding changes

    Update label constraints when textContainer.lineFragmentPadding changes

    I noticed that the constraints were only updated after updating the textContainer, not after updating textContainer.lineFragmentPadding and decided to make a fix for it.

    opened by markterluun 0
  • YOUTUBE VIDEO TUTORIAL

    YOUTUBE VIDEO TUTORIAL

    Hi, I like KMPlaceholderTextView so much that (besides using it in my own projects) I have created a video tutorial on how to use it:

    https://youtu.be/b-ODoxT7qMo

    If you like it feel free to add it to the README of your repo. You can also add this image so visitors may click on it easily: placeholder in uitextview in swift 2019 thubmnail

    opened by rebeloper 0
Owner
Zhouqi Mo
Zhouqi Mo
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.

KDInteractiveNavigationController Features ✨ UINavigationController interactive with UINavigationBar hidden or show Hide all UINavigationController ba

Kingiol 154 Dec 3, 2022
Placeholder views based on content, loading, error or empty states

StatefulViewController A protocol to enable UIViewControllers or UIViews to present placeholder views based on content, loading, error or empty states

Alexander Schuch 2.1k Dec 8, 2022
UIView and CGRect extension that adds properties to manipulate them efficiently

Geometry Geometry is a UIView and CGRect extension that lets you work with view and rect geometry easier. It adds the following properties to UIView:

Tuomas Artman 92 Sep 7, 2022
A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag

HidesNavigationBarWhenPushed A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed

Danil Gontovnik 55 Oct 19, 2022
SwiftUI-Margin adds a margin() viewModifier to a SwiftUI view.

SwiftUI-Margin adds a margin() viewModifier to a SwiftUI view. You will be able to layout the margins in a CSS/Flutter-like.

Masaaki Kakimoto(柿本匡章) 2 Jul 14, 2022
UIViewController subclass to beautifully present news articles and blog posts.

LMArticleViewController This framework allows you to create Apple News-inspired UIViewControllers with ease. It is heavily inspired by MRArticleViewCo

Luca Mozzarelli 7 Feb 3, 2022
A UIControl subclass that makes it easy to create empty states.

AZEmptyState Making empty state simple. Screenshots Installation Cocoa Pods: pod 'AZEmptyState' Manual: Simply drag and drop the Sources folder to you

Antonio Zaitoun 88 Oct 2, 2022
IHTypeWriterLabel - A simple, UILabel subclass which poulates itself as if being typed

IHTypeWriterLabel A simple, UILabel subclass which poulates itself as if being typed. HighLights Written purely in SWIFT. Very simple and lightweight.

Md Ibrahim Hassan 24 May 7, 2019
🔍 Awesome fully customize search view like Pinterest written in Swift 5.0 + Realm support!

YNSearch + Realm Support Updates See CHANGELOG for details Intoduction ?? Awesome search view, written in Swift 5.0, appears search view like Pinteres

Kyle Yi 1.2k Dec 17, 2022
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 1, 2023
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.

MZFormSheetPresentationController MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding sup

Michał Zaborowski 979 Nov 17, 2022
SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!

SAHistoryNavigationViewController Support 3D Touch for iOS9!! SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationConto

Taiki Suzuki 1.6k Dec 29, 2022
SheetPresentation for SwiftUI. Multiple devices support: iOS, watchOS, tvOS, macOS, macCatalyst.

SheetPresentation for SwiftUI. Multiple devices support: iOS, watchOS, tvOS, macOS, macCatalyst.

Aben 13 Nov 17, 2021
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Evgenii Neumerzhitckii 874 Dec 13, 2022
Cool Animated music indicator view written in Swift

Cool Animated music indicator view written in Swift. ESTMusicIndicator is an implementation of NAKPlaybackIndicatorView in Swift for iOS 8. 本人著作的书籍《La

Aufree 465 Nov 28, 2022
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 467 Dec 5, 2022
Whole, half or floating point ratings control written in Swift

FloatRatingView A simple rating view for iOS written in Swift! Supports whole, half or floating point values. I couldn't find anything that easily set

Glen Yi 546 Dec 8, 2022
Material design components for iOS written in Swift

MaterialKit NOTE: This project is unmaintained. Material design components (inspired by Google Material Design) for iOS written in Swift Please feel f

Le Van Nghia 2.5k Jan 5, 2023