首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

将一个按钮置于navigationBar中

将一个按钮置于navigationBar中,可以使用以下方法:

  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制
let button = UIButton(type: .system)
button.setTitle("按钮", for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = barButton
  1. 在navigationBar中添加一个按钮,可以使用以下代码:
代码语言:swift
复制

let button = UIButton(type: .system)

button.setTitle("按钮", for: .normal)

button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)

button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

let barButton = UIBarButtonItem(customView: button)

navigationItem.rightBarButtonItem = barButton

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券