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

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

相关·内容

iOS开发UINavigation系列一——导航栏UINavigtionBar

iOS开发UINavigation系列一——导航栏UINavigtionBar 一、导航栏的使用         在iOS开发,我们通常会使用导航控制器,导航控制器中封装了一个UINavigationBar...@property(nullable, nonatomic,strong) UIColor *barTintColor; BarTintColor用于设置导航栏的背景色,这个属性被设置后,半透明的效果失效...,导航栏左侧pop按钮的图案默认是一个箭头,我们可以使用下面的方法修改: @property(nullable,nonatomic,strong) UIImage *backIndicatorImage...操作         UINavigationBar上面不只是简单的显示标题,它也标题进行了堆栈的管理,每一个标题抽象为的对象在iOS系统是UINavigationItem对象,我们可以通过push...//向栈添加一个item,上一个item会被推向导航栏的左侧,变为pop按钮,会有一个动画效果 - (void)pushNavigationItem:(UINavigationItem *)item

94331

UINavigationBar的用法

UINavigationBar是一个我们在开发必定会碰到的控件,用好它能帮助我们自定义导航栏的样式,所以今天讲解一下UINavigationBar的用法。...设置导航栏的标题 这个直接是很简单的设置,一行代码搞定 self.navigationItem.title = @"导航栏标题"; 设置导航栏背景颜色 导航栏的背景颜色,也是很简单的 自己替换代码的颜色即可...,黑色颜色,用于亮色背景,一个是白色用于深色背景 设置返回按钮 有时候我们会发现,我们设置的返回按钮都是蓝色的默认颜色,那么到底该怎么更改这些按钮的颜色呢 设置返回按钮的颜色,只设置tintColor的颜色就好了...self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 只设置返回按钮的图片 - (void)goToBack...如果你对返回按钮实在不满意,你可以自定义一个按钮,并把它设置为navigation的leftButton - (void)setCustomLeftButton { UIView* leftButtonView

1.9K20

TSMessages,非HUD风格的iOS提示框(附官方demo BUG修复方案)

用起来也很方便 导入 pod导入相对很简单,主要讲怎么手动导入这个库 下载(https://github.com/KrauseFx/TSMessages),这个文件管理的不好,用到的东西比较分散,首先,TSMessages-master.../Pod/Classes下所有文件拖到工程里,然后TSMessages-master/Example/Pods/HexColors/Classes的两个文件导入 引用头文件#import "TSMessageView.h...的话紧挨着它),遮挡NavigationBar(实际测试并不好用),底部 TSMessageNotificationDuration:提示消失方式,包含 TSMessageNotificationDurationAutomatic...appearance]setWarningIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];//自定义警告图片 官方demo修改成遮挡NavigationBar...样式效果也不好,提示信息被NAvigationBar遮挡,但demo上有一个很好的处理思路,先把NavigationBar隐藏,待提示消失后再展示出来 修改方法 首先你的样式应该是 TSMessageNotificationPositionNavBarOverlay

97150

UIImagePickerController的中文界面和改变statusBar的颜色

用户选择头像功能是最常见的调用相机相册场景,调用系统的方法会存在两个问题:1.除了UIImagePickerController的拍照页面,UISearchBar的取消按钮,键盘上的返回、完成等按钮,以及其他系统界面带有英文的...在info.plist添加Localized resources can be mixed value值为YES 如下图: ?...UIImagePickerControllerDelegate> @property(strong,nonatomic)UIImagePickerController*pickerViewController; @end 在点击选择头像按钮代码...self.pickerViewController.navigationBar.barTintColor = [UIColor colorWithRed:20.f/255.0 green:24.0/255.0...setTitleTextAttributes:attrs]; 改变状态栏的颜色方法为: 方法1: 声明一个类继承UIImagePickerController #import <UIKit/UIKit.h

1.8K40

IOS开发之TabBarItem&NavigationBarItem

下面将会结合一个实际的效果来简单的介绍一下TabBar和NavigationBar, 然后说一下用我们的storyboard和纯代码如何配置我们的NavigationBar, 上一篇博客中提到了如何用Navigation...视图关系说明:     1.当打开时首先会出现一个登陆页面,当登陆成功后会跳转到Tab Bar Controller。     ...接下来会为每个导航控制器配置NavigateBar, 在一个NavigationController只有一个NavigationBar, 而在一个NavigationController下的各个ViewController...我们可以通过storyboard通过拖拽的方式来配置我们的NavigationBar 也可以通过手写代码的方式进行配置:     (1)用storyboard来为我们的Navigation Bar添加按钮...1 //手动添加NavigationBar上得右侧按钮 2 //新建BarButtonItem1, 同时指定样式,和注册回调 3 UIBarButtonItem *item1

1.3K80

React-Native组件之 Navigator和NavigatorIOS

Navigator 与 NavigatorIOS 在移动开发过程,几乎所有的APP或多或少都会涉及到多个界面间的切换,在React Native中有两个组件负责实现这样的效果 —— Navigator...对象参数调用; navigationBar view 导航的可选组件导航标题栏,需要设置左按钮,右按钮和标题属性。...component:Home // 要跳转的板块 }} renderScene={(route, navigator) => { // 板块生成具体的组件...要实现上面的效果,需要三个文件:第一个页面,第二个页面和一个控制跳转的JS。...一个常见的用途是设置所有页面的背景颜色 navigationBarHidden 布尔值,决定导航栏是否隐藏 shadowHidden 布尔值,决定是否要隐藏1像素的阴影 tintColor 导航栏上按钮的颜色

4.4K70

iOS系统中导航栏的转场解决方案与最佳实践

想要成功的自定义返回按钮的图标样式,我们需要同时设置这两个 API ,从字面上来看,它们一个是返回图片本身,另一个是返回图片在转场时用到的 mask 图片,看起来不怎么难,我们写一段代码试试效果: self.navigationController.navigationBar.backIndicatorImage...掌握了原理,我们来解释下刚才的两种现象: 在第一种实现,我们提供的 indicatorTransitionMaskImage 覆盖了整个返回按钮的图标,所以我们在转场过程可以清晰的看到返回按钮的文字...,所以显然返回按钮的文字会在图标的最右边就已经被遮挡住了,因为那片区域是透明的。...系统原有导航栏的背景设置为透明色,同时在每个 ViewController 上添加一个 View 或者 NavigationBar 来充当我们实际看到的导航栏,每个 ViewController 同样只需要关心自身的样式即可...等到页面 B 调用 viewWillLayoutSubviews 的时候,转场库会在页面 B 自身的 view 上添加一个与真的导航栏一模一样的 NavigationBar,同时真的导航栏隐藏。

2.3K30

UI篇-UINavigationController之易忘补充

状态栏隐藏就可实现这样不错的页面效果 PS:  backBarButtonItem的自定义事件是不会被执行的 backItem = [[UIBarButtonItem alloc] initWithTitle...UINavigationItem属于MVC的M,封装了要显示在UiNavigationBar上的数据,定义了UINavigationItem上按钮的触发事件,外观等 -initWithBarButtonSystemItem...每个视图控制器都有一个navigationItem属性,navigationItem设置的做按钮、右按钮、标题等,会随着控制器的显示,也显示到navigationBar上 我们来看一下这些名词是什么意思...,然后包含的navigationbar形成整个nv的导航栏。...NSArray存放的顺序一致,其中每一个数据都一个`UIBarButtonItem`对象,可以使用系统提供的很多常用风格的对象,也可以根据需求进行自定义,`每个UIBarButtonItem可以绑定一个事件

2.1K20

iOS透明导航栏的平滑过渡(进阶版)引实现过程结

而很多App的做法其实比较粗糙,类似于我在传送门:iOS导航栏切换界面时隐藏和显示的做法,需要导航栏透明时,直接导航栏隐藏起来。...直接隐藏起来的意思是,整个导航栏就用不了了,也就是说,标题、返回按钮等都需要自己去做,这是一个比较麻烦的地方,此外,在有无导航栏的界面间切换时,过程是比较生硬的,导航栏不是渐变出现的。...如果说这些都可以接受,那最大的一个问题,也是我在那篇文章里提到的,如果正好处于用UITabbarConatroller切换界面,那么导航栏会有一个往上缩回的快速动画,这其实就很不美观了,当然我们可以通过隐藏导航栏的动画去掉来达到对...,包括返回按钮,因为我没有给导航栏添加任何其他按钮,所以这里一定是返回按钮,下属的 UILabel 就是 “返回” 两个字了。...我们自己创建一个用于交换的方法,这个方法,除了调用原方法外(注意由于方法名称对应的实现已经交换了,这里我们目的是调用原实现,但是使用的名称确实本方法自己的名称),还添加一个处理,_updateInteractiveTransition

2.9K40
领券