0

Please help truncating the placeholder of a UITextField like it does the UILabel with UILineBreakModeTailTruncation.

I would post some code, but.. there's nothing to post... I don't even know what to start trying.

There's no problem with tail truncation of a label, but the placeholder of the textfield... no idea.

What's the use:

The placeholder has to list some cities:

"Search in Munchen, Stanberg, Frankfurt, Blablabla"

The textfield truncates its placeholder to:

"Search in Munchen, Stanberg, Frankfurt," ( notice the last comma )

I gotta do it like this:

"Search in Munchen, Stanberg, Frankfurt, Bla..."

Even if I somehow delete the "last" comma, I need the rest "Bla...", in order to suggest the user that the list is not finished with Frankfurt.

Any help is appreciated. Thanks in advance.

4

2 回答 2

2

Create custom UITextField subclass and override method - (void)drawPlaceholderInRect:(CGRect)rect

Something like this

- (void) drawPlaceholderInRect:(CGRect)rect
{
    [[UIColor colorWithWhite:0.7 alpha:1.0] setFill];
    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:14] lineBreakMode:NSLineBreakByTruncatingTail];
}
于 2013-05-23T13:50:27.243 回答
-2

There's an attributedPlaceholder property of UITextField that you should be able to modify to have the desired truncation logic.

于 2013-11-26T10:56:33.077 回答