A static character prefix in UITextField

cocoa-touch, ios, uitextfield, user-interface

Solution

Simply adding a gray `UILabel` on top of the `UITextField` does the trick:

Note that the `UILabel` behaves like a background image, the entered text stays on top:

UPDATE

Additionally you can add some padding to the `UITextField` using the following code:

UIView *thePadding = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
theTextField.leftView = thePadding;
theTextField.leftViewMode = UITextFieldViewModeAlways;

This way the text cannot cover the prefix character. Adjust the rect to make it working properly in your situation.

Problem

Is there a built-in way to add a character prefix to a `UITextField` like the screenshot below? If no, what is the best, most straight-forward way to accomplish this? I am thinking the `background` property might be able to do this.

Original source