Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i put icons on the textfield like this #495

Closed
sagaya opened this issue Aug 24, 2016 · 8 comments
Closed

How can i put icons on the textfield like this #495

sagaya opened this issue Aug 24, 2016 · 8 comments

Comments

@sagaya
Copy link

sagaya commented Aug 24, 2016

screen shot 2016-08-24 at 3 42 12 pm

@adamdahan
Copy link
Contributor

adamdahan commented Aug 25, 2016

@Cosmo1234

Few techniques you can use for this:

  1. You can tap into the textField sublayers and perform a transform that will push the actual textfield's editable view over to the right. Then you can just draw the image in the paddings space.
  2. You can override UITextfield layout and add an image as a subview @ position 0, 0.
  3. You can create a custom view with a regular textfield + a CAShapeLayer as a divider and an image as subviews.

@DanielDahan Might be nice to consider this for option in Material 2.

Thanks @Cosmo1234 - closing this ticket.

@daniel-jonathan
Copy link
Member

@adamdahan agreed.

@CavalcanteLeo
Copy link

CavalcanteLeo commented Nov 30, 2017

any news about that?

Using leftView, the layout looks like was made by an amateur designer.
And adding as subview, it's impossible to add extra padding to the text, so the icon will be over the text
And the textInset is not visible in objective-c

@DanielDahan

adding as subview:
img_df4047a384aa-1

adding as leftView:
img_0fefb95dace6-1

@daniel-jonathan
Copy link
Member

@CavalcanteLeo can you try this commit: 5065e88, it is available in Objc-C now. As well, have you looked at the TextField sample? To put it fully across as the image above, I will need to investigate that.

@CavalcanteLeo
Copy link

I could do it by creating a UITextField Category in objective-c

#import <objc/runtime.h>

@implementation UITextField (Padding)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

- (CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectMake(bounds.origin.x + 21, bounds.origin.y + 8,
                      bounds.size.width - 31, bounds.size.height - 16);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
    return [self textRectForBounds:bounds];
}

@end

and then i just imported to my viewcontroller,

But i will try this commit, this might work, and will be much better than create a category to change the properties

@daniel-jonathan
Copy link
Member

@CavalcanteLeo Yes, I reopened the issue to make an internal fix for this :) Maybe you can suggest something before I jump into this issue more.

@CavalcanteLeo
Copy link

CavalcanteLeo commented Dec 4, 2017

It's visible now, and worked perfectly!

Thanks dude!

captura de tela 2017-12-04 as 16 46 26

@daniel-jonathan
Copy link
Member

Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants