views:

68

answers:

3

How can I set the label of my UITableViewCell to "SecureText"?

[cell.textLabel setText:@"passwordNotShown"];
A: 

UILabel doesn't have a secure property, you'll have to create a custom cell with a non-editable UITextField with the secure property set.

Tom Irving
A: 

UILabel doesn't have 'secure entry' how about setting masked string as label text?

NSString *secretText = @"sekert";
NSMutableString *masked = [[NSMutableString alloc] init];
for (int i=0; i < [secretText count] ; i++)
    [masked appendString:@"*"];  // 

cell.textLabel.text = masked;
[masked release];
sujee
+1  A: 

You might use a category:

@interface UILabel (SecureText)
@property (nonatomic, retain) NSString *secureText;
@end
@implementation UILabel (SecureText)
- (void)setSecureText:(NSString *)newText {
    NSMutableString *securedMutableText = [NSMutableString new];
    for (int i = 0; i < [newText length]; i++) {
        [securedMutableText appendString:@"*"];
    }
    self.text = securedMutableText;
}
- (NSString *)secureText {
    return self.text;
}
@end

and then use it like this:

[cell.textLabel setSecureText:@"passwordNotShown"];
Michael Kessler
Very clever idea.
Jason Jenkins
Thank you Jason.
Michael Kessler
Thank you! That works fine:-)Is there a way to use the iPhone "bullets" instead of "*"?
jgray
I believe that the bullet is a regular character. You just have to know its value. Try searching the Internet. I've found this: `http://www.fileformat.info/info/unicode/char/2022/index.htm`.
Michael Kessler
If you don't want the user to see the password, why let the user see how many characters it has?
Emil