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…...

UE5 学习系列(二)用户操作界面及介绍
这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…...

Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误
HTTP 状态码 406 (Not Acceptable) 和 500 (Internal Server Error) 是两类完全不同的错误,它们的含义、原因和解决方法都有显著区别。以下是详细对比: 1. HTTP 406 (Not Acceptable) 含义: 客户端请求的内容类型与服务器支持的内容类型不匹…...
线程同步:确保多线程程序的安全与高效!
全文目录: 开篇语前序前言第一部分:线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分:synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分ÿ…...

QT: `long long` 类型转换为 `QString` 2025.6.5
在 Qt 中,将 long long 类型转换为 QString 可以通过以下两种常用方法实现: 方法 1:使用 QString::number() 直接调用 QString 的静态方法 number(),将数值转换为字符串: long long value 1234567890123456789LL; …...

Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...
Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?
Redis 的发布订阅(Pub/Sub)模式与专业的 MQ(Message Queue)如 Kafka、RabbitMQ 进行比较,核心的权衡点在于:简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...

网站指纹识别
网站指纹识别 网站的最基本组成:服务器(操作系统)、中间件(web容器)、脚本语言、数据厍 为什么要了解这些?举个例子:发现了一个文件读取漏洞,我们需要读/etc/passwd,如…...

Git 3天2K星标:Datawhale 的 Happy-LLM 项目介绍(附教程)
引言 在人工智能飞速发展的今天,大语言模型(Large Language Models, LLMs)已成为技术领域的焦点。从智能写作到代码生成,LLM 的应用场景不断扩展,深刻改变了我们的工作和生活方式。然而,理解这些模型的内部…...

C++实现分布式网络通信框架RPC(2)——rpc发布端
有了上篇文章的项目的基本知识的了解,现在我们就开始构建项目。 目录 一、构建工程目录 二、本地服务发布成RPC服务 2.1理解RPC发布 2.2实现 三、Mprpc框架的基础类设计 3.1框架的初始化类 MprpcApplication 代码实现 3.2读取配置文件类 MprpcConfig 代码实现…...
es6+和css3新增的特性有哪些
一:ECMAScript 新特性(ES6) ES6 (2015) - 革命性更新 1,记住的方法,从一个方法里面用到了哪些技术 1,let /const块级作用域声明2,**默认参数**:函数参数可以设置默认值。3&#x…...