Question

I have tried to style the UISearchBar text in my app with pixate. It work only after I dismiss the keyboard, but when I'm writing the text it not use my style:

I'm writting:

I

After the keyboard is closed:

After the keyboard is closed

This is my current CSS:

text-field {
    color: black;
    background-color : @colorEditTexto;
    border-radius: 4px;
    border-width: 8px;
    border-color: gray;
    height: 30px;

    placeholder {
        font-style: italic;
        color: darkgray;
    }
}
search-bar {
    background-color: @colorBarra;
    -ios-tint-color: white;
    color: white;

    text-field {
        color: white;
        placeholder {
            color: white;
        }
    }
}
Was it helpful?

Solution 3

I finally do this:

for (UIView* subview in [[self.subviews lastObject] subviews]) {
    if ([subview isKindOfClass:[UITextField class]]) {
        UITextField *textField = (UITextField*)subview;
        textField.styleMode = PXStylingNone;
        [textField setBackgroundColor:[UIColor colorWithHexString:@"#014148"]];
        textField.textColor = [UIColor whiteColor];
    }
}

I have this style interfering:

text-field {
    color: black;
    background-color : @colorEditTexto;
    placeholder {
        font-style: italic;
        color: darkgray;
    }
}

that is why is necessary to set PXStylingNone.

OTHER TIPS

Try adding a highlighted pseudo-class like this:

search-bar {
    background-color: @colorBarra;
    -ios-tint-color: white;
    color: white;

    text-field {
        color: white;
        placeholder {
            color: white;
        }
    }
    text-field:highlighted {
        color: blue;
    }
}

Try setting a styleId or styleClass on your search bar and style it directly versus using the element name. For example:

#mySearchBar { ... }

Also, Pixate doesn't currently support the searchFieldBackgroundImageForState property, but we'll add that soon to more properly set the background image of a Search Bar.

And lastly, to set the color of the text, right now, this is probably the best way, in code:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top