Placeholder text and typed text do not align in UITextField

I have a UIText field with some placeholder text.

I used both alignment properties. However, the text peeping is still a bit on the top side. Can anyone help me out?

Thank.

+5
source share
4 answers
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+3
source

Here is my solution in MonoTouch to fix the alignment of placeholder vs text. As I noticed in the comments, there are three different parts: editing, static text and static landowner. Equivalent to the C-of Objective drawTextInRect: and drawPlaceholderInRect: .

. , , , - , , iOS .

, -.

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));
    }
}
+1

UITextField textAlignment. docs: " , -. - UITextAlignmentLeft".

, :

textfield.textAlignment = UITextAlignmentLeft

, , UITextAlignmentCenter UITextAlignmentRight =.

0

, Y Size, CGRectMake, . , ?

0

All Articles