Search code examples
parse-platformnsattributedstring

changing placeholder text in parse loginviewcontroller


So I'd like to change the username placeholder in the Parse LoginView controller, but the text is showing up as fuzzy - how do either set the right shadows/highlights ... or just change the text without changing the style attributes.

https://parse.com/tutorials/login-and-signup-views

Both of these below create the fuzzy gray text without the right shadow/highlights

logInViewController.logInView.usernameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Phone" attributes:@{}];

logInViewController.logInView.usernameField.placeholder = @"phone";

Solution

  • I don't know which effect you want to apply (there are a few example/screenshot on your link).
    But here what you could do or set up as you want (and apply the value you want):

    NSAttributedString *originalUserNamePlaceHolder = logInViewController.logInView.usernameField.attributedPlaceholder;
    
    NSShadow *shadow = [[NSShadow alloc] init];
    [shadow setShadowBlurRadius:2.0];
    [shadow setShadowColor:[UIColor grayColor]];
    [shadow setShadowOffset:CGSizeMake(0, 2.0)];
        
    NSDictionary *attributesCustom = @{NSShadowAttributeName: shadow, NSForegroundColorAttributeName:theUIColorYouWant};
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"customText" attributes: attributesCustom];
    logInViewController.logInView.usernameField.attributedPlaceholder = attrString;
    

    Note that customText could be [originalUserNamePlaceHolder string];

    You can read more about the various effect you wan apply here.

    Now, you could do this to retrieve the setting you want to mimic (because you like it), retrieving its specific settings:

    __block NSDictionary *attributesRetrieved;
    [attrString enumerateAttributesInRange:NSMakeRange(0, [attrString length]) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop)
    {
        NSLog(@"Attrs: %@", attrs);
        attributesRetrieved = [attrs copy];
    }];
    

    There should be only one attribute (for the whole text). For example, on the one I set: You got:

    attributesRetrieved: {
    NSColor = "UIDeviceWhiteColorSpace 1 1";
    NSShadow = "NSShadow {0, 2} blur = 2 color = {UIDeviceWhiteColorSpace 0.5 1}";
    } So you can retrieve the previous setting I put before.