erabhishekchandani / acfloatingtextfield Goto Github PK
View Code? Open in Web Editor NEWIt is a subclass of UITextfield to Provide the floating label and customisations.
License: MIT License
It is a subclass of UITextfield to Provide the floating label and customisations.
License: MIT License
i have added code in viewDidLoad
let aTextField.frame = CGRect(x:20, y:300, width:UIScreen.main.bounds.width-40, height:45)
aTextField.delegate = self
aTextField.text = "hello"
aTextField.placeholder = "Password"
aTextField.errorText = "error"
self.view.addSubview(aTextField)
clear text to my custom logic like this way
aTextField.text = ""
then is display blur
Hi,
I'm Facing the bellow issue when i need to edit my view i can't see the ACFloating Text fields due to the IB Designalbes rederring issue.
error: IB Designables: Failed to render and update auto layout status for myViewController (VQr-Y8-dMK): dlopen(ACFloatingTextfield_Objc.framework, 1): no suitable image found. Did find:
ACFloatingTextfield_Objc.framework: required code signature missing for 'ACFloatingTextfield_Objc.framework'
Please help
When I open a new page , where i kept acfloatingtextfield with some value , placeholder is not coming. When i again open then only it is visible. can you kindly check this.
Thanks in advance
how can i show the error message at bottom of the line
Hi,
Its happening on xCode 9, iOS 11. I also checked it on your demo app.
Could you look at it please?
Hello!
I'm use the OC version. If I add leftView or rightView for ACFloatingTextfield, the text will be overlay with the leftView or rightView.
Hi,
Excellent component, however if i manually set the text values like self.txtfloatval.text = @"Something"; the text disappears sometimes in the textfield. if i tap on the field the text appears. Just called [self layoutSubviews]; after [self floatTheLabel]; in the setText function which seem to solve the issue.
Hi,
I didn't have this situation while working on xCode 8 and iOS 10 devices. But its strangely occurs on xCode 9.
Could you look at it please?
I had to change the line;
/// Change Bottom Line Color.
- //@IBInspectable open var lineColor : UIColor = UIColor.black
+ @IBInspectable open var lineColor : UIColor?
如题。。。
ACFloatingTextfield animation created by code is very strange.
ACFloatingTextfield created by Storyboard is no problem.
Hello,
Can we make a same behavious for uitextView?
thanks in advanced.
I have add [txtEmail becomeFirstResponder];, its automatically remove floating textfield functionality
How can i fix this?
I manually added the ACFloatingTextField.swift file. I am thinking it was written in Swift 1 because my project uses Swift 2 and some of the issues were just changing the name of a function call. However there were some issues with some of your if statement and even though there is a field for errorTextColor your code was pointing the the placeholder color. Below is the code with the updates I made.
//
// ACFloatingTextfield.swift
// ACFloatingTextField
//
// Created by Er Abhishek Chandani on 31/07/16.
// Copyright © 2016 Abhishek. All rights reserved.
//
import UIKit
@IBDesignable
class ACFloatingTextfield: UITextField {
var bottomLineView : UIView?
var labelPlaceholder : UILabel?
var labelErrorPlaceholder : UILabel?
var showingError : Bool = false
@IBInspectable var disableFloatingLabel : Bool = false
@IBInspectable var lineColor : UIColor = UIColor.blackColor()
@IBInspectable var selectedLineColor : UIColor = UIColor(red: 19/256.0, green: 141/256.0, blue: 117/256.0, alpha: 1.0)
@IBInspectable var placeHolderColor : UIColor = UIColor.lightGrayColor()
@IBInspectable var selectedPlaceHolderColor : UIColor = UIColor(red: 19/256.0, green: 141/256.0, blue: 117/256.0, alpha: 1.0)
@IBInspectable var errorTextColor : UIColor = UIColor.redColor()
@IBInspectable var errorLineColor : UIColor = UIColor.redColor()
//MARK:- Set Text
override var text:String? {
didSet {
floatTheLabel()
checkForDefaulLabel()
}
}
override var placeholder: String? {
willSet {
self.labelPlaceholder?.text = newValue
}
}
var errorText : String? {
willSet {
self.labelErrorPlaceholder?.text = newValue
}
}
//MARK:- UITtextfield Draw Method Override
override func drawRect(rect: CGRect) {
super.drawRect(rect)
self.updateTextField(CGRect(x:self.frame.minX, y:self.frame.minY, width:rect.width, height:rect.height));
}
// MARK:- Loading From NIB
override func awakeFromNib() {
super.awakeFromNib()
self.initialize()
}
// MARK:- Intialization
override init(frame: CGRect) {
super.init(frame: frame)
self.initialize()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.initialize()
}
// MARK:- Text Rect Management
override func textRectForBounds(bounds: CGRect) -> CGRect {
if (showingError) {
return CGRect(x:0, y:0, width:bounds.size.width, height:bounds.size.height);
}else{
return CGRect(x:4, y:4, width:bounds.size.width, height:bounds.size.height);
}
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
if (showingError) {
return CGRect(x:0, y:0, width:bounds.size.width, height:bounds.size.height);
}else{
return CGRect(x:4, y:4, width:bounds.size.width, height:bounds.size.height);
}
}
//MARK:- UITextfield Becomes First Responder
override func becomeFirstResponder() -> Bool {
let result = super.becomeFirstResponder()
self.textFieldDidBeginEditing()
return result
}
//MARK:- UITextfield Resigns Responder
override func resignFirstResponder() -> Bool {
let result = super.resignFirstResponder()
self.textFieldDidEndEditing()
return result
}
//MARK:- Show Error Label
func showError() {
showingError = true;
self.updateTextField(self.frame)
self.showErrorPlaceHolder();
}
func showErrorWithText(errorText : String) {
self.errorText = errorText;
showingError = true;
self.updateTextField(self.frame)
self.showErrorPlaceHolder();
}
}
extension ACFloatingTextfield {
//MARK:- ACFLoating Initialzation.
func initialize() -> Void {
/// HIDE DEFAULT PLACEHOLDER LABEL OF UITEXTFIELD
checkForDefaulLabel()
/// Adding Bottom Line
addBottomLine()
/// Placeholder Label Configuration.
addFloatingLabel()
/// Adding Error Label
if (showingError) {
if (self.errorText == "" || self.errorText == nil) {
self.errorText = "Error";
}
self.addErrorPlaceholderLabel()
}
/// Checking Floatibility
if self.text != nil && self.text != "" {
self.floatTheLabel()
}
}
//MARK:- ADD Bottom Line
func addBottomLine(){
bottomLineView?.removeFromSuperview()
//Bottom Line UIView Configuration.
bottomLineView = UIView(frame: CGRect(x:0, y:self.frame.height-1, width:self.frame.width, height:2))
bottomLineView?.backgroundColor = lineColor;
bottomLineView?.tag = 20;
if bottomLineView != nil {
self.addSubview(bottomLineView!)
}
}
//MARK:- ADD Floating Label
func addFloatingLabel(){
labelPlaceholder?.removeFromSuperview()
var placeholderText : String? = labelPlaceholder?.text
if self.placeholder != nil && self.placeholder != "" {
placeholderText = self.placeholder!
}
labelPlaceholder = UILabel(frame: CGRect(x:5, y:0, width:self.frame.size.width-5, height:self.frame.height))
labelPlaceholder?.text = placeholderText
labelPlaceholder?.textAlignment = self.textAlignment
labelPlaceholder?.textColor = placeHolderColor
labelPlaceholder?.font = self.font
labelPlaceholder?.tag = 21
if labelPlaceholder != nil {
self.addSubview(labelPlaceholder!)
}
}
func addErrorPlaceholderLabel() -> Void {
self.endEditing(true)
labelErrorPlaceholder?.removeFromSuperview()
labelErrorPlaceholder = UILabel(frame: CGRect(x:5, y:0, width:self.frame.size.width-5, height:self.frame.height))
labelErrorPlaceholder?.text = self.errorText
labelErrorPlaceholder?.textAlignment = self.textAlignment
labelErrorPlaceholder?.textColor = errorTextColor
labelErrorPlaceholder?.font = UIFont(name: (self.font?.fontName ?? "helvetica")!, size: 12)
labelErrorPlaceholder?.tag = 21
var frameError = labelErrorPlaceholder?.frame;
frameError?.size.height = 15;
frameError?.origin.y = self.bounds.size.height - (frameError?.size.height ?? 0)!;
frameError?.origin.x = 0;
labelErrorPlaceholder?.frame = frameError ?? CGRect.zero;
if labelErrorPlaceholder != nil {
self.addSubview(labelErrorPlaceholder!)
}
labelErrorPlaceholder?.hidden = true;
}
func showErrorPlaceHolder() {
labelErrorPlaceholder?.hidden = false;
var bottmLineFrame = bottomLineView?.frame ?? CGRect.zero;
bottmLineFrame.origin.y = (labelErrorPlaceholder?.frame.origin.y ?? 0)! - 1;
labelErrorPlaceholder?.alpha = 0;
labelErrorPlaceholder?.frame = CGRect(x:(labelErrorPlaceholder?.frame.origin.x ?? 0)!, y:(labelErrorPlaceholder?.frame.origin.y ?? 0)!-5, width:labelErrorPlaceholder?.frame.size.width ?? 0, height:labelErrorPlaceholder?.frame.size.height ?? 0);
var labelErrorFrame = labelErrorPlaceholder?.frame ?? CGRect.zero;
labelErrorFrame.origin.y = labelErrorFrame.origin.y + 6;
UIView.animateWithDuration(0.2) {
self.bottomLineView?.frame = bottmLineFrame;
self.bottomLineView?.backgroundColor = self.errorLineColor;
self.labelErrorPlaceholder?.alpha = 1;
self.labelErrorPlaceholder?.frame = labelErrorFrame;
}
}
func hideErrorPlaceHolder(){
showingError = false;
var labelErrorFrame = labelErrorPlaceholder?.frame;
labelErrorFrame?.origin.y = (labelErrorFrame?.origin.y ?? 0)! - 6;
UIView.animateWithDuration(0.2) {
self.labelErrorPlaceholder?.alpha = 0;
self.labelErrorPlaceholder?.frame = labelErrorFrame!;
}
}
// Checks The Default Placeholder Label
func checkForDefaulLabel() -> Void {
var aLabelView : UIView?
for aView in self.subviews {
if aView is UILabel {
if aView.tag != 21 {
aLabelView = aView
}
}
}
if self.text == nil || self.text == "" {
aLabelView?.hidden = true;
}else{
aLabelView?.hidden = false;
}
}
//MARK:- Float & Resign
func floatTheLabel() -> Void {
if (self.text!.isEmpty && self.isFirstResponder()) {
floatPlaceHolder(true)
}else if (self.text!.isEmpty && !self.isFirstResponder()) {
resignPlaceholder()
}else if (!self.text!.isEmpty && !self.isFirstResponder()) {
floatPlaceHolder(false)
}else if (!self.text!.isEmpty && self.isFirstResponder()) {
floatPlaceHolder(true)
}
self.checkForDefaulLabel()
}
//MARK:- Upadate and Manage Subviews
func updateTextField(frame:CGRect) -> Void {
self.frame = frame;
self.initialize()
}
//MARK:- Float UITextfield Placeholder Label.
func floatPlaceHolder(selected:Bool) -> Void {
var bottomLineFrame = bottomLineView?.frame
bottomLineFrame?.origin.y = self.frame.height-2
if disableFloatingLabel {
labelPlaceholder?.hidden = true
UIView.animateWithDuration(0.2, animations: {
self.bottomLineView?.frame = bottomLineFrame!
})
return
}
var labelFrame = labelPlaceholder?.frame
labelFrame?.size.height = 12
if selected {
bottomLineView?.backgroundColor = selectedLineColor
self.labelPlaceholder?.textColor = self.selectedPlaceHolderColor;
} else {
bottomLineView?.backgroundColor = lineColor;
bottomLineFrame?.origin.y = self.frame.height-1
self.labelPlaceholder?.textColor = self.placeHolderColor;
}
UIView.animateWithDuration(0.2, animations: {
self.labelPlaceholder?.frame = labelFrame!;
self.labelPlaceholder?.font = UIFont(name: (self.font?.fontName)!, size: 12)
self.bottomLineView?.frame = bottomLineFrame!;
})
}
//MARK:- Resign the Placeholder
func resignPlaceholder() -> Void {
var bottomLineFrame = bottomLineView?.frame
bottomLineFrame?.origin.y = self.frame.height-1
bottomLineView?.backgroundColor = lineColor;
if disableFloatingLabel {
labelPlaceholder?.hidden = false
self.labelPlaceholder?.textColor = self.placeHolderColor;
UIView.animateWithDuration(0.2, animations: {
self.bottomLineView?.frame = bottomLineFrame!
})
return
}
let labelFrame = CGRect(x:5, y:0, width:self.frame.size.width-5, height:self.frame.size.height)
UIView.animateWithDuration(0.2, animations: {
self.labelPlaceholder?.frame = labelFrame;
self.labelPlaceholder?.font = self.font
self.labelPlaceholder?.textColor = self.placeHolderColor;
self.bottomLineView?.frame = bottomLineFrame!;
})
}
//MARK:- UITextField Begin Editing.
func textFieldDidBeginEditing() -> Void {
if showingError {
self.hideErrorPlaceHolder()
}
self.floatTheLabel()
self.layoutSubviews()
}
//MARK:- UITextField Begin Editing.
func textFieldDidEndEditing() -> Void {
self.floatTheLabel()
}
}
Also, I do not know what your intentions are for this library but if you are going to make it compatible with swift 3 I would do that as a separate file so users still using swift 2 can also use this awesome library. I know Android has this built in and it has been annoying not having a way to have that same functionality on iOS. Thanks for writing this, it was exactly what I was looking for!
I have a UITableViewController with Static Cells. These cells contain ACFloatingTextFields. I am configuring these text fields on viewDidLoad as :
textField.selectedLineColor = [self getThemeColor];
textField.lineColor = [self getThemeColor];
textField.text = @"";
The problem is that the visible cells (text fields) of UITableViewControllers display Placeholder. Non-Visible cells do not display placeholder. (Look for the attached GIFs.)
Am I missing something specific to UITableViewController? Please guide me.
I came across this issue but it looks different than my situation : #2
I am using Objective-C version.
still showing the text and not the "labelPlaceholder" when the textfield becomes firstRespond on the first time.
Hi,
Thanks for this awesome library.
Can you please let me know how can I use this control in UITextView?
Regards.
I am using your library and it is good. But why cursor is not available for password options. Thanks in advance
I love this library!
However, is there a way to dismiss the error message programmatically after using showError:
?
Hello ,
I facing issue over line height of textBox , it is 2px i set bottomLineViewHeight constraint to 1 px in ACFloatingTextfield (hard coded), i am using storyboard , but in some pages text bottom Line height is 2px(Suppose 3 textbox 2 have line height 1 px but 1 have line height 2px) , try to find out this issue but unable to resolve it , can you guys help me what i am doing wrong. @ErAbhishekChandani @keshavvishwkarma
When I use in storyboards I get error for IBDesignables:
Main.storyboard: error: IB Designables: Failed to update auto layout status: Failed to load designables from path (null).
Main.storyboard: error: IB Designables: Failed to render and update auto layout status for LoginViewController (XXZ-vo-xhS): Failed to load designables from path (null)
file:///Users/carlossolano/kolbi-ios/Kolbi/Kolbi/servicesStoryboard.storyboard: error: IB Designables: Failed to render and update auto layout status for AddPhoneNumbersViewController (xOd-dz-gYy): Failed to load designables from path (null)
That Error appears in storyboard after set ACFloatingTextField in class for the textField. After that, it shows the View in blank. If i set again the class to UITextField, it works again.
this is my code , the buttomLine and line Color not normal work
_pwdTextField = [[ACFloatingTextField alloc]init];
[_pwdTextField setPlaceholder:@"密码"];
_pwdTextField.tintColor = [UIColor colorWithRed:0.979 green:0.326 blue:0.380 alpha:1];
[_pwdTextField setBackgroundColor:[UIColor whiteColor]];
_pwdTextField.secureTextEntry = YES;
_pwdTextField.selectedLineColor = [UIColor colorWithHexString:@"#999999"];
_pwdTextField.selectedPlaceHolderColor = [UIColor colorWithHexString:@"#CCCCCC"];
_pwdTextField.placeHolderColor = [UIColor colorWithHexString:@"#CCCCCC"];
_pwdTextField.lineColor = [UIColor colorWithHexString:@"#E5E5E5"];
}
the buttomLine frame Y is 0 , is not self height - 1, and i set LineColor but is not use , you dont code setLineColor , init ButtomLine is init function, so ,i don
t know _lineColor is block color,you can reset setLineColor
function. the is last version
click a text box animation not working
When a text field resign first responder and the focus passes on another text field, it shows an horrible animation.
I attached the video of that issue.
I've tried to fix it, but i didn't find any fix. :(
I am using ACFloatingTextfield to float the placeholder.
I have set the placeholder color programmatically and by storyboard inspector also.
But it is changing it after the selection.
It is not setting up the color while the view is loaded.
Please tell me why is this happening?
Thanks
Jittender (iOS Developer)
@ErAbhishekChandani ErAbhishekChandani Obj c file is completely out dated. Can you please update the file. It's getting lot of warnings around 20+.
Hello, Abhishek,
First of all thanks for making such a nice library. But I am having trouble setting multiple custom fonts to the attributedText property of this control. Example is given below.
Example -
Result I want = Hello World
Result now = Hello World
Currently whatever font style I apply it always take the later font in this case the font of "World" is set to the whole string. There is no issue with creating NSAttributedString because I am using the same string in UILabel and it works fine.
Please if you have a quick fix let me know.
Thanks,
hi, its not an actually an issue, but could you help me point out where i need to modify if i want to put all side border? (not just bottom line)
thanks
I am used ACFloatingTextfield version 1.5 , Objective C
Create the textfield programmatically => error :((
https://ezgif.com/video-to-gif/ezgif-4-c5caa6562c.mov
When I want to install this via Cocoapods I get the error:
[!] Unable to find a specification for ACFloatingTextfield
Probably meaning the pod can't be found. When looking for it on cocoapods.org I see no typos are made, so there must some issue with how you guys handle the pods I guess...
Hi,
Can can we display error message at bottom of the Textfield Line?
https://im3.ezgif.com/tmp/ezgif-3-cd780743a6.gif
xcode9
ios11
ACFloatingTextfield version 1.5
objc.
It would be great if there is a option for reducing the width of line
Hi. I have found a recent issue i.e when I use your texfield for Iphone 7 plus, the placeholder is not going upside. Only for iphone 7 plus.
I am using 'ACFloatingTextfield-Swift' latest version (1.7), and sometimes when I load a View Controller, the placeholder is missing, then if I start typing it appears. And sometimes the cursor is missing while editing.
In iOS 11 the placeholder animation starts only when the text is not empty.
And it has also wrong behaviour.
Thank you
Please fix bugs.
thanks
[<ACFloatingTextField 0x7fbec4e057d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _placeholderLabel.'
styling via appearance so we don't need to do it one by one
thanks
Hi, thanks for this great library.
I have issue to reset the default state after showing an error like this:
self.showErrorTextField(textField, message: "Username not available")
textField.errorTextColor = UIColor.red
How i get back to default state, for example gray when I want to begin editing? Without have to change focus to other text field first.
Thanks
how to use it with pod?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.