NSTextField - 插入虚线

时间:2010-11-02 20:07:50

标签: cocoa nstextfield

我需要在NSTextField中每5个字符插入一个短划线。如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

我通过继承NSTextField来解决这个问题:

-(void)textDidChange:(NSNotification *)notification
{
    NSString*value = [self stringValue];

    NSInteger integer = [[[self stringValue] stringByReplacingOccurrencesOfString:@"-" withString:@""] length];

    if (integer % 5 == 0)
    {
        value = [value stringByAppendingString:@"-"];
        [self setStringValue:value];
    }
}