【问题标题】:Change the Width of UISearchBars on a TableView更改 TableView 上 UISearchBars 的宽度
【发布时间】:2011-09-09 09:02:06
【问题描述】:

我需要在我的 tableView 中创建两个 UISearchBar。我希望它们在桌子顶部的宽度相等(并排)。

我已经为它们创建了两个 UISearchBar 出口,以及属性和 de alloc。我发现很难将它们都放在视图中(我的意思是合适的)。我只有一个搜索栏扩展到屏幕的整个宽度。我如何适合两个?

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;

【问题讨论】:

    标签: iphone objective-c xcode ios tableview


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    相关资源
    最近更新 更多