我意识到会有这样的评论是重复的:
更改 TableView 上 UISearchBars 的宽度
我认为不是。为什么我无法更改情节提要中的宽度?
我可以在宽度字段中写入任何值,但只要我按下返回/输入键值 320 就会恢复。
我也尝试过在视图中执行加载方法:
searchBar.frame = CGRectMake(0, 0, 222, 45);
再次零成功,有谁知道如何做到这一点?我有一个索引表,右侧的字母与搜索文本字段重叠,看起来非常难看。
更新
简而言之,这就是我想要的(概念上):
这是我设法制作的:
再次让我重申“我正在尝试调整搜索栏的大小,以便字母不会重叠”的问题。
我已经尝试过 taus-iDeveloper 的建议,它确实调整了大小,但表格单元格/部分与其重叠。
也试过这个:
我设法在情节提要中调整它的大小,但是当应用程序运行时,大小没有改变。
我完全不知道下一步该尝试什么..
更新 2
我接受了答案,因为它有一些解决方案的要素,我得出结论,仅以编程方式使用情节提要无法做到这一点,解决方案:
//Add the search bar uiview wrapper
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.frame.size.width, 44.0)];
//Add the search bar and navigation item to fill in the remaining space
UINavigationBar *remainingSearchSpace = [[UINavigationBar alloc] initWithFrame:CGRectMake(290, 0.0, (self.tableView.frame.size.width-290), 44.0)];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 290, 44.0)];
searchBar.delegate = self;
[searchBarView addSubview:searchBar];
[searchBarView addSubview:remainingSearchSpace];
self.tableView.tableHeaderView = searchBarView;