我可以在安全的UITextField中使用自定义图标而不是点吗?

时间:2014-04-18 09:44:21

标签: objective-c ios7.1

iOS7.1用于Secure Text Fields的点比以前的点大,而且非常难看。

我可以使用different icon代替这些标准点吗?如果是这样,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

/* don't ever use this PROOF OF CONCEPT CODE for production use */
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{   
if ( self.backing == nil ) self.backing = @"";
static BOOL pasting = false;

if ( !pasting )
{       
    self.backing = [self.backing stringByReplacingCharactersInRange:range withString:string];
    NSLog(@"backing: %@",self.backing);
    if ( [string length] == 0 ) return YES; // early bail out when just deleting chars

    NSString *sec = @"";
    for ( int i=0;i<[string length]; i++ ) sec = [sec stringByAppendingFormat:@"■"];

    pasting = true;
    [[UIPasteboard generalPasteboard] setString:sec];
    [textField paste:self];

    return NO;  
} else {
    pasting = false;
    return YES; 
}       
}