码迷,mamicode.com
首页 > 其他好文 > 详细

在UINavigation上添加UISearchBar

时间:2015-08-20 14:38:33      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

在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];

 

在UINavigation上添加UISearchBar

标签:

原文地址:http://www.cnblogs.com/aggie/p/4744749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!