如何在 iBooks 上搜索桌面 UI

发布于 2024-11-05 11:06:24 字数 169 浏览 1 评论 0原文

我想像 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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坚持沉默 2024-11-12 11:06:24

我可以想到两个选项:

通过子类化 UITextfield 创建自己的

  • 将边框样式设置为 UITextBorderStyleNone
  • 将 leftView 设置为放大镜图像
  • 将背景设置为透明 png,仅显示圆形边框
  • 如果uiimagesstretchableImageWithLeftCapWidth:topCapHeight 方法,这样背景图像在拉伸时看起来会很漂亮

与 UISearchbar 混在一起,不推荐

您可以访问 a 的子视图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 :)
    }       
}

隐藏搜索栏

  • 您可以通过将隐藏属性设置为 YES 来
  • 将框架或中心属性设置为可见区域之外的某个位置
  • 将 alpha 属性设置为 0.0
  • 仅在需要时将搜索栏添加到视图中

I can think of two options:

Create your own by subclassing UITextfield

  • 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

Mess around with UISearchbar, not recommended

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

You can hide the searchbar by

  • 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文