Code Monkey home page Code Monkey logo

textfieldeffects's Introduction

TextFieldEffects Build Status

I fell in love with the text inputs effects in this article. As an exercise I decided to recreate as many of them as I can using Swift (some of them have a personal touch).

Currently it features the following effects from the article:

  • Kaede
  • Hoshi
  • Jiro
  • Isao
  • Minoru
  • Yoko
  • Madoka
  • Akira
  • Yoshiko

How they look

Kaede

Hoshi

Jiro

Isao

Minoru

Yoko

Madoka

Akira

Yoshiko

Installation

  • Looking for Swift 2.3 support? Check out the 1.2.0 tag.
  • Looking for Swift 2.1 support? Check out the 1.1.1 tag.
  • Looking for Swift 1.2 support? Check out the swift-1.2 branch.

Manual

The easiest way to install this framework is to drag and drop the TextFieldEffects/TextFieldEffects folder into your project. This also prevents the frameworks problem in iOS where the IBInspectable and IBDesignable are stripped out.

CocoaPods

Add the following to your Podfile:

use_frameworks!
pod 'TextFieldEffects'

Carthage

Add the following to your Cartfile:

github 'raulriera/TextFieldEffects'

How to use them

Every effect is properly documented in the source code, this is the best way to both understand and see what they do. There is also an example project included with all the effects and their settings.

Interface Builder

The library is a simple drop-in, as soon as you set your subclass to one of the effects and your module to TextFieldEffects you will be able to see all the IBDesignable settings in the storyboard.

Code

If you like to get your hands dirty, you can use them just like you would normally use any UITextField

let textField = KaedeTextField(frame: textFieldFrame)
textField.placeholderColor = .darkGrayColor()
textField.foregroundColor = .lightGrayColor()

view.addSubView(textField)

Is that simple.

Created by

Raul Riera, @raulriera

textfieldeffects's People

Contributors

askari01 avatar barrettj avatar besarism avatar charlisim avatar christie-alphero avatar erenozkul avatar hugo-pivaral avatar hyerra avatar julienkode avatar kkiermasz avatar lammertw avatar liuhaoeee avatar martin-key avatar michallaskowski avatar netizen01 avatar patrickreynolds avatar raulriera avatar readmecritic avatar sairamkotha avatar vladyslavsosiuk 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

textfieldeffects's Issues

Minoru doesn't animate

This effect doesn't animate correctly, everything just "pops" without any transition at all.

Error when running on Device (iPhone 6 Plus)

It runs fine on the simulator and compiles fine on both the simulator and the device. But when I run the app on the device I get the following error:

dyld: Library not loaded: @rpath/TextFieldEffects.framework/TextFieldEffects
Referenced from: /private/var/mobile/Containers/Bundle/Application/DD8E223B-5A3C-47AE-BA55-7F030765D4E5/TextFieldsDemo.app/TextFieldsDemo
Reason: image not found
(lldb)

use programmatically

How do you use this programmatically (without storyboard)? I am unable to instantiate the KaedeTextField as there are no constructors.

placeholder image

Is there any way to add a image to the placeholder? Or at least pin a image beside it so that it follows it?

Access modifiers limit subclassing

Hi,

I'm using Cocoapods to add this project to my own, but that's causing issues when I want to make a custom subclass of TextFieldEffects since a few of the functions are declared as internal rather than public - all of the TextFieldsEffectsProtocol methods for example. I was able to bypass this by overriding the functions that were public (ex. drawRect, prepareForInterfaceBuilder) but that isn't ideal.

I was wondering if this limitation was intentional?

Thank you for the wonderful library!

Phone Number Formatting with TextFieldEffects | Not an Issue

I really like TextFieldEffects and I thought that would be awesome to be able to use it with phone number formatter as the user types in. I found PhoneNumberKit, which seemed interesting for playing with phone numbers.

However, when I tried implementing it, I realised that I need to declare it as let textField = PhoneNumberTextField() but I declare my UITextField with var textField = HoshiTextField().

I went into TextFieldEffects.swift and found UITextField there, but changing it there doesn't seem like an option. (I think I should use a delegate to observe every change on the HoshiTextField, but I got very confused)

Can you please guide me on that? Also, please let me know if there are better ways than this for doing it.

Unknown class _TtC16TextFieldEffects14HoshiTextField in Interface Builder file.

Hi, I got this error at run time.
I just drag the TextFieldEffects folder to my project:
screen shot 2015-07-13 at 5 55 13 pm

and use it in my XIB:

screen shot 2015-07-13 at 5 54 05 pm

and I got this warning:

screen shot 2015-07-13 at 5 54 09 pm

at run time i got this error

Unknown class _TtC16TextFieldEffects14HoshiTextField in Interface Builder file.

Failed to set (borderInactiveColor) user defined inspected property on (UITextField): [<UITextField 0x12dd96030> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderInactiveColor.

any idea :( ?

Expected ',' separator AND Expected expression in list of expressions during build

I am getting the following errors when I tried to build the Pod on Swift version 2.1.1 and Xcode 7.2.

Expected expression in list of expressions
Expected ',' separator

The errors are on the following lines in file TextFieldEffects.swift:

fatalError("\(#function) must be overridden")
and
..addObserver(self, selector: #selector(textFieldDidEndEditing)..

This problem appears to be due to the usage of hashes (#) in the code.
Any idea what is happening?

textAlignment - mini-visual-bug

I tried setting textField.textAlignment = .Center however there seem to be a little bug.

At first (without typing anything) it doesn't seem centered...
screen shot 2016-03-15 at 04 45 42

But as soon as I start typing a letter, it pushes the blue line to center and actually works fine..
screen shot 2016-03-15 at 04 46 04

It's just a mini-visual bug. Everything works nicely after I start typing. Or maybe am I the one breaking it?

Using with prefixed attributedText (as the first character)

I tried to add a prefixed character as first character ("+" sign for phone numbers) as soon as clicked on the text field by using attributedText. However, it eliminated the creation animation.

To be exact:

  1. UITextField is empty
  2. As soon as clicked on the text field, + sign added (no animation occured)
  3. If clicked outside & empty, delete prefixed + sign (animation occurs)

I am adding the prefixed character in:

    func textFieldDidBeginEditing(textField: UITextField) {
        if textField == phoneField {
            if textField.text?.characters.count < 2 {
                makePrefix()
            }
        }
    }

Is there a way to check if the animation is completed, and then add the prefixed character? What is the best place to put the creating the attributed text?

Hoshi set text programmatically after it's drawn

hello, Raul.
The issue same with #13 still visible in my app.
I using your library in Objective-C project, when I set text are emty string, the placeholder string do not move down.

Objective-C
_nameText = [[HoshiTextField alloc] initWithFrame:CGRectMake(xPos, yPos, WIDTH - 10, WIDTH0.1667)];
[_nameText setBorderActiveColor:[UIColor LVL_colorWithHexString:@"ffc16a" andAlpha:1.0]];
[_nameText setBorderInactiveColor:[UIColor LVL_colorWithHexString:@"d0d0d0" andAlpha:1.0]];
[_nameText setPlaceholder:@" Name:"];
[self.pageScroll addSubview:_nameText];
yPos += WIDTH0.1667 + 5;

_title = [[HoshiTextField alloc] initWithFrame:CGRectMake(xPos, yPos, WIDTH - 10, WIDTH*0.1667)];
[_title setBorderActiveColor:[UIColor LVL_colorWithHexString:@"ffc16a" andAlpha:1.0]];
[_title setBorderInactiveColor:[UIColor LVL_colorWithHexString:@"d0d0d0" andAlpha:1.0]];
[_title setPlaceholder:@"  Title:"];
[self.pageScroll addSubview:_title];
yPos += WIDTH*0.1667 + 5;

_comment = [[HoshiTextField alloc] initWithFrame:CGRectMake(xPos, yPos, WIDTH - 10, WIDTH*0.1667)];
[_comment setBorderActiveColor:[UIColor LVL_colorWithHexString:@"ffc16a" andAlpha:1.0]];
[_comment setBorderInactiveColor:[UIColor LVL_colorWithHexString:@"d0d0d0" andAlpha:1.0]];
[_comment setPlaceholder:@"  Comment"];
[self.pageScroll addSubview:_comment];
yPos += WIDTH*0.1667 + 5;

and when I call clear function like:

[_nameText setText:@""];
[_title setText:@""];
[_comment setText:@""];
[_nameText becomeFirstResponder];

the placeholder do not move down.

Thank & Regard,
-- Luc.

Yoshiko effect issues

  • The label shouldn't "flash" when you enter or leave the textfield
  • The placeholders don't appear to be rendering in Interface Builder
  • We shouldn't transform the placeholder (to capitalised), getting the value already in the placeholder property should be ideal

Objective-C usage

I really like the library and the effects, but how can I implement this in my Objective-C project (Xcode 6, iOS 8)

Swift 2

Any chance to convert this wonderful library to Swift 2. It would be greatly appreciated :)

Appearance compatibility?

Hi,

I'm trying to use appearance to customize an HoshiTextField instance.

In the AppDelegate, I call the Appearance method:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        Appearance().applyStyling()
        ...

Which contains:

class Appearance: NSObject {

    func applyStyling() {
        HoshiTextField.appearance().backgroundColor = UIColor.redColor() //will work
        HoshiTextField.appearance().placeholderColor = UIColor.redColor() // will fail 
    }
}

Doing that, I get a EXC_BAD_ACCESS in the second line of the method. Any idea why this isn't working? Is it somehow not compatible with appearance yet?

Thanks for your help and for your really cool plugin!

Xcode 7 Interface Builder problem

I installed TextFieldEffects with Carthage. I added frameworks and set the custom class for textfield. However XCode doesn't show IBDesignable properties.

screen shot 2016-02-03 at 14 13 40
screen shot 2016-02-03 at 14 14 01
screen shot 2016-02-03 at 14 14 16

UITextView

Any chance to get this for a UITextView?

YokoTextField does not update when text is set programmatically

Hi @raulriera, nice work on these effects, they look and function great!!

Noticed one issue when using YokoTextField. If you set the text on the field after it is already visible, the field does not animate and still shows as if the text is empty.

To reproduce, simply pre-populate a text field in viewDidAppear(animated) instead of viewWillAppear(animated) and the text field won't show the "populated" appearance until you click on it. Let me know if you need an example project to show it, happy to help!

Thanks a lot.

Dismiss Keyboard

Thanks for the great library!

I am trying to dismiss keyboard on click on return and on click outside. I tried using what I usually use but unfortunately, no luck:

    func textFieldShouldReturn(textField: HoshiTextField) -> Bool {
        self.view.endEditing(true)
        return false
    }

    func dismissKeyboard() {
        view.endEditing(true)
    }

What is the proper way of dismissing the keyboard? Thanks in advance

Subclassing causes exc_bad_access 2 when accessing properties

Created a simple subclass

import UIKit
import TextFieldEffects

class CLHoshiTextField: HoshiTextField {
    var isFieldValid = false
}

And trying to access it:

@IBOutlet var emailTextField : CLHoshiTextField!
self.emailTextField.text = "[email protected]"

Causes exc_bad_access 2. The outlet itself is not nil, and it initialized, so trying to figure out why this is hapenning...

Increasing Height & BorderSize of AkiraTextField

I am using AkiraTextField and I am trying to

  1. Increase the height of the box.. I tried adding +20 to height, but bottom of the box disappears like this:
    screen shot 2016-03-18 at 04 41 57
private func rectForBounds(bounds: CGRect) -> CGRect {
    return CGRect(x: bounds.origin.x, y: bounds.origin.y + placeholderHeight, width: bounds.size.width, height: (bounds.size.height - placeholderHeight)+20)
}
  1. I tried increasing the border of the box a little bit.. I played with borderSize, but unfortunately, seem like it's kind of buggy.
    private let borderSize : (active: CGFloat, inactive: CGFloat) = (1.1, 1.1)

Are there any ways to increase the height or the borderSize? Thanks

HoshiTextField Does not Display Line

As the title suggests, I cannot see the line underneath the Hoshi Text Field.
Code:

let textField = HoshiTextField(frame: textFieldFrame)
textField.delegate = self
textField.placeholderColor = UIColor.whiteColor()
textField.placeholder = "Email"
textField.textColor` = `UIColor.whiteColor()

Carthage support

Please, provide Carthage support to make installation easier.

becomeFirstResponder bug

http://gfycat.com/ThriftyPiercingAlleycat

The link above describes the issue I'm having when I set the textfield to become the first responder. The animation makes the placeholder to go a little diagonal instead of straight up. Any help would be appreciated. Thanks for making this awesome library.

drawViewsForRect method being call multiple times

Since this method is called a few times, the foregroundView and placeholderLabel will be add multiple times. I think this is not very elegant, need to consider only add them only once. Am I right?

Hoshi set text programmatically after it's drawn

Hello,Raul
I’ m using HoshiTextField,everything works fine if I enter text from keyboard.But when I set the text of textfield manually,like textfield.text = “abcdefg”,the placeholder text does not move up, so the text being set got covered by the placeholder text.Is there any way the fix the problem?
Thanks.

Implement more effects

At the moment just a single one of the effects is created. Need to support most if not all of them

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.