Ani*_*das 3 iphone search uisearchbar
我想在iBooks中显示tableview的搜索栏.如何减少搜索栏的宽度以及如何在没有任何背景颜色的情况下显示它.
另外,如何在显示页面时隐藏搜索框.

我可以想到两个选择:
通过继承UITextfield创建自己的
与UISearchbar混在一起,不推荐
您可以通过以下方式访问UISearchbar的子视图:
for (UIView *aSubview in [searchbar subviews]) {
// this will remove the toolbar around the searchbar in iOS 4
if ([aSubview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[aSubview removeFromSuperview];
}
// get a grip on the underlying textfield...
if ([aSubview isKindOfClass:NSClassFromString(@"UISearchBarTextField")])
{
UITextField *aTextfield = (UITextField *)aSubview;
// this won't do anything at it is already none, just experimenting
aTextfield.borderStyle = UITextBorderStyleNone;
// this will remove the whole border as it is a custom background
aTextfield.background = nil;
// this will remove the magnifying glass
aTextfield.leftView = nil;
// play around even more :)
}
}
Run Code Online (Sandbox Code Playgroud)
您可以隐藏搜索栏