I have a UITextfield with some placeholder text.
I have used both alignment properties. However, the palceholder text is still a little on the upper side. Can anyone help me out ?
Thanks.
var delegate: UITextFieldDelegate? The string that displays when there is no other text in the text field. This value is nil by default. The placeholder string is drawn using a system-defined color. The text that the text field displays. The styled text that the text field displays.
How to Align the Placeholder Text of an Input Field in HTML. The ::placeholder pseudo-element allows styling the placeholder text of a form element. It can change from browser to browser. The placeholder attribute is used to describe the expected value of an input field. Before entering a value, there is a short hint displayed in the field.
When the user start editing the text, the cursor shows up at the start of the field but the placeholder is still there until they type a character Once they type a character in the field (i.e., when it has contents) the placeholder text disappears and the text color gets darker
UITextField has pretty support for placeholder text. UITextView doesn’t. So if you need a multi-line editable text component, you don’t get a pretty placeholder. Here’s how to roll your own. This tutorial has been updated to Swift 2.0. First, requirements.
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Here's my solution in MonoTouch for having to fix the alignment of placeholder vs text. As I noted in the comments -- there are three distinct pieces: the editing, the static text, and the static placeholder. The equivalent in Objective-C is drawTextInRect: and drawPlaceholderInRect:.
My solution was to subclass and offset the mis-aligned items. Unfortunately the issue seems to be related to the font-file itself and how editing mode affects it, vs. how iOS renders static text.
Hope this helps someone.
Allison
public class MyTextField : UITextField
{
public MyTextField(RectangleF rect) : base(rect)
{
}
public override void DrawPlaceholder(RectangleF rect)
{
base.DrawPlaceholder(new RectangleF(rect.X, rect.Y + 2, rect.Width, rect.Height));
}
public override void DrawText(RectangleF rect)
{
base.DrawText(new RectangleF(rect.X, rect.Y + 2, rect.Width, rect.Height));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With