调整 UISearchController 的 searchBar 的 insets

Adjust insets of UISearchController's searchBar

我正在尝试一些设计,我希望所有子视图的边距均等 25px。 UISearchControllersearchBar 开箱即用,两侧各有 16px 的内边距。我是否必须从头开始编写搜索栏文本字段,或者是否有任何方法(未记录的、调配的或其他方式)来完成抵消原生栏以符合我的口味?

如果您使用的是 UISearchController,您可以像这样设置 searchBar 的边距(假设 searchBarUISearchController 实例):

let directionalMargins = NSDirectionalEdgeInsets(top: 0, leading: 25, bottom: 0, trailing: 25)
searchController.searchBar.directionalLayoutMargins = directionalMargins