简体   繁体   English

UITextField占位符尾部截断

[英]UITextField placeholder tail truncation

Please help truncating the placeholder of a UITextField like it does the UILabel with UILineBreakModeTailTruncation . 请帮助截断UITextField的占位符,就像使用UILineBreakModeTailTruncation进行UILabel 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 ) "Search in Munchen, Stanberg, Frankfurt," (请注意最后一个逗号)

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. 即使我以某种方式删除了“最后一个”逗号,我也需要其余的“ Bla ...”,以便向用户建议该列表还没有在法兰克福完成。

Any help is appreciated. 任何帮助表示赞赏。 Thanks in advance. 提前致谢。

Create custom UITextField subclass and override method - (void)drawPlaceholderInRect:(CGRect)rect 创建自定义UITextField子类并重写方法- (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];
}

UITextField有一个attributedPlaceholder属性,您应该可以对其进行修改以具有所需的截断逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM