UISearchBar在uinavigationbar上显示-ios7

来源:互联网 发布:淘宝可以同城交易吗 编辑:程序博客网 时间:2024/05/21 17:29

1,malloc searchbar,and add it to navbar

    mSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0,  SearchBar_W, SearchBar_H)];
    [self setSearchBarBgColor];
    mSearchBar.delegate = self;
    mSearchBar.placeholder = @"搜索";
    self.navigationItem.titleView  = mSearchBar;
    [mSearchBar release];


2, add fun ->setSearchBarBgColor

mSearchBar.backgroundColor = [UIColor clearColor];
    if (IOS7)
    {
        if ([[mSearchBar subviews] count] > 0)
        {
            UIView * thesuperview = [[mSearchBar subviews] objectAtIndex:0];
            NSArray *viewSubvies = [thesuperview subviews];
            for (UIView *_theview in viewSubvies)
            {
                if ([_theview isKindOfClass:[UITextField class]])
                {
                    
                }
                if ([_theview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
                {
                    [_theview removeFromSuperview];//去掉背景,否searchbar则会闪一下灰色背景
                }
            }
        }
        mSearchBar.tintColor = [UIColor myColor];//光标颜色
    }

0 0