我想在iBooks中显示tableview的搜索栏。如何减少搜索栏的宽度以及如何在没有任何背景颜色的情况下显示它。
另外,如何在显示页面时隐藏搜索框。
答案 0 :(得分:6)
我可以想到两个选择:
通过继承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 :)
}
}
您可以通过
隐藏搜索栏