我需要在NSTextField中每5个字符插入一个短划线。如何实现这一目标?
答案 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];
}
}