簡體   English   中英

如何iBooks喜歡在桌子上搜索UI

[英]How to iBooks like search UI on table

我想在iBooks中顯示tableview的搜索欄。 如何減少搜索欄的寬度以及如何在沒有任何背景顏色的情況下顯示它。

另外,如何在顯示頁面時隱藏搜索框。

在此輸入圖像描述

我可以想到兩個選擇:

通過繼承UITextfield創建自己的

  • 將邊框樣式設置為UITextBorderStyleNone
  • 將leftView設置為放大鏡圖像
  • 將背景設置為透明的png,僅顯示圓形邊框
  • 使用如果uiimages stretchableImageWithLeftCapWidth:topCapHeight方法使得背景圖像在拉伸時看起來很漂亮

與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 :)
    }       
}

您可以隱藏搜索欄

  • 將hidden屬性設置為YES
  • 將框架或中心屬性設置為可見區域之外的某個位置
  • 將alpha屬性設置為0.0
  • 僅在需要時將搜索欄添加到視圖中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM