Unfortunately, I do not say "Swift", but you can easily translate the Objective-C version ...
You are talking about the so-called "placeholder"; a string (or attribute string) that appears in a UITextField when no text is inserted.
To display the image here, use the following code:
// Create a NSTextAttachment with your image NSTextAttachment* placeholderImageTextAttachment = [[NSTextAttachment alloc] init]; placeholderImageTextAttachment.image = [UIImage imageNamed:@"Your image name"]; // Use 'bound' to adjust position and size placeholderImageTextAttachment.bounds = CGRectMake(0, 0, 16, 16); NSMutableAttributedString* placeholderImageString = [[NSAttributedString attributedStringWithAttachment:placeholderImageTextAttachment] mutableCopy]; // Append the placeholder text NSMutableAttributedString* placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Search", nil)]; [placeholderImageString appendAttributedString:placeholderString]; // set as (attributed) placeholder _yourTextField.attributedPlaceholder = placeholderImageString;
source share