SkyFloatingLabelTextField icon indicating copy to clipboard operation
SkyFloatingLabelTextField copied to clipboard

Icon on the right side

Open reeichert opened this issue 8 years ago • 15 comments

I need an Icon on the right side, how can I do that??

just the icon

thank you

reeichert avatar May 05 '16 20:05 reeichert

Hi! This use case is not supported out of the box - however you can definitely do this by extending the control. You could either subclass SkyFloatingLabelTextField, and draw the icon to the right size. You can check how displaying an icon on the left side is implemented in SkyFloatingLabelTextFieldWithIcon (see source here.

Alternatively, you could also try subclassing SkyFloatingLabelTextFieldWithIcon, and move iconLabel to the right side. You would need to override layoutSubviews, textRectForBounds, editingRectForBounds and placeholderRectForBounds to place the textfield to the right location (and the right size).

Please let me know if this helps. We designed the control so when subclassing, you can change the layout programmatically, like in this case.

gergelyorosz avatar May 06 '16 10:05 gergelyorosz

Maybe we should consider accomplishing the icon placement with UITextFields leftView property. In right-to-left context UITextField places leftView on the right, so we could achieve this with very little effort.

From the documentation:

You can use the left overlay view to indicate the intended behavior of the text field. For example, you might display a magnifying glass in this location to indicate that the text field is a search field. The left overlay view flips automatically in a right-to-left user interface.

intonarumori avatar May 06 '16 12:05 intonarumori

That's a good point @intonarumori . @reeichert - would you mind letting us know if you are using the textfield with right-to-left text (e.g. Arabic or Hebrew), or with left-to-right text (e.g. English or Spanish).

Showing the icon on the other side with right-to-left, as Daniel said, should be something we could add to the control. Configuring which side the icon is displayed is also potentially something we could add by just adding an additional property to specify the icon location in SkyFloatingLabelTextFieldWithIcon.

gergelyorosz avatar May 06 '16 12:05 gergelyorosz

Thanks for reply. I'm using LTR text, if you can add and additional property like iconSide = .Left will be awesome!

This is what I'm trying to do: captura de tela 2016-05-07 as 15 30 43

With icon on left side captura de tela 2016-05-07 as 15 30 58

reeichert avatar May 07 '16 18:05 reeichert

I think that ignorer to support this request and keep the RTL support intact iconSide should have the following states:

  • .Left & .Right - Will be flipped when switching to RTL language (right will become left and vice versa)
  • .LeftForce & .RightForce - language orientation won't change the alignment (RTL will use the same value for alignment)

So the enum should have:

  1. .Unspecified (whet we have today, will be flipped for RTL).
  2. .Left
  3. .Right
  4. .LeftForce
  5. .RightForce

pichirichi avatar May 08 '16 09:05 pichirichi

@pichirichi good point on those potential values, as well as thinking of the "force" options. I'll give the implementation a go the next few days 👍

gergelyorosz avatar May 09 '16 15:05 gergelyorosz

@gergelyorosz the alignment to right is already available from the RTL support, all is required is just the property and referencing it. I might have time tomorrow to look into it if you want.

the only problems there are no enums in inspectable and it will be a problem in the storyboard (making it readable)

pichirichi avatar May 09 '16 15:05 pichirichi

Thanks @pichirichi . I'll try to squeeze some time in by tomorrow as well. Sounds like it will be a simple change then! (Just finishing another fix first)

gergelyorosz avatar May 09 '16 15:05 gergelyorosz

up

reeichert avatar May 19 '16 13:05 reeichert

Hello everybody.

I was looking for something like this

passwordfield A responsive icon on the right ;)

Anyone did an extension or something you can help me with. If not I'll try @gergelyorosz suggestion.

Thanks in advance

alelevinas avatar Dec 27 '16 20:12 alelevinas

Hey guys, is there an option added to the library to add icon to the right instead of the left?

anitaa1990 avatar Mar 20 '18 10:03 anitaa1990

There is no option to set iconImage to Right or Left. Still you can achieve this by coding. Just make the textFiled class as SkyFloatingLabelTextField and add this two lines to your code

textField.rightViewMode = UITextFieldViewMode.always
textField.rightView = UIImageView(image: UIImage(named : "imageName"))

With this no need to use SkyFloatingLabelTextFieldWithIcon

chejarla-venkatesh avatar May 28 '18 06:05 chejarla-venkatesh

@chejarla-venkatesh yes but if the text is too large, then the letters are above the image. And a workaround is the following

import SkyFloatingLabelTextField

extension SkyFloatingLabelTextField {
    /**
     Calculate the rectangle for the textfield when it is not being edited
     - parameter bounds: The current bounds of the field
     - returns: The rectangle that the textfield should render in
     */
    override open func textRect(forBounds bounds: CGRect) -> CGRect {
        super.textRect(forBounds: bounds)
        let rightViewWidth = self.rightView?.bounds.width ?? 0.0
        let rect = CGRect(
            x: 0,
            y: titleHeight(),
            width: bounds.size.width - rightViewWidth,
            height: bounds.size.height - titleHeight() - selectedLineHeight
        )
        return rect
    }
    
    /**
     Calculate the rectangle for the textfield when it is being edited
     - parameter bounds: The current bounds of the field
     - returns: The rectangle that the textfield should render in
     */
    override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        let rightViewWidth = self.rightView?.bounds.width ?? 0.0
        let rect = CGRect(
            x: 0,
            y: titleHeight(),
            width: bounds.size.width - rightViewWidth,
            height: bounds.size.height - titleHeight() - selectedLineHeight
        )
        return rect
    }
}

kwstasna avatar Jul 30 '18 14:07 kwstasna

Make the textFiled class as SkyFloatingLabelTextField and add this code

 self.textField.rightViewMode = .always
 let imageView = UIImageView()
 let image = UIImage(named: "icon")
 imageView.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
 imageView.image = image
 self.textField.rightView = imageView

TomikeKrasnay avatar Oct 22 '18 14:10 TomikeKrasnay

@TomikeKrasnay Thank you, your answer worked properly

bhanushalilinesh avatar Mar 13 '19 09:03 bhanushalilinesh