如何iBooks喜欢在桌子上搜索UI [英] How to iBooks like search UI on table

查看:107
本文介绍了如何iBooks喜欢在桌子上搜索UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iBooks中显示tableview的搜索栏。如何减少搜索栏的宽度以及如何在没有任何背景颜色的情况下显示它。

I want to show the search bar of tableview like that in iBooks. How can i reduce the width of searchbar and how it can be shown without any background color.

此外,如何在显示页面时隐藏搜索框。

Also how can i hide the search box initially when the page is displayed.

推荐答案

我可以想到两个选项:

通过子类创建自己的选项UITextfield


  • 将边框样式设置为UITextBorderStyleNone

  • 将leftView设置为放大镜图片

  • 将背景设置为透明png,只显示圆形边框

  • 如果uiimages stretchableImageWithLeftCapWidth:topCapHeight方法使用,那么背景图片将会伸展时看起来很漂亮

  • set border style to UITextBorderStyleNone
  • set the leftView to a magnifying glass image
  • set the background to a transparent png with only the round border showing
  • make use if the uiimages stretchableImageWithLeftCapWidth:topCapHeight method so the background image will looks nice when stretched

乱用UISearchbar,不推荐

您可以通过以下方式访问UISearchbar的子视图:

You can access the subviews of a UISearchbar in this way:

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

您可以隐藏搜索栏


  • 将隐藏属性设置为YES

  • 将框架或中心属性设置为可见区域之外的某个位置

  • 将alpha属性设置为0.0

  • 仅在需要时将搜索栏添加到视图中

  • setting the hidden property to YES
  • set the frame or center property to somewhere outside the visible area
  • set alpha property to 0.0
  • adding the searchbar to your view only when needed

这篇关于如何iBooks喜欢在桌子上搜索UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆