[英]How to iBooks like search UI on table
我想在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 :)
}
}
您可以隱藏搜索欄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.