Giter Club home page Giter Club logo

materialtextfield's Introduction

MaterialTextField

A Material Design inspired UITextField with animated placeholder label and error message.

MaterialTextField gif

Features

Floating placeholder label
  • Animates on focus or on text input
  • Supports attributed placeholder text with custom fonts
  • Can be turned off to use the text field with the default UITextField placeholder
Underline
  • Line height expands when editing
  • Set colours for default, editing and error states
Error message
  • Animated error message appears below the text field
  • Long error messages wrap onto multiple lines
IBDesignable view
  • Adjust the appearance of the text field in Interface Builder with inspectable properties

Setup

CocoaPods

To install via CocoaPods, add to your podfile:

pod 'MaterialTextField', '~> 1.0'

Carthage

First, add this to your Cartfile:

github "stephsharp/MaterialTextField"

Then run carthage update.

The recommended way to integrate MaterialTextField.framework is as a workspace dependency:

  1. If you don't yet have a workspace, go to the File menu in Xcode and select Save as Workspace...
  2. At the bottom left of the project navigator, select the + and add Carthage/Checkouts/MaterialTextField/MaterialTextField.xcodeproj.
  3. Add MaterialTextField.framework to your app's "Link Binary with Libraries" build phase.

Acknowledgements

I found the following libraries to be useful resources:

License

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

materialtextfield's People

Contributors

bobbyrehm avatar sharplet avatar stephsharp 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

materialtextfield's Issues

Stack overflow on iOS 13.0 (Xcode 11 beta)

We've been using MaterialTextField in our app for about a year.

While testing our app for iOS 13.0 with the latest Xcode 11 beta (beta 7), we ran into an issue with MaterialTextField. The MaterialTextFields in our app have placeholderAnimatesOnFocus enabled. The issue we ran into is that when focus leaves an empty MaterialTextField with a placeholder, the app crashes with an EXC_BAD_ACCESS (code=2, address=...) error. This appears to be a stack overflow. The bottom of the stack at exception time looks like this:

#10352	0x0000000105de5bad in -[MFTextField layoutSubviews] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:325
#10353	0x000000011287366e in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#10354	0x0000000105f4d2bd in -[CALayer layoutSublayers] ()
#10355	0x0000000105f51cc3 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#10356	0x000000011285e981 in -[UIView(Hierarchy) layoutBelowIfNeeded] ()
#10357	0x0000000105de6d13 in -[MFTextField hidePlaceholderLabelAnimated:] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:467
#10358	0x0000000105de5ca3 in -[MFTextField layoutPlaceholderLabelAnimated:] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:342
#10359	0x0000000105de5bad in -[MFTextField layoutSubviews] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:325
#10360	0x000000011287366e in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#10361	0x0000000105f4d2bd in -[CALayer layoutSublayers] ()
#10362	0x0000000105f51cc3 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#10363	0x000000011285e981 in -[UIView(Hierarchy) layoutBelowIfNeeded] ()
#10364	0x0000000105de6d13 in -[MFTextField hidePlaceholderLabelAnimated:] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:467
#10365	0x0000000105de5ca3 in -[MFTextField layoutPlaceholderLabelAnimated:] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:342
#10366	0x0000000105de5bad in -[MFTextField layoutSubviews] at <snip>/Pods/MaterialTextField/MaterialTextField/MFTextField.m:325
#10367	0x000000011287366e in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#10368	0x0000000105f4d2bd in -[CALayer layoutSublayers] ()
#10369	0x0000000105f51cc3 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#10370	0x0000000105f5e3a8 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
#10371	0x0000000105ea6a20 in CA::Context::commit_transaction(CA::Transaction*, double) ()
#10372	0x0000000105edc02b in CA::Transaction::commit() ()
#10373	0x00000001123c8b61 in _afterCACommitHandler ()
#10374	0x0000000107756eb7 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#10375	0x000000010775194e in __CFRunLoopDoObservers ()
#10376	0x0000000107751fca in __CFRunLoopRun ()
#10377	0x00000001077516b6 in CFRunLoopRunSpecific ()
#10378	0x000000010b3b3bb0 in GSEventRunModal ()
#10379	0x000000011239f90f in UIApplicationMain ()

The top part, with calls to [MFTextField hidePlaceholderLabelAnimated:], [MFTextField layoutPlaceholderLabelAnimated:] and [MFTextField layoutSubviews], keep repeating to the top of the stack.

The issue does not occur if we disable animation, nor when we disable placeholderAnimatesOnFocus. It also does not occur with Xcode 10/iOS 12.

I've downloaded the source to try the demo app in the repository with Xcode 11 beta to see if it has the same issue, but it doesn't crash. I've been trying to change some settings in the demo app to match our setup more closely, but I haven't been able to reproduce it yet.

Browsing the repository history, I did notice there has been a similar issue before (commit 17e4908), but the changes to fix this were (partially?) reverted later.

Hopefully, this is enough information to investigate (and possibly fix) this issue. In the mean time, I will see if I can make a reproduction using the demo app.

Please convert to swift

Excuse men you can convert source to version swift because to want use and extension function inside code

Clearing text for the first time doesn't hide inline placeholder

Steps to reproduce:

  • Set a placeholder and some text in the storyboard
  • Focus on text field
  • Clear text using (x) button

Expected behaviour:

  • Smaller placeholder above the text field stays visible, and there is no grey placeholder in the text field.

Actual behaviour:

  • Now there are 2 placeholders: the smaller one above the text field (correct) and one in the text field is visible as well (incorrect).
  • This only seems to happen the first time the text is cleared, then it behaves as expected.

screen shot 2018-06-24 at 4 55 07 pm

clear-text-bug

failed to render and update auto layout status

"failed to render and update auto layout status".
This error message appears when I assign MFTextField class for the UITextField in IB, However, it works but can't be rendered by interface builder.

Set left view of uitextfield make placeholder overlap on icon

I've tried following code to set left view of uitextfield but got placeholder overlap over icon when editing uitextfield.
txtUsername.leftViewMode = UITextField.ViewMode.always let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) let image = UIImage(named: "icon_camera") imageView.image = image imageView.contentMode = .scaleAspectFit txtUsername.leftView = imageView

Got an error 'NSConcreteAttributedString initWithString:: nil value'

Can someone explain what i did wrong, some of my TextField working with MFTextField but another just display empty placeholder and i am realy sure i already make it to custome class MFTextField and set placeholder

screen shot 2018-04-19 at 10 01 48 am
screen shot 2018-04-19 at 10 01 33 am

and app crash after i tap on another MFTextField without fill it

screen shot 2018-04-19 at 10 21 04 am

*i am working on cell and some MFTextField are work
*sry for bad english

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteAttributedString initWithString:: nil value'
*** First throw call stack:
(
0 CoreFoundation 0x00000001117a012b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001104c0f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000111815245 +[NSException raise:format:] + 197
3 Foundation 0x000000010fedb358 -[NSConcreteAttributedString initWithString:] + 135
4 Foundation 0x000000010fee4060 -[NSConcreteAttributedString initWithString:attributes:] + 27
5 MaterialTextField 0x000000010c748c16 -[MFTextField attributedString:withColor:] + 358
6 MaterialTextField 0x000000010c746748 -[MFTextField setAttributedPlaceholder:] + 168
7 MaterialTextField 0x000000010c7482e3 -[MFTextField hidePlaceholderLabelAnimated:] + 211
8 MaterialTextField 0x000000010c7472ca -[MFTextField layoutPlaceholderLabelAnimated:] + 202
9 MaterialTextField 0x000000010c7471a4 -[MFTextField layoutSubviews] + 148
10 UIKit 0x000000010dd21a6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439
11 QuartzCore 0x000000010c9db61c -[CALayer layoutSublayers] + 159
12 QuartzCore 0x000000010c9df7ad _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
13 QuartzCore 0x000000010c96686c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 364
14 QuartzCore 0x000000010c993946 _ZN2CA11Transaction6commitEv + 500
15 QuartzCore 0x000000010c994694 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
16 CoreFoundation 0x0000000111742c07 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
17 CoreFoundation 0x0000000111742b5e __CFRunLoopDoObservers + 430
18 CoreFoundation 0x0000000111727124 __CFRunLoopRun + 1572
19 CoreFoundation 0x0000000111726889 CFRunLoopRunSpecific + 409
20 GraphicsServices 0x0000000114d3e9c6 GSEventRunModal + 62
21 UIKit 0x000000010dc505d6 UIApplicationMain + 159
22 GDC Mobile v2 0x0000000109088007 main + 55
23 libdyld.dylib 0x0000000112fa0d81 start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

App crash on intrinsicContentSize

When user has empty textfield and he return the keyboard means resign the textfield then it will crash on below line.
CGSize intrinsicSize = [super intrinsicContentSize];

If user has input something then no crash. It's only occur when empty textfield and resign the responder.

iOS 11 cropped text

Strange behaviour with textfield on iOS 11 beta . Text are cropped and placed three dots at the end of string. It is like that your autolayout is broken on newer version of iOS

Setting custom rightView on TextField causes strange scroll behaviour

Hi,

Awesome component!

Question though; I want to set a custom rightView on one of my TextFields, but when I do so the rightView also scrolls down when the custom errorMessage, displayed below the line, is animated.
Note: I use the component in a swift project using a bridging header.

My code to set the custom rightView:
let eyeButton = UIButton(type: .custom)
eyeButton.setImage(UIImage(named: "icon_eye"), for: .normal)
eyeButton.imageEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0)
eyeButton.frame = CGRect(x: CGFloat(passwordTextField.frame.size.width - 16), y:(passwordTextField.frame.size.height - 16) / 2, width: CGFloat(16), height: CGFloat(16))
eyeButton.addTarget(self, action: #selector(self.togglePassword), for: .touchUpInside)
passwordTextField.rightViewMode = UITextFieldViewMode.always
passwordTextField.rightView = eyeButton

The setup of the MFTextField itself it pretty straightforward, using properties like underlineColor, placeholderFont etc.
Can someone verify this behaviour?

Cheers, Raoul.

Getter for attributedString == crash

If you try to get attributedString that exist but empty you will catch app crash

- (NSAttributedString *)attributedString:(NSAttributedString *)attributedString withColor:(UIColor *)color
{
    NSMutableDictionary *attributes = [[attributedString attributesAtIndex:0 effectiveRange:NULL] mutableCopy];
    attributes[NSForegroundColorAttributeName] = color;

    return [[NSAttributedString alloc] initWithString:attributedString.string attributes:attributes];
}

The problem is in this line of code

NSMutableDictionary *attributes = [[attributedString attributesAtIndex:0 effectiveRange:NULL] mutableCopy];

Content will be overwriten if 'Secured Text Entry' is enabled

For password field (Secured Text Entry = on), everytime when user input new content, existing content on that textfield will be erased.

Using the demo application as provided in the repo:
Steps to reproduce:

  1. select the password field
  2. type something on password field
  3. Make the password textfield 'lose focus' (e.g. select other fields)
  4. select the password field again
  5. type anything

You will see the content typed in step 2 is all gone.

Error message not showing up.

Hi,

I'm using your library on the app I'm currently developing. I really liked it, but I've found that the error message is not getting displayed after setting the NSError to the MFTextField object.

As you can see in the GIF, the line and placeholder color is getting updated, but the message label is not showing up. I'm handling the text changes with delegation (UITextFieldDelegate).

By the way, my app is being written in Swift 4.2, but I'm making sure to pass NSObjects to the MFTextField.

Best regards, and I'll hope for your answer.

animated

MaterialTextFIeld using previous modal's MFTextField font styling

I've run into a bug (or memory management issue?) where an MFTextField is referencing a previously initialised MFTextField's font and text alignment.

The app presents a VC modally, once a verification code is confirmed this is dismissed and a VC is then pushed. This latter VC also contains an MFTextField which should have the font Avenir Next Regular sized 16pt left aligned yet matches the previous field's styling of Avenir Next Regular sized 24pt centre aligned.

Here's the modally presented VC:
screen shot 2016-12-28 at 09 25 12

Here's the next pushed VC after the modal VC is dismissed:
screen shot 2016-12-28 at 09 23 24

And here's how it should look (and does look if the VC is pushed without the modal step)
screen shot 2016-12-28 at 08 54 03

What I've tried:

  • Setting the font/alignment of the MFTextField in the modal VC's nib to size 16pt left aligned which stops the issue (thus confirming it's referencing this field). This of course doesn't fix the issue as I want that MFTextField in 24pt font centred
  • Manually setting the font of the MFTextField in viewDidLoad/appear
  • Checking there's no duplicated or cross referenced IBOutlets between the two nibs
  • Ensuring first responders are resigned correctly
  • Setting outlets to nil

Any ideas?

textRectForBounds is wrong with left/rightView

Hi,

textRectForBounds is sometimes wrong when using left/rightView:

  • when viewMode is .never or .whileEditing everything is working as expected
  • when viewMode is .always or .whileEditing, frame is smaller than expected.

It seems coming from the fact that in 1st case UIKit UITextField.textRectForBounds is returning the full frame while in second it returns frame minus left/right frames.

Can't see error text when field in table view cell

First off, thanks for writing and publishing this!

When I add error text to a field, the underline turns red, but I cannot see the error text. If I use Reveal to look at the views, the text is there, but hidden.
The field is attached to all 4 sides of the content view of the cell, and the cell should grow based on autolayout (height methods return UITableViewAutomaticDimension).
Any thoughts on how to get this to work? I also tried changing the error padding, but no help.
Thanks

Show error label in designable view

Currently prepareForInterfaceBuilder hides the error label because I was unable to get it to show up correctly in the storyboard.

Steps to fix:

  1. Currently the error property is of type NSError, but the localized description is the only thing that's used in MFTextField so it could be changed to a string instead.

  2. Making the error an NSString instead of an NSError would allow the property to be made inspectable. The error string could then be set in the storyboard.

  3. prepareForInterfaceBuilder could be updated to not remove the error label anymore and call sharedInit instead.

Considerations:
This would be a breaking change to the API.

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.