Pixate / pixate-freestyle-ios

Pixate Freestyle for iOS
Apache License 2.0
849 stars 134 forks source link

UITextField attributedText letter-spacing styling issue #123

Open PaulTaykalo opened 10 years ago

PaulTaykalo commented 10 years ago

So here's usecase:

.login-textfield attributed-text {
   letter-spacing: 10%;
}

.login-textfield placeholder {
   letter-spacing: 10%;
}

In the code, we setup this field like

self.field.styleClass = @"login-textfield";
self.filed.placeholder = @"some placeholder"

With this setup, I will correctly see the placeholder with correct letter spacing.

Once I start typing, I will se the font without letter spacing :( so "attributed-text" style will not be applied, until I finish editing textField.

P.S. I've tried to check how things are done in this project :) And I have local commit that siply recalculattes cache based on the characters abount for this two styleables. But I'm sure that you can provide better solution.

        if ([[styleable pxStyleElementName] isEqualToString:@"attributed-text"] && [[styleable pxStyleParent] isKindOfClass:[UITextField class]]) {
            UITextField * textField = (UITextField *)[styleable pxStyleParent];
            NSUInteger additionalHash = textField.attributedText.length == 0 && textField.text.length == 0 ? 1 : 0;
            activeDeclarationsHash += additionalHash;
        }