【问题标题】:UISearchBar with a left button带有左键的 UISearchBar
【发布时间】:2013-06-18 14:52:53
【问题描述】:

我正在寻找一个带有左侧按钮的 UiSearchBar。 我一直在阅读 this topic,并按照 KennyTM 描述的步骤进行操作,但没有得到相同的结果。

这是我得到的:

如您所见,我的搜索栏与导航栏的颜色不同。

有没有人可以解决这个问题?

【问题讨论】:

    标签: ios interface-builder uisearchbar


    【解决方案1】:
     for( id view in search.subviews) {
            if([view isKindOfClass:[UIImageView class]]) {
                UIImageView *img = (UIImageView *)view;
                img.image = nil;
            }
        }
    search.backgroundImage = [UIImage imageNamed:@"searchbar.png"];
    

    搜索是UISearchbar的对象

    【讨论】:

    • search.backgroundImage = [UIColor clearColor];一起工作正常
    【解决方案2】:
    / button
    UIBarButtonItem *settingsButtonItem = // create settings button
    
    // search bar
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
    UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
    [searchBar release];
    
    // toolbar is UIToolbar
    [toolbar setItems:[NSArray arrayWithObjects:settingsButtonItem, searchBarButtonItem nil] animated:NO];
    

    请执行上面的代码可能会有很大帮助。

    【讨论】:

    • 很抱歉给您带来不便,但尝试实施您的解决方案(不幸的是,这也导致了这个问题的问题:stackoverflow.com/questions/3482612/…),我一直在撤消修改并获得所需的结果。但感谢您的帮助。
    猜你喜欢
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多