• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UISearchController UISearchBar 背景

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:21:56 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

当给 UITableView 头部 View 添加 UISearchController 时,不可能在 UISearchBar 后面设置背景。

第二张图是拖到底部时的 View 。

Normal Dragging

UITableView 在 Storyboard 中设置,没有任何标题。

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

// Setup appearance
self.searchController.searchBar.barStyle = UIBarStyleBlack;
self.searchController.searchBar.barTintColor = BLUE;
self.searchController.searchBar.tintColor = RED;

// Setup logic
self.searchController.searchBar.scopeButtonTitles = @[ NSLocalizedString(@"students", nil), NSLocalizedString(@"professors", nil), NSLocalizedString(@"rooms", nil) ];
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;

self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;

我尝试将背景添加到 Storyboard 、 super View 、UITableView 以及手动添加到 UISearchBar。

更多代码可用here .



Best Answer-推荐答案


你可以试试这个:

UIView* topview = [[UIView alloc] initWithFrame:CGRectMake(0, -480, self.view.frame.size.width, 480)];
topview.backgroundColor = BLUE;

[self.tableView addSubview:topview];

我已经用 UITableViewController 进行了测试,它工作正常。

灵感来自 this answer

关于ios - UISearchController UISearchBar 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28714620/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap