在导航栏添加搜索框

来源:互联网 发布:turtlebot编程 编辑:程序博客网 时间:2024/06/08 00:47
 
    //导航条的搜索条
        UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(500.0f,0.0f,250.0f,44.0f)];
        searchBar.delegate = self;
        [searchBar setPlaceholder:@"搜索"];
         
        //将搜索条放在一个UIView上
        UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 44)];
        searchView.backgroundColor = [UIColor clearColor];
        [searchView addSubview:searchBar];
         
        self.navigationItem.titleView = searchView;
      
// 自定义导航栏的背景:
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];   //@{}代表Dictionary   
 [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];


0 0
原创粉丝点击