[英]Is it possible to change the vertical position of cancel button in the search bar?
当我将应用程序从 10 更新到 11 iOS SDK 时,我将搜索栏从UIView
到UIViewController
navigationItem
。 此外,我设置在UISearchBar
以垂直偏移定位背景图像,因为徽标和 searchBar 之间的距离很小。
searchBar.setSearchFieldBackgroundImage(searchFieldImage, for: .normal)
searchBar.searchFieldBackgroundPositionAdjustment = UIOffset(horizontal: 0, vertical: 4)
但我不能将取消按钮定位在垂直位置。 如何设置UISearchBar
的 Cancel 按钮或按钮中的标题的垂直位置?
访问取消按钮如下:-
UIBarButtonItem *cancelButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
现在尝试更新cancelButton
的框架(y 轴)。
let cancelButton = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self])
let offset = UIOffset(horizontal: 0, vertical: 7)
cancelButton.setTitlePositionAdjustment(offset, for: .default)
也看看这里的苹果文档。
您可以增加 searchBar Height heightAnchor.constraint
以增加导航栏高度以修复图像标志问题,请检查它
在 IOS 11
searchController.searchBar.heightAnchor.constraint(equalToConstant: 50).isActive = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.