当前位置: 首页 > news >正文

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 列表推导式使得创建特定列表的方式更简洁。常见的用法为,对序列或可迭代对象中的每个元素应用某种操作,用生成的结果创建新的列表&#xff…...

应急三维电子沙盘数字孪生系统

一、简介应急三维电子沙盘数字孪生系统是一种基于虚拟现实技术和数字孪生技术的应急管理工具。它通过将真实世界的地理环境与虚拟世界的模拟环境相结合,实现了对应急场景的模拟、分析和决策支持。该系统主要由三维电子沙盘和数字孪生模型两部分组成。三维电子沙盘是…...

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回归预测

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

一个面向MCU的小型前后台系统

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

eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)

说明&#xff1a; 想象一下&#xff0c;你正在用eNSP搭建一个虚拟的网络世界&#xff0c;里面有虚拟的路由器、交换机、电脑&#xff08;PC&#xff09;等等。这些设备都在你的电脑里面“运行”&#xff0c;它们之间可以互相通信&#xff0c;就像一个封闭的小王国。 但是&#…...

多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验

一、多模态商品数据接口的技术架构 &#xff08;一&#xff09;多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如&#xff0c;当用户上传一张“蓝色连衣裙”的图片时&#xff0c;接口可自动提取图像中的颜色&#xff08;RGB值&…...

剑指offer20_链表中环的入口节点

链表中环的入口节点 给定一个链表&#xff0c;若其中包含环&#xff0c;则输出环的入口节点。 若其中不包含环&#xff0c;则输出null。 数据范围 节点 val 值取值范围 [ 1 , 1000 ] [1,1000] [1,1000]。 节点 val 值各不相同。 链表长度 [ 0 , 500 ] [0,500] [0,500]。 …...

Spring AI与Spring Modulith核心技术解析

Spring AI核心架构解析 Spring AI&#xff08;https://spring.io/projects/spring-ai&#xff09;作为Spring生态中的AI集成框架&#xff0c;其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似&#xff0c;但特别为多语…...

DingDing机器人群消息推送

文章目录 1 新建机器人2 API文档说明3 代码编写 1 新建机器人 点击群设置 下滑到群管理的机器人&#xff0c;点击进入 添加机器人 选择自定义Webhook服务 点击添加 设置安全设置&#xff0c;详见说明文档 成功后&#xff0c;记录Webhook 2 API文档说明 点击设置说明 查看自…...

iview框架主题色的应用

1.下载 less要使用3.0.0以下的版本 npm install less2.7.3 npm install less-loader4.0.52./src/config/theme.js文件 module.exports {yellow: {theme-color: #FDCE04},blue: {theme-color: #547CE7} }在sass中使用theme配置的颜色主题&#xff0c;无需引入&#xff0c;直接可…...

4. TypeScript 类型推断与类型组合

一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式&#xff0c;自动确定它们的类型。 这一特性减少了显式类型注解的需要&#xff0c;在保持类型安全的同时简化了代码。通过分析上下文和初始值&#xff0c;TypeSc…...

echarts使用graphic强行给图增加一个边框(边框根据自己的图形大小设置)- 适用于无法使用dom的样式

pdf-lib https://blog.csdn.net/Shi_haoliu/article/details/148157624?spm1001.2014.3001.5501 为了完成在pdf中导出echarts图&#xff0c;如果边框加在dom上面&#xff0c;pdf-lib导出svg的时候并不会导出边框&#xff0c;所以只能在echarts图上面加边框 grid的边框是在图里…...

Django RBAC项目后端实战 - 03 DRF权限控制实现

项目背景 在上一篇文章中&#xff0c;我们完成了JWT认证系统的集成。本篇文章将实现基于Redis的RBAC权限控制系统&#xff0c;为系统提供细粒度的权限控制。 开发目标 实现基于Redis的权限缓存机制开发DRF权限控制类实现权限管理API配置权限白名单 前置配置 在开始开发权限…...

鸿蒙Navigation路由导航-基本使用介绍

1. Navigation介绍 Navigation组件是路由导航的根视图容器&#xff0c;一般作为Page页面的根容器使用&#xff0c;其内部默认包含了标题栏、内容区和工具栏&#xff0c;其中内容区默认首页显示导航内容&#xff08;Navigation的子组件&#xff09;或非首页显示&#xff08;Nav…...