iOS基础——UI控件之UIAlertController、UINavigationController、Segue、SVProgressHUD
iOS基础——UI控件之UIAlertController、UINavigationController、Segue
一、UIAlertController
1、普通对话框
-(void)update{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"版本更新" message:@"发现新版本 v2.0.1" preferredStyle: UIAlertControllerStyleAlert];//1、创建按钮UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定更新" style:UIAlertActionStyleDefault handler:nil];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"残忍拒绝" style:UIAlertActionStyleDestructive handler:nil];//2、添加按钮[alert addAction:sure];[alert addAction:cancel];[self presentViewController:alert animated:YES completion:nil];
}
2、文本对话框
-(void)password{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"修改密码" message:@"输入旧密码" preferredStyle: UIAlertControllerStyleAlert];//添加文本框[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {textField.placeholder = @"请输入旧密码";textField.secureTextEntry = YES;}];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"下一步" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {//获取文本框内容self.oldPassword = alert.textFields[0].text;}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消修改" style:UIAlertActionStyleDestructive handler:nil];[alert addAction:sure];[alert addAction:cancel];[self presentViewController:alert animated:YES completion:nil];
}
文本框也可以增加多个,不过由于样子实在是太丑了,并没有使用,可以改成弹出一个再弹出另一个方式解决
3、Sheet对话框
底部弹窗只是把弹出的style设置为sheet即可,其他跟普通对话框是一样的
-(void)loginOut{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出登录" message:@"确定要退出登录吗" preferredStyle: UIAlertControllerStyleActionSheet];UIAlertAction *out = [UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {//退出到根界面[self.navigationController popToRootViewControllerAnimated:YES];}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];[alert addAction:out];[alert addAction:cancel];[self presentViewController:alert animated:YES completion:nil];
}
二、UINavigationController
1、UINavigationController的介绍
UINavigationController是导航控制器,默认会有一个标题栏,也可以通过连接两个ViewController实现界面的来回切换
2、UINavigationController的创建
可以在storyboard中拖拽控件到界面中,或者点击某个ViewController,在菜单栏中点击Editor->Embed In->Navigation Controller来升级你的ViewController
3、UINavigationController标题栏
在导航控制器标题栏可以设置其标题、按钮,可通过Navigation Item创建标题栏,接着可以通过拖动Bar Button Item到标题栏上
Bar Button Item可用文字或者图片,一般使用系统默认带有的图片
4、UINavigationController切换效果
通过control按住控件拖拽到ViewController,选择show跳转模式,即可将UINavigationController连接到下一个ViewController
如果选择Present Modally模式,可以通过点击连线中的Transition属性设置其跳转的效果,不过这样的跳转不会有标题栏
三、Segue
Segue指的是两个ViewController跳转时候的连接,也可以理解为连接两个界面的那条线,可以通过Segue获取跳转时候的两个界面,以便于两个界面的数据传递
1、Segue属性
- identifier:Segue的id
- sourceViewController:连接Segue的源界面
- destinationViewController:连接Segue的目标界面
2、Segue传值
在两个界面跳转时,会回调prepareForSegue方法,可以通过该方法拿到ViewController进行数据传递
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{//拿到目标界面UIViewController *targetVC = segue.destinationViewController;//当一个界面跳转多界面时需要判断目标界面是否为我们要操作的界面if([targetVC isKindOfClass:[TC_BluetoothSearch class]]){//强转TC_BluetoothSearch *searchVC = (id)targetVC;//数据传递searchVC.managerArray = self.dataArray;}
}
3、Segue跳转界面
Segue跳转界面有两种方式
- 自动型:通过控件拖拽到另一个界面,使用show方式跳转
- 手动型:在Segue的identifier属性进行跳转
手动型需要代码实现需要拖拽ViewController黄色箱子拖拽到另一个界面,点击Segue进行identifier设置
通过代码进行跳转
//跳转到页面
[self performSegueWithIdentifier:@"go2main" sender:nil];
四、SVProgressHUD
SVProgressHUD是一个开源的第三方库,其内容是一个进度条弹窗,在应用中加上这些温馨提示的对话框很大的提升我们应用的用户体验
SVProgressHUD:https://github.com/SVProgressHUD/SVProgressHUD
1、SVProgressHUD的使用
[SVProgressHUD showWithStatus:@"正在登录"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//模拟网络操作[NSThread sleepForTimeInterval:2];[SVProgressHUD showSuccessWithStatus:@"登录成功"];dispatch_async(dispatch_get_main_queue(), ^{[SVProgressHUD dismissWithDelay:1];});
});
2、SVProgressHUD的常用API
- showWithStatus:正在加载的弹窗
- showSuccessWithStatus:加载成功的弹窗
- showErrorWithStatus:加载失败的弹窗
- dismiss:弹窗消失
- dismissWithDelay:弹窗延时消失
iOS基础——UI控件之UIAlertController、UINavigationController、Segue、SVProgressHUD相关推荐
- IOS 常用UI控件
目录 下拉刷新 模糊效果 AutoLayout 富文本 图表 表相关与Tabbar 隐藏与显示 HUD与Toast 对话框 其他UI 具体内容 下拉刷新 EGOTableViewPullRefresh ...
- sketch里的ios控件_30个让你眼前一亮的iOS Swift UI控件!
前言 笔者接触 iOS 开发有一段时间了,尤其特别喜欢UI部分,特意收集整理了30个让你惊艳的第三方开源控件(swift),无论是应用到项目中还是用来学习都能让你大呼过瘾,废话不多说,直接上图上链接! ...
- iOS 使用UI控件的外观协议UIAppearance进行设置默认UI控件样式
在iOS开发中,经常会对UINavigationBar的样式进行全局样式.采用的设置方式有两种: 第一种,采用方式如下: [UINavigationBar appearance] 这种是对一类对象的默 ...
- 封装iOS原生UI 控件给RN调用
封装原生UI控件给RN调用 前言 前些日子在做项目的时候,接到一个需求:在APP上,点击一个Cell,跳转到拍照页面进行拍照.按理来说,这个需求实现起来,并不困难,第一想法是想直接用 UIImageP ...
- android基础ui控件,Android基础——基础UI控件
日历,时钟,计时器 package com.example.mybaseuii; import androidx.appcompat.app.AppCompatActivity; import and ...
- iOS基本UI控件总结
包括以下几类: //继承自NSObject:(暂列为控件) UIColor *_color; //颜色 UIImage *_image; //图像 //继承自UIView:只能相应手势UI ...
- IOS开发UI控件UIScrollView和Delegate的使用
1. 什么是UIScrollView 移动设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限 当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内容 普通的UIVie ...
- iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度
转自: http://www.cnblogs.com/cocoajin/p/3494290.html 简介: 使用 iOS 系统 UIImagePickerController 获取视频大小 获取视频 ...
- 黑马程序员——IOS学习—基本UI控件的代码创建
-----------Java培训.Android培训.IOS培训..Net培训.期待与您交流!------------ 本节采用代码的方式系统了解一下IOS主要UI控件的创建和使用,在开始之前首先 ...
最新文章
- spark指定python版本_如何将正常的Python应用程序正确转换为PySpark版本
- Pytorch转TensorRT范例代码
- hibernate、struts、spring mvc的作用
- java学习笔记(3)——面向对象
- SAP托管在Github上的ABAP编程规范
- 分析以太网帧结构_传统以太网中的——中继器及集线器
- 700. 二叉搜索树中的搜索
- n位数的全排列(需要考虑大数的情况)
- Linux Shell脚本_关闭防火墙
- springboot + vue项目跨域请求解决方案
- trados 2007 2009 共用一个LICENSE服务器
- 游戏云平台怎么开发_百度“云手机”与咪咕快游共建国内最大云游戏平台
- uni-app实现android,ios打包过程详解
- 提高电商ROI的方法有哪些?
- C/S架构的优点和缺点
- Illegal string offset错误
- QCC3040/QCC3046 ANC(主动降噪)调测
- 计算机病毒在我国的发展情况,计算机病毒检测技术的现状与发展
- 报错解决Error parsing Mapper XML
- Philo和潘多拉提供了一个打折的,但暂时的,3个月的电视和音乐捆绑