【问题标题】:Create UIBarButtonItem with fixed size and with custom icon创建具有固定大小和自定义图标的 UIBarButtonItem
【发布时间】:2018-10-17 01:47:55
【问题描述】:

我已经创建了如下图所示的导航栏

“drop”按钮是一个自定义的系统 UIBarButtonItem。它包含在右栏按钮项目中,并且其区域已扩大。

我希望它的大小适合我设置的图像,例如右侧的“撰写”按钮。

【问题讨论】:

  • 你可以把静态放在导航栏里。
  • @Jay 如果我将 I 宽度设置为固定数字,则没有任何变化
  • 这是uitabbarbutton的默认功能。
  • @Jay 请原谅我的无知,你的意思是没有办法,只能使用自定义视图而不是导航栏
  • 您可以使用编程方式添加条形按钮。

标签: ios uibarbuttonitem


【解决方案1】:
public func setCustomButton() {

    let btnSearch: UIButton = UIButton(type: .custom)
    btnSearch.frame = CGRect(x: 0, y: 0, width: 25.0, height: 25.0)
    btnSearch.setImage("Your image", for: .normal)
    btnSearch.addTarget(self, action: #selector(yourActionName(_:)), for: .touchUpInside)
    et btnBarButtonSearch: UIBarButtonItem = UIBarButtonItem(customView: btnSearch)
    navigationItem.rightBarButtonItems = [btnBarButtonSearch]
 }

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多