ios 添加导航栏视图

In this tutorial, we’ll be discussing the UIProgressView component and create a progress bar in our iOS Application.

在本教程中,我们将讨论UIProgressView组件,并在iOS应用程序中创建进度条。

iOS进度栏– UIProgressView (iOS Progress Bar – UIProgressView)

ProgressView is used to display the progress of any long running activity such as downloading/uploading/waiting for a response from web service to the user. This is a vital UI element which when absent could give the users an impression that the application is not responding.

ProgressView用于显示任何长时间运行的活动的进度,例如下载/上传/等待Web服务对用户的响应。 这是至关重要的UI元素,如果缺少该元素,可能会给用户留下应用程序没有响应的印象。

Launch XCode Single View iOS Application. Let’s add the UIProgressView in our Main.storyboard

启动XCode Single View iOS应用程序。 让我们在Main.storyboard中添加UIProgressView

ProgressView can have a value between 0.0 and 1.0 and would be indicated by the blue color.
Values outside this interval would be rounded off to either of them depending on whether it’s greater than 1.0 or less than 0.0.

ProgressView的值可以在0.0到1.0之间,并且将由蓝色表示。
超出此时间间隔的值将四舍五入为其中一个,具体取决于它是大于1.0还是小于0.0。

iOS进度视图属性 (iOS Progress View Properties)

ProgressView has the following properties:

ProgressView具有以下属性:

  • progressTintColor – Used to change the UIColor of the progress part i.e. the filled part in the ProgressView.progressTintColor –用于更改进度部分的UIColor,即ProgressView中的填充部分。
  • trackTintColor – Used to change the UIColor of the track i.e. the unfilled part of the ProgressView.trackTintColor –用于更改轨道的UIColor,即ProgressView的未填充部分。
  • ProgressBarStyle – There are two styles: default and bar. The bar style has a transparent track.ProgressBarStyle –有两种样式:默认样式和条形样式。 条形样式具有透明的轨道。
  • trackImage – Here an image is used instead of color for the unfilled part.trackImage –在这里,未填充的部分使用图像代替颜色。
  • progressImage – Image is used to show the progress.progressImage –图像用于显示进度。

Let’s begin our implementation. Our Main.storyboard contains a button to start/stop the ProgressView.

让我们开始执行。 我们的Main.storyboard包含一个用于启动/停止ProgressView的按钮。

The code for the ViewController.swift class is given below:

下面给出了ViewController.swift类的代码:

import UIKitclass ViewController: UIViewController {@IBOutlet weak var btn: UIButton!var isRed = falsevar progressBarTimer: Timer!var isRunning = false@IBAction func btnStart(_ sender: Any) {if(isRunning){progressBarTimer.invalidate()btn.setTitle("Start", for: .normal)}else{btn.setTitle("Stop", for: .normal)progressView.progress = 0.0self.progressBarTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(ViewController.updateProgressView), userInfo: nil, repeats: true)if(isRed){progressView.progressTintColor = UIColor.blueprogressView.progressViewStyle = .default}else{progressView.progressTintColor = UIColor.redprogressView.progressViewStyle = .bar}isRed = !isRed}isRunning = !isRunning}@IBOutlet weak var progressView: UIProgressView!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.progressView.progress = 0.0}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}@objc func updateProgressView(){progressView.progress += 0.1progressView.setProgress(progressView.progress, animated: true)if(progressView.progress == 1.0){progressBarTimer.invalidate()isRunning = falsebtn.setTitle("Start", for: .normal)}}
}

IBOutlet and IBActions are created by linking the Main.storyboard views to the Swift file.

通过将Main.storyboard视图链接到Swift文件来创建IBOutlet和IBAction。

We start a Timer when the Button is clicked which updates the progress bar through the selector function passed: updateProgressView.

当单击按钮时,我们启动一个Timer,它通过传递的选择器函数updateProgressView更新进度条。

Every alternate timer would toggle the style of the ProgressView.

每个备用计时器都将切换ProgressView的样式。

The output of the above application when run on the simulator is given below:

在模拟器上运行时,上述应用程序的输出如下:

增加ProgressView的高度 (Increasing the Height of the ProgressView)

We can change the height of the ProgressView in the following way:

我们可以通过以下方式更改ProgressView的高度:

progressView.transform = progressView.transform.scaledBy(x: 1, y: 8)

This transforms the height by 8 times. Let’s see how it looks in the simulator.

这会将高度转换8倍。 让我们看看它在模拟器中的外观。

You can also change the height from the storyboard in the constraints:

您还可以在约束中从情节提要中更改高度:

The second approach is better since the first one might pixelate the ProgressView if we try to shape the edges.

第二种方法更好,因为如果尝试对边缘进行整形,则第一种方法可能将ProgressView像素化。

圆角ProgressBar (Rounded Corners ProgressBar)

Add the following code in the viewDidLoad() function.

在viewDidLoad()函数中添加以下代码。

override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.progressView.progress = 0.0progressView.layer.cornerRadius = 10progressView.clipsToBounds = trueprogressView.layer.sublayers![1].cornerRadius = 10progressView.subviews[1].clipsToBounds = true}

We set the corner radius to half of the height of the ProgressView. Following is the output of the application with the updated code.

我们将拐角半径设置为ProgressView高度的一半。 以下是带有更新代码的应用程序的输出。

This brings an end to this tutorial. You can download the project from the link below:

本教程到此结束。 您可以从下面的链接下载项目:

iOSProgressViewiOSProgressView

翻译自: https://www.journaldev.com/22011/ios-progress-bar-progress-view

ios 添加导航栏视图

ios 添加导航栏视图_iOS进度栏(进度视图)相关推荐

  1. iOS 添加导航栏两侧按钮

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"首页" style ...

  2. ios添加全局悬浮按钮_iOS开发悬浮按钮

    释放双眼,带上耳机,听听看~! #import "ViewController.h"@interface ViewController ()@property (weak, non ...

  3. IOS设置导航栏返回按钮,并添加事件返回主页面

    IOS设置导航栏返回按钮,并添加事件返回主页面 前提是已经push了一个viewController了.才能使用. XXXTableViewController 里面书写 - (void)viewDi ...

  4. 导航栏透明度渐变; 下拉头视图拉伸效果;勾号动画; 一段文字中点击部分可响应不同事件...

    之前通过设置navigationBar的barTintColor设置导航栏颜色,然后拿到self.navigationController.navigationBar.subviews.firstOb ...

  5. iOS 解决导航栏pop返回时出现黑块问题!

    iOS 解决导航栏pop返回时出现黑块问题! 问题描述: 导航栏正常从A页面push到B页面,从B页面pop返回A页面时遇到过渡过程中导航栏出现黑块的问题. 如截图所示: 问题原因: A界面导航栏被影 ...

  6. IOS设置导航栏的背景图片和文字

    IOS设置导航栏的背景图片和文字 - (void)viewDidLoad {[super viewDidLoad];[self.navigationBar setBackgroundImage:[UI ...

  7. php主题怎么增加导航页,教你如何给wordpress主题添加导航栏

    烈火建站学院转载 不是所有的wordpress主题都自带导航栏的,我早就想自行添加一个.昨天的标题前有"GOOGLE是个好老师"这个句子,今早赶紧删了,倒不是不认同,而是觉得在添加 ...

  8. php添加导航,wordpress网站导航栏如何添加导航菜单栏

    一个网站,一般都会有自己的导航菜单栏,这样方便用户分类查找.那么,在使用wordpress建站时,导航菜单一般都是能直接在后台设置的,也不需要其他插件或动作.现在我就以个人经验教大家wordpress ...

  9. ios底部栏设计规范_IOS设计尺寸规范

    导航栏(Navigation Bar) 导航栏包含了可以导航整个应用.管理当前界面内容的控件.它一般都存在于屏幕的顶部,状态栏的下方. 在默认情况下,导航栏是半透明的,并且会把被导航栏遮住的页面内容进 ...

最新文章

  1. meanpool maxpool 前向和反向传播
  2. 命令点无效怎么处理_怎么更好处理闲置包包,买包卖包都要记住这5点
  3. 漫谈单点登录(SSO)(淘宝天猫)(转载)
  4. Sublime 插件安装、卸载、更新
  5. Mybatis的查询、关联查询
  6. 丰田汽车顶级供应商 Denso 疑遭勒索攻击,被威胁泄露商业机密
  7. 数学之路(3)-机器学习(3)-机器学习算法-欧氏距离(3)
  8. 人体肌肉怎么画?怎样才能画好人体肌肉?
  9. 神经网络机器翻译的实现
  10. 【Photoshop 教程系列第 3 篇】如何在 PS 中修改图片的分辨率和大小(一步一步详细说明)
  11. VS2019项目自动包含bin或obj文件夹的问题
  12. 基于C++和QT实现的第三人称RPG游戏编辑器设计
  13. 归一化MinMaxScaler()、标准化StandardScaler()(特征工程之特征预处理)
  14. 国外推荐:计算机专业人士必读
  15. python比较运算符中大于等于且小于等于的表达方式
  16. labview调用外部仪器设备案例一(标签打印机)
  17. android apk的md5值,android 获取apk md5值
  18. Android反编译、签名、重打包、zipalign一条龙
  19. 计算机硬件有哪些升级空间等级查询,你的电脑要不要升级内存?怎么升级?答案都在这里~...
  20. 【读书笔记】《曾国藩的正面与侧面(一)》

热门文章

  1. HTML5 meta最全使用手册
  2. 静态/动态注冊广播的差别
  3. 程序设计基础(C语言)教学案例-序言
  4. [转载] Python3接口自动化框架:第三方openpyxl库读取excel之命名元组namedtuple承载数据
  5. Eclipse下创建Spring MVC web程序--非maven版
  6. HTML5学习笔记(二十六):JavaScript的错误处理
  7. dokcer 容器启动报错
  8. android开发学习笔记系列(6)--代码规范
  9. [Leetcode][JAVA] Populating Next Right Pointers in Each Node II
  10. java 同步块(Java Synchronized Blocks)