首页
学习
活动
专区
工具
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

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

相关·内容

3分6秒

如何在Mac版Photoshop中去除图片中的水印?

34秒

PS使用教程:如何在Photoshop中合并可见图层?

1分6秒

PS使用教程:如何在Mac版Photoshop中制作“3D”立体文字?

-

【解密】小米被禁用GMS?真相非你所想

47秒

KeyShot特效

7分5秒

MySQL数据闪回工具reverse_sql

7分20秒

鸿怡电子工程师:芯片测试座在半导体测试行业中的关键角色和先进应用解析

2分23秒

如何从通县进入虚拟世界

793
24分28秒

GitLab CI/CD系列教程(四):.gitlab-ci.yml的常用关键词介绍与使用

9分20秒

查询+缓存 —— 用 Elasticsearch 极速提升您的 RAG 应用性能

12分26秒

AJAX教程-01-全局刷新和局部刷新【动力节点】

10分57秒

AJAX教程-04-ajax概念

领券