【问题标题】:How to add custom/normal button on top of navigation bar?如何在导航栏顶部添加自定义/普通按钮?
【发布时间】:2022-01-14 19:28:23
【问题描述】:

我想在导航栏区域放置一个自定义按钮,但您可以自定义导航栏项目的数量似乎有限制。我想做一个带有圆角方形背景和标题和背景自定义颜色的基本按钮。有没有办法在导航栏顶部放置一个普通按钮来解决缺乏自定义的问题?我还尝试以编程方式更改栏按钮项以具有所需的特征,但没有成功。

【问题讨论】:

  • 尝试使用自定义的 UIButton 作为 UIBarButton 的视图。

标签: swift user-interface uibutton uikit uibarbuttonitem


【解决方案1】:

您可以像这样添加自定义视图:

let customButton = UIButton.init(type: .custom)
// your customization here
    
// assign your custom view to left/right bar button item  
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: customButton)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2011-04-25
    • 2019-08-26
    • 1970-01-01
    相关资源
    最近更新 更多