Code Monkey home page Code Monkey logo

swiftfloatinglabeltextfield's Introduction

SwiftFloatingLabelTextField

For learning Swift, one of the things I did was convert some existing Objective-C tools and ported them over to Swift. This repository is the result of doing that with JVFloatLabeledTextField.

Usage

Usage is pretty simple. Just add FloatingLabelTextField.swift to your project, and then either set the custom class for a UITextField in Interface Builder to be FloatingLabelTextField, or create it programatically let textField = FloatingLabelTextField( frame: CGRectMake( 0, 0, 320.0, 44.0 ) )

See the provided Example project for a live example.

Property Definitions

  • floatingLabel:UILabel The actual label that will be floated above a textfield
  • floatingLabelTextColor: UIColor The Default color of the floatingLabel while it is still a "placeholder"
  • floatingLabelIsBoundToParent:Bool When set to true, the label will be shown "inside" of the textfield when it is "floating". False will have the label float "above" the textfield instead. By default, this is set to false (for my own preference)
  • placeholderYPadding:CGFloat The amount of padding to apply to the floatingLabel's Y-Position when it is floated. This will change based on the floatingLabelIsBoundToParent value.
  • yPadding:CGFloat The Amount of padding applied to the UITextField itself. This is only used when floatingLabelIsBoundToParent is set to true (in order to make room for the floatingLabel)
  • showAnimationDuration The duration of the animation when "showing" the floatingLabel
  • hideAnimationDuration:NSTimeInterval The duration of the animation when "hiding" the floatingLabel
  • floatingLabelActiveTextColor:UIColor The color of the floatingLabel when it is in floated display mode (rather than placeholder)
  • animatedYPos:CGFloat The Y-Position that the floatedLabel should be animated to when transitioning from placeholder to floated display mode
  • floatingLabelFont:UIFont The font to use for the floatedLabel

Todo

This could be better represented using the IBDesignable/IBInspectable method. When attempting to do this though, xcode throws errors such as:

  • @IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
  • Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.

This is more than likely something silly I'm doing, but after having exhausted stackoverflow and numerous walkthroughs on the subject, I decided its just not something I'm capable of doing at this stage. If some smarter dev would like to add this functionality, by all means do and let me know!

swiftfloatinglabeltextfield's People

Contributors

infolock avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.