【问题标题】:Adjust insets of UISearchController's searchBar调整 UISearchController 搜索栏的插图
【发布时间】:2019-05-19 14:15:08
【问题描述】:

我正在尝试一些设计,我希望我的所有子视图都有相同的 25 像素边距。 UISearchControllersearchBar 在开箱即用的两侧都有 16px 的填充。我是否必须从头开始编写搜索栏文本字段,或者是否有任何方法(无证、混合或其他方式)来完成根据我的口味抵消本机栏?

【问题讨论】:

    标签: ios swift uikit uisearchcontroller


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,比我的更干净!我只是使用隐式初始化来避免炸弹这个词。 (searchController.searchBar.directionalLayoutMargins = .init(top: 0.0, leading: 25.0, bottom: 0.0, trailing: 25.0))
    • 从 iOS 13 开始,这又被打破了。谢谢,苹果。
    • 你在 iOS 13 中找到解决方案了吗?
    • 实际上,它在 iOS13 中对我有用(仅使用前导和尾随)。为什么说它坏了?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多