Coder Social home page Coder Social logo

samtextview's Introduction

SAMTextView

Add a placeholder to UITextView.

SAMTextView is tested on iOS 6 and requires ARC. Released under the MIT license.

Usage

// Initialize a text view
SAMTextView *textView = [[SAMTextView alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 280.0f)];

// Add a placeholder
textView.placeholder = @"Type something…";

For more advanced control of the placeholder, you can set the attributedPlaceholder property instead. See the header for full documentation.

Installation

Simply add the files in the SAMTextView.h and SAMTextView.m to your project or add SAMTextView to your Podfile if you're using CocoaPods.

samtextview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

samtextview's Issues

placeholder stretch on iOS7

Hi. I noticed that on iOS7 (I know the README states that the class is tested under iOS6 but I guess you'd like to know) a textview like this:
schermata 2013-10-31 alle 14 48 49
after device rotation becomes this:
schermata 2013-10-31 alle 14 48 39
Regards
MB

crash in iOS 8

_textView = [[SAMTextView alloc] init];
_textView.translatesAutoresizingMaskIntoConstraints = NO;
_textView.backgroundColor = [UIColor lightTextColor];
_textView.editable = YES;
_textView.placeholder = @"What happened?";

Crash on numberOfLines?

I'm getting this error when running my app. I have searched through my project and can't find any instance of where I use numberOfLines. Has anyone else experienced this problem?

-[SAMTextView numberOfLines]: unrecognized selector sent to instance

Setting placeholder text before setting a font causes the placeholder to be small

A small quirk I found is if you set the placeholder text before setting the font then the placeholder's font no longer matches the text view's font. Not sure if this is an intended feature. The code snippet below shows an example:

SAMTextView *textView = [SAMTextView new];
textView.translatesAutoresizingMaskIntoConstraints = NO;
textView.backgroundColor = [UIColor yellowColor];
textView.placeholder = @"This is the placeholder";
textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2];

Maybe when setting a font, it could regenerate the attributed string?

Value of type 'SAMTextView' has no member 'addTarget'

Im trying to set the target "textViewDidChange" but

Value of type 'SAMTextView' has no member 'addTarget'

My code
self.tvComment.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)

How can i do this?

Xcode6 and iOS8 crash due UIViewControllerHierarchyInconsistency

Using SAMTextView component via storyboard, Xcode5 was ok. When compiled with Xcode6 and run under iOS8, app crashes:

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:UICompatibilityInputViewController: 0x18b58560 should have parent view controller:MyViewController: 0x178d5620 but requested parent is:UIInputWindowController: 0x169fc600'

Haven't found a fix yet, stack overflow seemed to suggest removing component from superview and/or not using storyboard at all. Still researching, but hoping "you" (anyone) could suggest a fix right away.

Allow for nil placeholder text

I have an app with a textview that can go into a "Read Only" mode. When in "Read Only" mode the placeholder gets set to nil, even if the field value is empty or nil.

notesTextView.placeholder = (notesTextView.editable) ?
    @"Enter additional notes..." : nil;

This used to work in SSTextView, however in SAMTextView it crashes:

[89217:450317] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteAttributedString initWithString:: nil value'
.
.
4   Foundation                          0x0000000103a1eafd -[NSConcreteAttributedString initWithString:attributes:] + 27
5   App                      0x000000010290a664 -[SAMTextView setPlaceholder:] + 1060

Animating constraint changes causes the overlay to stretch/shrink until animation completes

I'm currently using SAMTextView in a full-screen modal. Whenever the keyboard appears or disappears, I animate the updated constraint. While the animation is taking the place, the placeholder text shrinks while the resize is taking place but then is redrawn after the animation is complete. I've attached a snippet of code which causes the issue.

- (void)keyboardWillShow:(NSNotification *)note {
	NSDictionary *userInfo = [note userInfo];
	CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
	// Check if the constraint is the same as what it is about to be set to, and abort if it is.
	if (self.descriptionBottomConstraint.constant == -(keyboardFrame.size.height)) {
		return;
	}
	double animationDuration = [((NSNumber *)userInfo[UIKeyboardAnimationDurationUserInfoKey]) doubleValue];
	[self.view layoutIfNeeded];
	self.descriptionBottomConstraint.constant = -(keyboardFrame.size.height);
	[UIView animateWithDuration:animationDuration animations:^{
		[self.view layoutIfNeeded];
	}];
}

Placeholder Color is Black When Used in Storyboard

Since Version 0.2.0 and the introduction of attributedPlaceholder, when the default SAMTextView is placed into a storyboard and something like

textView.placeholder = @"Example";

is done in code, the color of the placeholder text, which used to be light gray by default, is ignored. Whatever color the actual text is set to be in the storyboard is the color set for the placeholder text as well.

I'm doubting this is intentional behavior, but I just wanted to run it by you and make sure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.