在TableView上更改UISearchBars的宽度 [英] Change the Width of UISearchBars on a TableView

查看:109
本文介绍了在TableView上更改UISearchBars的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在tableView中创建两个UISearchBars。我希望它们两个宽度相等(在桌面上)(并排)。

I am required to create two UISearchBars in my tableView. I want both of them of equal width on top of the table (side-by-side).

我创建了两个UISearchBar出口,以及属性和de alloc for他们。我发现很难在视图中放置它们(我的意思是合适)。我只有一个搜索栏扩展到屏幕的全宽。我怎么适合两个?

I have created two outlets of UISearchBar, and property and de alloc for them. I am finding it hard to place (I mean fit) both of them in the view. I get only one search bar expanding to the FULL width of the screen. How do I fit two ?

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 4, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(4, 0, 4, 45)];

searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";

searchBar.delegate = self;
zipSearchBar.delegate = self;

self.tableView.tableHeaderView= zipSearchBar;
self.tableView.tableHeaderView= searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;


推荐答案

当您执行<$ c时,您只需重新分配它$ c> self.tableView.tableHeaderView = searchBar; 。您必须构建一个包含搜索栏的视图,然后将其设置为表的标题视图。这样的事情,

You are simply reassigning it when you do self.tableView.tableHeaderView= searchBar;. You will have to build a view that contains both the search bars and then set it to the table's header view. Something like this,

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(200, 0, 120, 45)];

searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";

searchBar.delegate = self;
zipSearchBar.delegate = self;

UIView * comboView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
[comboView addSubview:searchBar];
[comboView addSubview:zipSearchBar];

self.tableView.tableHeaderView= comboView;
[comboView release];

这篇关于在TableView上更改UISearchBars的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆