iOS swift5 弹出提示文字(停留1~2s)XHToastSwift
CoderZhuXH/XHToastSwift - github
//
// XHToast.swift
// XHToastSwiftExample
//
// Created by xiaohui on 16/8/12.
// Copyright © 2016年 CoderZhuXH. All rights reserved.
// 代码地址:https://github.com/CoderZhuXH/XHToastSwiftimport UIKit/*** Toast默认停留时间 1.2*/
private let ToastDispalyDuration:CGFloat = 1.2
/*** Toast到顶端/底端默认距离*/
private let ToastSpace:CGFloat = 100.0
/*** Toast背景颜色*/
private let ToastBackgroundColor = UIColor(red:0.2,green:0.2,blue:0.2,alpha:0.75)//在window上显示
extension XHToast
{//MARK:-中间显示/**中间显示- parameter text: 文字*/public class func showCenterWithText(_ text: String) {XHToast.showCenterWithText(text, duration:ToastDispalyDuration)}/**中间显示+自定义时间- parameter text: 文字- parameter duration: 自定义停留时间*/public class func showCenterWithText(_ text:String,duration:CGFloat) {let toast = XHToast(text: text)toast.duration = durationtoast.showIn(UIWindow.window())}// MARK:-上方显示/**上方显示- parameter text: 文字*/public class func showTopWithText(_ text:String) {XHToast.showTopWithText(text, topOffset:ToastSpace, duration:ToastDispalyDuration)}/**上方显示+自定义停留时间- parameter text: 文字- parameter duration: 自定义停留时间*/public class func showTopWithText(_ text:String, duration:CGFloat) {XHToast.showTopWithText(text, topOffset:ToastSpace, duration:duration)}/**上方显示+自定义到顶部距离- parameter text: 文字- parameter topOffset: 自定义到顶部距离*/public class func showTopWithText(_ text:String,topOffset:CGFloat) {XHToast.showTopWithText(text, topOffset:topOffset, duration:ToastDispalyDuration)}/**上方显示+自定义到顶部距离+自定义停留时间- parameter text: 文字- parameter topOffset: 自定义到顶部距离- parameter duration: 自定义停留时间*/public class func showTopWithText(_ text:String, topOffset:CGFloat,duration:CGFloat) {let toast = XHToast(text: text)toast.duration = durationtoast.showIn(UIWindow.window(), topOffset: topOffset)}// MARK:-下方显示/**下方显示- parameter text: 文字*/public class func showBottomWithText(_ text:String) {XHToast.showBottomWithText(text, bottomOffset:ToastSpace, duration:ToastDispalyDuration)}/**下方显示+自定义停留时间- parameter text: 文字- parameter duration: 自定义停留时间*/public class func showBottomWithText(_ text:String,duration:CGFloat) {XHToast.showBottomWithText(text, bottomOffset:ToastSpace, duration:duration)}/**下方显示+自定义到底部距离- parameter text: 文字- parameter bottomOffset: 自定义到底部距离*/public class func showBottomWithText(_ text:String,bottomOffset:CGFloat) {XHToast.showBottomWithText(text, bottomOffset:bottomOffset, duration:ToastDispalyDuration)}/**下方显示+自定义到底部距离+自定义停留时间- parameter text: 文字- parameter bottomOffset: 自定义到底部距离- parameter duration: 自定义停留时间*/public class func showBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat) {let toast: XHToast = XHToast(text: text)toast.duration = durationtoast.showIn(UIWindow.window(), bottomOffset: bottomOffset)}}//在view上显示
extension UIView
{// MARK:- 中间显示/// 中间显示////// - Parameter text: 文字public func showXHToastCenterWithText(_ text:String){self.showXHToastCenterWithText(text, duration: ToastDispalyDuration)}/// 中间显示+自定义停留时间////// - Parameters:/// - text: 文字/// - duration: 自定义停留时间public func showXHToastCenterWithText(_ text:String , duration:CGFloat){let toast: XHToast = XHToast(text: text)toast.duration = durationtoast.showIn(self)}// MARK:-上方显示/// 上方显示////// - Parameter text: 文字public func showXHToastTopWithText(_ text:String){self.showXHToastTopWithText(text, topOffset: ToastSpace, duration: ToastDispalyDuration)}/// 上方显示+自定义停留时间////// - Parameters:/// - text: 文字/// - duration: 自定义停留时间public func showXHToastTopWithText(_ text:String, duration:CGFloat){self.showXHToastTopWithText(text, topOffset: ToastSpace, duration: duration)}/// 上方显示+自定义到顶部距离////// - Parameters:/// - text: 文字/// - topOffset: 自定义到顶部距离public func showXHToastTopWithText(_ text:String,topOffset:CGFloat){self.showXHToastTopWithText(text, topOffset: topOffset, duration: ToastDispalyDuration)}/// 上方显示+自定义到顶部距离+自定义停留时间////// - Parameters:/// - text: 文字/// - topOffset: 自定义到顶部距离/// - duration: 自定义停留时间public func showXHToastTopWithText(_ text:String,topOffset:CGFloat,duration:CGFloat) {let toast: XHToast = XHToast(text: text)toast.duration = durationtoast.showIn(self, topOffset: topOffset)}//MARK:-下方显示/// 下方显示////// - Parameter text: 文字public func showXHToastBottomWithText(_ text:String){self.showXHToastBottomWithText(text, bottomOffset: ToastSpace, duration: ToastDispalyDuration)}/// 下方显示+自定义停留时间////// - Parameters:/// - text: 文字/// - duration: 自定义停留时间public func showXHToastBottomWithText(_ text:String, duration:CGFloat){self.showXHToastBottomWithText(text, bottomOffset: ToastSpace, duration: duration)}/// 下方显示+自定义到顶部距离////// - Parameters:/// - text: 文字/// - topOffset: 自定义到顶部距离public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat){self.showXHToastBottomWithText(text, bottomOffset: bottomOffset, duration: ToastDispalyDuration)}/// 下方显示+自定义到顶部距离+自定义停留时间////// - Parameters:/// - text: 文字/// - topOffset: 自定义到顶部距离/// - duration: 自定义停留时间public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat) {let toast: XHToast = XHToast(text: text)toast.duration = durationtoast.showIn(self, bottomOffset: bottomOffset)}}extension UIWindow
{fileprivate class func window() -> UIWindow{let window = UIApplication.shared.windows.last!if(!window.isHidden){return window;}return (UIApplication.shared.delegate?.window!)!;}
}open class XHToast:NSObject {var contentView: UIButtonvar duration:CGFloatinit(text: String) {duration = ToastDispalyDurationlet font = UIFont.boldSystemFont(ofSize: 16)let attributes = [NSAttributedString.Key.font: font]let rect = text.boundingRect(with: CGSize(width: 250,height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attributes, context: nil)let textLabel: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: rect.size.width+40, height: rect.size.height+20))textLabel.backgroundColor = UIColor.cleartextLabel.textColor = UIColor.whitetextLabel.textAlignment = NSTextAlignment.centertextLabel.font = fonttextLabel.text = texttextLabel.numberOfLines = 0contentView = UIButton(frame: CGRect(x: 0, y: 0, width: textLabel.frame.size.width, height: textLabel.frame.size.height))contentView.layer.cornerRadius = 20.0contentView.backgroundColor = ToastBackgroundColorcontentView.addSubview(textLabel)contentView.autoresizingMask = UIView.AutoresizingMask.flexibleWidthsuper.init()contentView.addTarget(self, action:#selector(toastTaped(_:)), for: UIControl.Event.touchDown)contentView.alpha = 0.0}required public init?(coder aDecoder: NSCoder) {fatalError("init(coder:) has not been implemented")}fileprivate func dismissToast() {contentView.removeFromSuperview()}@objc fileprivate func toastTaped(_ sender: UIButton) {self.hideAnimation()}fileprivate func showAnimation() {UIView.animate(withDuration: 0.3, delay: 0, options: UIView.AnimationOptions.curveEaseIn, animations: {self.contentView.alpha = 1.0}) { (completion) in}}fileprivate func hideAnimation() {UIView.animate(withDuration: 0.3, delay: 0, options: UIView.AnimationOptions.curveEaseOut, animations: {self.contentView.alpha = 0.0}) { (completion) in}}fileprivate func showIn(_ view:UIView) {contentView.center = view.centerview.addSubview(contentView)self.showAnimation()DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {self.hideAnimation()}}fileprivate func showIn(_ view:UIView,topOffset top: CGFloat) {contentView.center = CGPoint(x: view.center.x, y: top+contentView.frame.size.height/2)view.addSubview(contentView)self.showAnimation()DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {self.hideAnimation()}}fileprivate func showIn(_ view:UIView,bottomOffset bottom: CGFloat) {contentView.center = CGPoint(x: view.center.x, y: view.frame.size.height-(bottom+contentView.frame.size.height/2))view.addSubview(contentView)self.showAnimation()DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {self.hideAnimation()}}}
相关文章:
iOS swift5 弹出提示文字(停留1~2s)XHToastSwift
CoderZhuXH/XHToastSwift - github // // XHToast.swift // XHToastSwiftExample // // Created by xiaohui on 16/8/12. // Copyright © 2016年 CoderZhuXH. All rights reserved. // 代码地址:https://github.com/CoderZhuXH/XHToastSwiftimport UIKit/*** Toast…...
Spring Bean 的生命周期,如何被管理的
实例化一个Bean,也就是我们通常说的new 按照Spring上下文对实例化的Bean进行配置,也就是IOC注入 如果这个Bean实现了BeanNameAware接口,会调用它实现的setBeanName(String beanId)方法,此处传递的是Spring配置文件中Bean的ID 如…...
MATLAB算法实战应用案例精讲-【概念篇】量子机器学习
目录 前言 几个高频面试题目 机器学习的方法论 知识储备 机器学习的实现...

【kubernetes】Argo Rollouts -- k8s下的自动化蓝绿部署
蓝绿(Blue-Green)部署简介 在现代软件开发和交付中,确保应用程序的平稳更新和发布对于用户体验和业务连续性至关重要。蓝绿部署是一种备受推崇的部署策略,它允许开发团队在不影响用户的情况下,将新版本的应用程序引入生产环境。 蓝绿部署的核心思想在于维护两个独立的环…...

vue Cesium接入在线地图
Cesium接入在线地图只需在创建时将imageryProvider属性换为在线地图的地址即可。 目录 天地图 OSM地图 ArcGIS 地图 谷歌影像地图 天地图 //矢量服务let imageryProvider new Cesium.WebMapTileServiceImageryProvider({url: "http://t0.tianditu.com/vec_w/wmts?s…...

OBS Studio 30.0 承诺在 Linux 上支持英特尔 QSV,为 DeckLink 提供 HDR 回放功能
导读OBS Studio 30.0 现已推出公开测试版,承诺为这款广受欢迎的免费开源截屏和流媒体应用程序提供多项令人兴奋的新功能,以及大量其他更改和错误修复。 OBS Studio 30.0 承诺在 Linux 上支持英特尔 QSV(快速同步视频)、WHIP/WebRT…...

springboot整合SpringSecurity
先写了一个配置类 给这个访问路径,加上角色权限 package com.qf.config;import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; impo…...
最近在搭建ELK日志平台时,logstash报错JSON parse error
直接进入正题,我在搭建elk日志,使用最简单的log4j2 socket json格式 输出到logstash. 但是logstash报错如下: [WARN ] 2023-08-30 10:15:17.766 [nioEventLoopGroup-2-2] jsonlines - JSON parse error, original data now in message field…...

某次护网红队getshell的经历
信息收集 某企业提供信息:企业官网的真实外网ip,内网ip 企业官网比较硬,从控股超过51%的子公司入手 通过企查查找到一堆控股高的子公司,通过ICP/IP地址/域名信息备案管理系统查找子公司官网,收集二级域名。通过google…...
C#实现日期选择器、显示当地时间、跑马灯等功能
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System...

如何让看书变听书?
听书神器 安卓 页面简单,易操作,全网小说随便听 各种声音帮你读你喜欢听的小说,带你进入主人公世界 支持网页版小说、本地小说、图片,都能读给你听 想看小说,又怕伤眼睛的宝子,可以试试看!…...

pytorch异常——loss异常,不断增大,并且loss出现inf
文章目录 异常报错异常截图异常代码原因解释修正代码执行结果 异常报错 epoch1:loss3667.782471 epoch2:loss65358620.000000 epoch3:loss14979486720.000000 epoch4:loss1739650891776.000000 epoch5:loss12361745880317952.000000 epoch6:loss2740315398365287284736.000000…...

Lua学习(一)
lua基础学习 LUA 语言1. 什么是lua?1.1 准备工作 2. 基本语法2.1 注释2.2 标识符2.3 关键字2.4 全局变量 3. 数据类型4. 变量4.1 赋值语句 5. 循环5.1 while循环5.2 for循环5.3泛型for循环5.4 repeat until 循环5.5 break 语句 6. 流程控制6.1 if语句6.2 if else 语…...

Python:列表推导式
相关阅读 Python专栏https://blog.csdn.net/weixin_45791458/category_12403403.html?spm1001.2014.3001.5482 列表推导式使得创建特定列表的方式更简洁。常见的用法为,对序列或可迭代对象中的每个元素应用某种操作,用生成的结果创建新的列表ÿ…...

应急三维电子沙盘数字孪生系统
一、简介应急三维电子沙盘数字孪生系统是一种基于虚拟现实技术和数字孪生技术的应急管理工具。它通过将真实世界的地理环境与虚拟世界的模拟环境相结合,实现了对应急场景的模拟、分析和决策支持。该系统主要由三维电子沙盘和数字孪生模型两部分组成。三维电子沙盘是…...
LeetCode每日一题:1654. 到家的最少跳跃次数(2023.8.30 C++)
目录 1654. 到家的最少跳跃次数 题目描述: 实现代码与解析: bfs 1654. 到家的最少跳跃次数 题目描述: 有一只跳蚤的家在数轴上的位置 x 处。请你帮助它从位置 0 出发,到达它的家。 跳蚤跳跃的规则如下: 它可以 …...
数据结构例题代码及其讲解-栈与队列
栈与队列 栈Stack 后进先出 栈的结构体定义及基本操作。 #define MaxSize 50 typedef struct {int data[MaxSize];//栈中存放数据类型为整型int top;//栈顶指针 }Stack;初始化 这里初始化时是将栈顶指针指向-1,有些则是指向0,因此后续入栈出栈…...
【Spark】Pyspark RDD
1. RDD算子1.1 文件 <> rdd对象1.2 map、foreach、mapPartitions、foreach Partitions1.3 flatMap 先map再解除嵌套1.4 reduceByKey、reduce、fold 分组聚合1.5 mapValue 二元组value进行map操作1.6 groupBy、groupByKey1.7 filter、distinct 过滤筛选1.8 union 合并1.9 …...

数学建模:Logistic回归预测
🔆 文章首发于我的个人博客:欢迎大佬们来逛逛 数学建模:Logistic回归预测 Logistic回归预测 logistic方程的定义: x t 1 c a e b t x_{t}\frac{1}{cae^{bt}}\quad xtcaebt1 d x d t − a b e b t ( c a e b t ) 2 >…...

一个面向MCU的小型前后台系统
JxOS简介 JxOS面向MCU的小型前后台系统,提供消息、事件等服务,以及软件定时器,低功耗管理,按键,led等常用功能模块。 gitee仓库地址为(复制到浏览器打开): https://gitee.com/jer…...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南
点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...

Flask RESTful 示例
目录 1. 环境准备2. 安装依赖3. 修改main.py4. 运行应用5. API使用示例获取所有任务获取单个任务创建新任务更新任务删除任务 中文乱码问题: 下面创建一个简单的Flask RESTful API示例。首先,我们需要创建环境,安装必要的依赖,然后…...
基于服务器使用 apt 安装、配置 Nginx
🧾 一、查看可安装的 Nginx 版本 首先,你可以运行以下命令查看可用版本: apt-cache madison nginx-core输出示例: nginx-core | 1.18.0-6ubuntu14.6 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages ng…...

从零开始打造 OpenSTLinux 6.6 Yocto 系统(基于STM32CubeMX)(九)
设备树移植 和uboot设备树修改的内容同步到kernel将设备树stm32mp157d-stm32mp157daa1-mx.dts复制到内核源码目录下 源码修改及编译 修改arch/arm/boot/dts/st/Makefile,新增设备树编译 stm32mp157f-ev1-m4-examples.dtb \stm32mp157d-stm32mp157daa1-mx.dtb修改…...

Ascend NPU上适配Step-Audio模型
1 概述 1.1 简述 Step-Audio 是业界首个集语音理解与生成控制一体化的产品级开源实时语音对话系统,支持多语言对话(如 中文,英文,日语),语音情感(如 开心,悲伤)&#x…...

Mac下Android Studio扫描根目录卡死问题记录
环境信息 操作系统: macOS 15.5 (Apple M2芯片)Android Studio版本: Meerkat Feature Drop | 2024.3.2 Patch 1 (Build #AI-243.26053.27.2432.13536105, 2025年5月22日构建) 问题现象 在项目开发过程中,提示一个依赖外部头文件的cpp源文件需要同步,点…...

宇树科技,改名了!
提到国内具身智能和机器人领域的代表企业,那宇树科技(Unitree)必须名列其榜。 最近,宇树科技的一项新变动消息在业界引发了不少关注和讨论,即: 宇树向其合作伙伴发布了一封公司名称变更函称,因…...

MacOS下Homebrew国内镜像加速指南(2025最新国内镜像加速)
macos brew国内镜像加速方法 brew install 加速formula.jws.json下载慢加速 🍺 最新版brew安装慢到怀疑人生?别怕,教你轻松起飞! 最近Homebrew更新至最新版,每次执行 brew 命令时都会自动从官方地址 https://formulae.…...

从“安全密码”到测试体系:Gitee Test 赋能关键领域软件质量保障
关键领域软件测试的"安全密码":Gitee Test如何破解行业痛点 在数字化浪潮席卷全球的今天,软件系统已成为国家关键领域的"神经中枢"。从国防军工到能源电力,从金融交易到交通管控,这些关乎国计民生的关键领域…...

在 Spring Boot 中使用 JSP
jsp? 好多年没用了。重新整一下 还费了点时间,记录一下。 项目结构: pom: <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://ww…...