Show an image alongside the placeholder text in a UITextField

astahirastahir USMember ✭✭

Hi all,

Is there a way to show an image beside the placeholder text of a Text Field as shown in the attached image?

Thanks

Best Answer

Answers

  • astahirastahir USMember ✭✭

    Thanks @adamkemp for your response.

    I tried doing like you said but it did not work. Here is the complete scenario:
    1) I have a text field called txtTest and an image view called imgTest
    2) I have set an image source for the image view
    3) For the text field, I have set its placeholder text to be 'Username'
    4) In ViewDidLoad of my ViewController.cs file I wrote this.txtTest.LeftView = this.imgTest;

    I thought I may see the image on the left but I just see the placeholder text and no image.

    PS: For some reason, the screenshot attached to my original question has been removed, so I am attaching it again for quick reference.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Be sure you give the image view a size. After setting its image call SizeToFit on it.

  • astahirastahir USMember ✭✭

    @adamkemp, thanks a lot for pointing me to the right direction. LeftView was the way to go but the following line actually made the image show:

    this.txtTest.LeftViewMode = UITextFieldViewMode.Always;

Sign In or Register to comment.