如何用pixate在搜索栏中设置文本样式?

时间:2014-01-29 21:01:06

标签: css ios7 pixate

我尝试使用pixate在我的应用中设置UISearchBar文本的样式。它只在我解除键盘后工作,但是当我写文本时它不使用我的风格:

我在写:

I'm writting

键盘关闭后:

After the keyboard is closed

这是我目前的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;
        }
    }
}

3 个答案:

答案 0 :(得分:0)

尝试添加highlighted伪类,如下所示:

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

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

答案 1 :(得分:0)

尝试在搜索栏上设置styleId或styleClass,并使用元素名称直接设置样式。例如:

#mySearchBar { ... }

此外,Pixate目前不支持searchFieldBackgroundImageForState属性,但我们会尽快添加,以更正确地设置搜索栏的背景图像。

最后,要设置文本的颜色,现在,这可能是代码中的最佳方式:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

答案 2 :(得分:0)

我终于做到了:

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];
    }
}

我有这种风格干扰:

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

这就是为什么有必要设置PXStylingNone