开发者

Change the Width of UISearchBars on a TableView

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).

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.a开发者_StackOverflow中文版utocorrectionType = UITextAutocorrectionTypeNo;


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜