在UINavigation上添加UISearchBar的方法

代码如下:

 

 1 // 创建UIView
 2     UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, 250, 54)];
 3     [self.view addSubview:view];
 4     // 创建搜索栏
 5     UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 10, 250, 30)];
 6     /**
 7      *  setTranslucent如果设置成no,则状态栏及导航样不为透明的,界面上的组件就是紧挨着导航栏显示了,所以就不需要让第一个组件在y方向偏离44+20的高度了
 8      */
 9     [searchBar setTranslucent:NO];
10     searchBar.placeholder = @"请输入需要查询的商品";
11     [view addSubview:searchBar];
12     // 添加导航栏
13     UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
14     UINavigationItem *item = [[UINavigationItem alloc] init];
15     item.titleView = view;
16     [navigationBar pushNavigationItem:item animated:YES];
17     [self.view addSubview:navigationBar];

 

相关文章:

  • 2021-09-23
  • 2022-01-29
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-10
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-10-18
  • 2022-12-23
相关资源
相似解决方案