Git Product home page Git Product logo

jvfloatlabeledtextfield's Introduction

JVFloatLabeledTextField

Build Status Carthage compatible Pod Version Pod Platform Pod License CocoaPods

JVFloatLabeledTextField is the first implementation of a UX pattern that has come to be known the "Float Label Pattern".

Due to space constraints on mobile devices, it is common to rely solely on placeholders as a means to label fields. This presents a UX problem, in that, once the user begins to fill out a form, no labels are present.

This UI component library, which includes both a UITextField and UITextView subclass, aims to improve the user experience by having placeholders transition into floating labels that hover above the fields after they are populated with text.

Credits for the concept to Matt D. Smith (@mds), and his original design:

Matt D. Smith's Design

The component is officially supported for iOS 9 and greater.

Getting started via CocoaPods

sudo gem install cocoapods

Create a Podfile in your project directory:

pod init

Add the following to your Podfile project's target:

pod 'JVFloatLabeledTextField'

Then run CocoaPods with pod install.

Finally, include JVFloatLabeledTextField.h and JVFloatLabeledTextView.h in your project.

Getting started via Carthage

brew update
brew install carthage

Create a Cartfile in your project directory that contains:

github "jverdi/JVFloatLabeledTextField"

Then run carthage with carthage update and add JVFloatLabeledText.framework to your project from the Carthage/Build/iOS directory.

Finally, include JVFloatLabeledText.h in your project:

#import <JVFloatLabeledText/JVFloatLabeledText.h>

Getting started via SPM (Xcode 11+)

Click File -> Swift Packages -> Add Package Dependency, enter JVFloatLabeledText repo's URL.

After select the package, you can choose the dependency type (tagged version, branch or commit). Then Xcode will setup all the stuff for you.

If you're a framework author and use JVFloatLabeledTextField as a dependency, update your Package.swift file:

let package = Package(
    dependencies: [
        .package(url: "https://github.com/jverdi/JVFloatLabeledTextField", from: "1.2.2")
    ],
)

Additional References

How the Float Label Pattern Started - Matt D. Smith
Float Label Pattern - Brad Frost
Material Design - Floating Labels - Google

Ports and Alternate Implementations

Android - Henrik Sandström
Android - Kaushik Gopal
Android - Kevin Johnson
Xamarin.iOS - Greg Shackles
Xamarin.Android - Johan du Toit
CSS Jonathan Snook
JQuery / Zepto.js - Achmad Mahardi
JQuery - Mike Mitchell
AngularJS - Dave Ackerman
Bootstrap plugin - Matt Powell
JavaFX - Andy Till
Swift - Dirk Fabisch
Swift - Fahim Farook
Swift - Neeraj Kumar
Swift - Jimmy Jose
Swift - Skyscanner (Daniel Langh, Gergely Orosz, Raimon Lapuente)
ObjC - Arthur Ariel Sabintsev
ObjC - Rob Phillips
4D - Maurice Inzirillo
Appcelerator Titanium - The Smiths
B4i - Erel Uziel

Added a port? Let me know - @jverdi

jvfloatlabeledtextfield's People

Contributors

artsabintsev avatar asolovev avatar b-raines avatar beribas avatar chanil1218 avatar ct4h avatar datwelk avatar delebedev avatar dimavartanian avatar fogh avatar gergelyorosz avatar gonzula avatar gshackles avatar jgrana avatar jverdi avatar laihj avatar ldrr avatar mattcarr147 avatar mjcuva avatar mkernahan avatar ndrewh avatar palringoben avatar pronebird avatar rcdilorenzo avatar reallyseth avatar rvijay007 avatar ryuheechul avatar sportlabsmike avatar stefanomondino avatar tailec avatar

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  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

jvfloatlabeledtextfield's Issues

IB_DESIGNABLE?!

Hi
sample could not be compiled.
Error in IB_DESIGNABLE in JVFloatLabeledTextField.h ( unknown type name).

FloatLabel position collides with text

I have this code:

let txtField = JVFloatLabeledTextField(frame: CGRect(x: 20, y: 50, width: 200, height: 30))
        txtField.placeholder = "Just a simple test"
        txtField.floatingLabelTextColor = UIColor.lightGrayColor()
        txtField.floatingLabelActiveTextColor = UIColor.redColor()
        self.view.addSubview(txtField)

        let txtField2 = JVFloatLabeledTextField(frame: CGRect(x: 20, y: 100, width: 200, height: 30))
        txtField2.placeholder = "Just a simple test 2"
        txtField2.floatingLabelTextColor = UIColor.lightGrayColor()
        txtField2.floatingLabelActiveTextColor = UIColor.redColor()
        self.view.addSubview(txtField2)

And this is the result:
Result

JVFloatLabeledTextView placeholder label doesn't hide correctly

I think there's a bug in how the class shows / hides the placeholder label. I noticed that the label was showing up on initial load even if the text view's text was not empty.

The code in question was this:

- (void)setText:(NSString *)text
{
    [super setText:text];

    self.placeholderLabel.alpha = [self.placeholderLabel.text length] > 0 ? 1.0f : 0.0f;
}

It seems to be checking if the placeholder label's text is > 0 or not, when it should be checking the text view's text length? I changed it to something long the lines of this example and now it appears to function properly:

- (void)setText:(NSString *)text
{
    [super setText:text];

    self.placeholderLabel.alpha = [self.text length] == 0 ? 1.0f : 0.0f;
}

Crashing on iOS 6.x and below

I am getting crashes on any iOS version older than 7.x. It looks like the crashes are caused by setTintColor since the function was not part of UITextField until iOS 7. The offending code block is:

- (void)setLabelActiveColor
{
    if (self.floatingLabelActiveTextColor) {
        _floatingLabel.textColor = self.floatingLabelActiveTextColor;
    }
    else {
       _floatingLabel.textColor = self.tintColor;
    }
}

text offset after selecting a row in the menu

But there is a bug when I try to use it with swift in Xcode 6 beta3. I try to use SWRevealViewControllerSeguePushController in Storyboard. And the animation happened when i actually select a row in the menu. The result is the bar buttons in navigation bar are off. Both the right and left.
2014-07-15 10 11 52
2014-07-15 10 12 03
2014-07-15 10 12 12

floatingLabelYPadding Type Issue

The floatingLabelYPadding property is declared as an NSNumber, and it appears to only be used when setting the floatingLabel's frame.

@Property (nonatomic, strong) NSNumber * floatingLabelYPadding UI_APPEARANCE_SELECTOR;

_floatingLabel.frame = CGRectMake(_floatingLabel.frame.origin.x,
_floatingLabelYPadding,
_floatingLabel.frame.size.width,
_floatingLabel.frame.size.height);

CGRects expect CGFloat, so when I first started to experiment with the project (in both Xcode 5 and the new beta) I was receiving a "Passing 'NSNumber *__strong' to parameter of incompatible type 'CGFloat' (aka 'double')" error at compile-time.

A quick fix for this would be to declare the padding property as a CGFloat instead:

@Property (nonatomic) CGFloat floatingLabelYPadding UI_APPEARANCE_SELECTOR;

Is there a reason why it is an NSNumber, or if you'd welcome it I could submit a pull request.

Awesome design though, love the concept!

A way to set field optional/required

Would be great to visually show that a field is required or optional other than (optional) appended to the label, right? Perhaps a question for the original designer?

Support for Interface Builder

It would be awesome if we could get this to work when placing a textfield in Interface Builder.

Thanks for the consideration.

Breaking changes on release 0.0.9

Hi guys, I'm having some problems with the alignment of TextView's text and placeholder since I updated from version 0.0.8 to 0.0.9, did somebody notice it as well? TextFields still work as expected, though. I am sorry but I didn't look deeper into it yet.

Label moves down

When I am editing the label there is no problem, but when I go to another textfield the label suddenly goes down. I only have bigger font and a tableview compared to the example you have provided.

Dismissing the Keyboard for JVFloatLabeledTextView

When I use the TextField I can send resignFirstResponder to my instance, in the -(BOOL)textFieldShouldReturn:(UITextField *)textField method of the UITextFieldDelegate protocol.

When I am using the TextView, however, there is not an equivalent in the UITextViewDelegate protocol so what would be the best way to dismiss the keyboard?

The demo project doesn't allow me to dismiss the keyboard either.

JVFloatLabeledTextView's floating label doesn't work well when assigned

image
when clear textView's text by

textView.text = nil;

textView's floating label didn't hidden and placeholder didn't shown.

image

when assign textView's text by

textView.text = @"Hello World!";

textView's floating label didn't shown and placeholder didn't hidden, placeholder under the text "Hello World!"

But textField always works well, i found when clear or assign textField's text, textField will invoke method layoutSubviews, textView didn't invoke. That's reason.

I solved the problem by overriding textView's setText: method

- (void)setText:(NSString *)text
{
    [super setText:text];

    [self layoutSubviews];
}

when set textView's text invoking layoutSubviews, then textView works well.

Should work with defaults dropping into Storyboard

Right now, just dropping it into a Storyboard has it working like an ordinary UITextField, can it be modified with sensible defaults to work out of the box in Storyboards? I saw a pull request adding support for Nibs, but when I tried to subclass a UITextField in a Storyboard, nothing changed.

Invisible content issue

Hi,

If TextView pre-filled with content, it becomes invisible when using JVFloatLabeledTextView:

image

The text shows up if I dismiss keyboard:

image

The text color for text view was always black and never changed, so that's not the case.

Update:

The problem resolves itself when I manually set text view's font in viewDidLoad.

version bump to 1.0 for cocoapods?

Thanks for merging my pull request and making this component! I'm going to use this component and I'd love to be able to pull it in as a cocoapod in its current state.

iOS 9 and JVFloatLabeledTextField

Hello, I am not sure if it is related to iOS 9 but when I try out the JVFloatLabeledTextField in my project, the text jumps down a bit when I start editing the text field.

simulator - - screen shot 11 july 2015 at 15 31

safari - github com - - screen shot 11 july 2015 at 15 31

textfiled placeholder initial alignment issue fix

JVFloatLabeledTextField.m

In function - (CGRect)editingRectForBounds:(CGRect)bounds
modifying line
rect = UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(ceilf(_floatingLabel.font.lineHeight+_placeholderYPadding), 0.0f, 0.0f, 0.0f));

to

if ([self text].length) {
rect = UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(ceilf(_floatingLabel.font.lineHeight+_placeholderYPadding), 0.0f, 0.0f, 0.0f));
}

and in function

  • (CGRect)textRectForBounds:(CGRect)bounds
    modifying line
    rect = UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(ceilf(_floatingLabel.font.lineHeight+_placeholderYPadding), 0.0f, 0.0f, 0.0f));

to

if ([self text].length) {
rect = UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(ceilf(_floatingLabel.font.lineHeight+_placeholderYPadding), 0.0f, 0.0f, 0.0f));
}

Fixes the initial vertical alignment issue of placeholder

textfield doesn't horizontally scroll with the cursor.

If the text is bigger then the visible space the cursor fails to scroll to the right with the text, as the standard behavior does for a UITextField. Seems like setting the textRectForBounds, stops the UITextField from tracking the cursor.

As I typed it out..
screen shot 2014-08-11 at 1 29 52 pm

If press down and scroll to the right of the same text.
screen shot 2014-08-11 at 1 31 05 pm

Cocoapod Podspec for Project

Although opt-in installation I just love cocoapods for every 3rd party stuff I use.
Would be great to have a Podspec of this project, too.

Release 1.0.0 broken on iOS 8.1.2

It seems that release 1.0.0 messed the vertical positions of the inner textField. Version 0.0.9 was fine.

This is on an iPhone 6 running iOS 8.1.2, building from Xcode 6.2 beta 3 with iOS 7.0 deployment target.

See the following screenshots (first two screenshots are 1.0.0, last two 0.0.9):

1 0 0 - a
1 0 0 - b
0 0 9 - a
0 0 9 - b

floating label font

Hi
Floating label font in default should be set as JVFloatLabeledTextField font.
current is not

Create UITextView Equivalent

I would appreciate it if you added a UITextView equivalent for this control. I have tried using RPFloatingPlaceholderTextView but it has several displaying issues. I believe this should be simple for you to port over to a UITextView. Thanks!

Title gets stuck in middle of animation

To reproduce, run the example app, go to the text area and type a single letter. Then QUICKLY delete it and type another one. The blue label will get stuck in a weird position.

screen shot 2013-11-14 at 14 59 50

keyboard covering textfield

textFieldDidBeginEditing method is not being triggered, is there a way to resolve this? Currently having an issue where the keyboard covers the field.

Placeholder color property.

Hey @jverdi

Made a quick change in my project as I needed to change the placeholder color. Would you be interested in a pull request or I'll leave it only in the fork?

Troubles adding custom clear button

I can't get a custom clear button to work with JVFloatLabeledTextField. Here is my code:

UIButton *clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 15.0, 15.0)];
[clearButton setImage:[UIImage imageNamed:@"Clear_Button"] forState:UIControlStateNormal];
[clearButton setImage:[UIImage imageNamed:@"Clear_Button"] forState:UIControlStateHighlighted];
[clearButton addTarget:self action:@selector(doClear:) forControlEvents:UIControlEventTouchUpInside];

field.rightView = clearButton;
field.rightViewMode = UITextFieldViewModeWhileEditing;

The button only shows a couple pixels. So the problem is a positioning issue. Any idea's?

Todd

textfield doesn't horizontally scroll with the cursor

screenshot 2014-11-10 17 34 36
I have same issue as #67. Is there any workaround for this?

If the text is bigger then the visible space the cursor fails to scroll to the right with the text, as the standard behavior does for a UITextField. Seems like setting the textRectForBounds, stops the UITextField from tracking the cursor.

I have same issue. Is there any workaround for this? I am using constraint.

let contentView = UIView()
        contentView.setTranslatesAutoresizingMaskIntoConstraints(false)
let emailInput = JVFloatLabeledTextField()
        emailInput.floatingLabel.font = PlaceHolderFontSmall
        emailInput.floatingLabelTextColor = PlaceholderSmallColor
        emailInput.setTranslatesAutoresizingMaskIntoConstraints(false)

let views = ["contentView": contentView, "emailInput": emailInput]
        let constrainV = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(16)-[emailInput(36)]-(16)-|",
            options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
        contentView.addConstraints(constrainV)

        let constrainH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[emailInput(260)]-10-|",
            options: nil, metrics: nil, views: views)
        contentView.addConstraints(constrainH)

Read label with textfield instead of just textfield for VoiceOver Accessibility

Right now when a VoiceOver user taps on the field it will initially read the label which is good. However once the user fills out the textfield and then taps on the field again VoiceOver only reads the textfield and not the label. I believe this is a bug since Apple's own textfields inside of a tableview cell read the label then the textfield.

TextView placeholder Y offset in Auto Layout

Hi jverdi, your repo is great and I have used it one of my app. Thank you for putting out such a great resources!
I have a problem here: So everything works fine when I am using frame to define the TextField or TextView. But when I am using Auto Layout. There's Y offset on the Placeholder UILabel. Here's a screen shot: http://cl.ly/image/4630050C1y3b
You can see that the one on the top is a TextField, which works fine but the one on the bottom is the TextView, where the placeholder "Detail" has a offset. You didn't make the placeholder UILabel public so I can't modify that. Is there any way to solve this problem?

Thank you in advance

Setting label centered text loses alignment

When I set the text of my label within the viewDidAppear it works fine:

But when I set it within the viewDidLoad the alignment is left from the center as you can see in the image:

No support for right to left languages.

The current implementation doesn't support natural alignment. We have a large Arabic user base and need to accommodate this. Is there any plans to add this feature?

Cursor moves downwards when placeholderYPadding is set to a positive value

I want to center my text vertically whilst using JVFloatLabeledTextView. To this end, I used the method here http://stackoverflow.com/a/17024644/590767 to offset the UITextView appropriately.

I noticed the placeholder stayed towards the top of the text view so I set placeholderYPadding = 40.

The placeholder moved. However, this also had the side-effect of offsetting the cursor and of the baseline of the text being typed as well.

You can see the cursor position faintly in the screenie below:

screen shot 2015-03-26 at 12 34 20

I expected placeholderYPadding to have zero effect on the way text is edited on the text view.

Cocoa Pods using 1.0.2

Despite the fact the latest version shows 1.1.0 next to pods, when I run pod update/install it uses version 1.0.2.

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.