FloatLabelFields - Float Label Fields With Swift

Overview

FloatLabelFields

Platform License Issues

Overview

FloatLabelFields is the Swift implementation of a UX pattern that has come to be known as the "Float Label Pattern". The initial Objective-C implementation of this pattern can be found on Github as JVFloatLabeledTextField.

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

Since the code is Swift-based, do note that this version of the component swill only work on iOS 7.x+.

Installation

You can install the FloatLabelField components two ways:

Via Interface Builder

Just add a UITextField or UITextView to your storyboard and then set the custom class for the control to either FloatLabelTextField or FloatLabelTextView.

Custom Class

Note: Sometimes, you might have to set the Module explicitly instead of letting Xcode set it implicitly too before it works.

Next, switch to the Attributes Inspector tab and set the necessary attributes to configure your text field or text view. The Placeholder attribute (or Hint in the case of a UITextView) defines the actual title which will be used for your field.

Properties

The other values such as Hint Y Padding, Title Y Padding, Title Text Colour etc. define how the title will look.

If everything is set up correctly, you'll see the title display on Interface Builder after you've configured the field.

Final Result

Via Code

Using FloatLabelFields via code works the same as you would do to set up a UITextField or UITextView instance. Simply create an instance of the class, set the necessary properties, and then add the field to your view.

let fld = FloatLabelTextField(frame:vwHolder.bounds)
fld.placeholder = "Comments"
vwHolder.addSubview(fld)

Credits

Additional References

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

Questions?

You might also like...
A lightweight library to calculate tensors in Swift, which has similar APIs to TensorFlow's
A lightweight library to calculate tensors in Swift, which has similar APIs to TensorFlow's

TensorSwift TensorSwift is a lightweight library to calculate tensors, which has similar APIs to TensorFlow's. TensorSwift is useful to simulate calcu

Running Swift automatic differentiation on iOS
Running Swift automatic differentiation on iOS

Differentiation Demo This is an example of Swift's automatic differentiation running on iOS. It is a modified version of the game from ARHeadsetKit tu

Track List Detail App With Swift

TrackListDetailApp TrackListDetailApp is master-detail application that containsa a list of items obtained from a iTunes Search API and show a detaile

A Swift package for working with probability-driven randomness

ControlledChaos ControlledChaos is a simple Swift package for working with proba

This repo contains beginner examples to advanced in swift. Aim to create this for learning native iOS development.

iOS-learning-with-swift-22 This repo contains beginner examples to advanced in swift. Aim to create this for learning native iOS development. Oh, you

NGram: a Swift implementation to generate N-grams (all word combinations) from an input string

nGram nGram is a Swift implementation to generate N-grams (all word combinations

TensorFlow C API Class Wrapper in Server Side Swift.
TensorFlow C API Class Wrapper in Server Side Swift.

Perfect TensorFlow 简体中文 This project is an experimental wrapper of TensorFlow C API which enables Machine Learning in Server Side Swift. This package

Swift for TensorFlow
Swift for TensorFlow

Swift for TensorFlow (Archived) Swift for TensorFlow was an experiment in the next-generation platform for machine learning, incorporating the latest

A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.
A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.

GraniteUI - v0.0 - WIP A powerful SwiftUI Architecture that merges Redux event handling and state management with functional programming. While bringi

Owner
Android Developer
null
Accelerated tensor operations and dynamic neural networks based on reverse mode automatic differentiation for every device that can run Swift - from watchOS to Linux

DL4S provides a high-level API for many accelerated operations common in neural networks and deep learning. It furthermore has automatic differentiati

Palle 87 Dec 29, 2022
The Swift machine learning library.

Swift AI is a high-performance deep learning library written entirely in Swift. We currently offer support for all Apple platforms, with Linux support

Swift AI 5.9k Jan 2, 2023
BrainCore is a simple but fast neural network framework written in Swift.

BrainCore is a simple but fast neural network framework written in Swift. It uses Metal which makes it screamin' fast. If you want to see it

Alejandro Isaza 377 Jun 29, 2022
MLKit is a simple machine learning framework written in Swift.

MLKit (a.k.a Machine Learning Kit) ?? MLKit is a simple machine learning framework written in Swift. Currently MLKit features machine learning algorit

Guled 152 Nov 17, 2022
Matft is Numpy-like library in Swift. Function name and usage is similar to Numpy.

Numpy-like library in swift. (Multi-dimensional Array, ndarray, matrix and vector library)

null 80 Dec 21, 2022
A simple Swift package which acts as an OpenAI client for the GPT-3 API.

SwiftyGPT3 A simple Swift package which acts as an OpenAI client for GPT-3 brought to you by the Airgift Crew. Supports GPT-3 Codex! Requirements iOS

Airgift 23 Dec 25, 2022
Artificial intelligence/machine learning data structures and Swift algorithms for future iOS development. bayes theorem, neural networks, and more AI.

Swift Brain The first neural network / machine learning library written in Swift. This is a project for AI algorithms in Swift for iOS and OS X develo

Vishal 331 Oct 14, 2022
A toolbox of AI modules written in Swift: Graphs/Trees, Support Vector Machines, Neural Networks, PCA, K-Means, Genetic Algorithms

AIToolbox A toolbox of AI modules written in Swift: Graphs/Trees, Linear Regression, Support Vector Machines, Neural Networks, PCA, KMeans, Genetic Al

Kevin Coble 776 Dec 18, 2022
A framework for building fast genetic algorithms in Swift.

Revolver is a framework for building fast genetic algorithms in Swift 3.0. Features Chromosomes: strings, trees Genetic operators: reproduction, mutat

Petr Mánek 27 Nov 17, 2022
A Swift deep learning library with Accelerate and Metal support.

Serrano Aiming to offering popular and cutting edge techs in deep learning area on iOS devices, Serrano is developed as a tool for developers & resear

pcpLiu 51 Nov 17, 2022