AfriwanLib 1.0

AfriwanLib 1.0

Afriwan Ahda维护。



  • Afriwan Ahda

一个库,适用于所有

适用于iOS、iPadOS和macOS应用的通用库。使用AfriwanLib轻松加载图像、创建动画、圆角视图/按钮、检查网络连接等。您可以点击下面的图像以了解如何使用此库的简单步骤。

Load Image Link Animation Link Connection Link

Toast Link Crypto Link Alert Link

如何使用

第一步,在您的Podfile中添加AfriwanLib

pod 'AfriwanLib'

打开终端并运行Pod Install。别忘了在您的类中导入AfriwanLib

import AfriwanLib

Animation Demo    创建动画 & 圆角

现在您可以使用一行代码轻松地创建视图或按钮的圆角

roundCorner(view: button_blue, cornerRadius: 15)

或仅通过添加您需要的参数来创建自定义圆角

// Custom round corner with full parameter
roundCorner(view: view_green, cornerRadius: 30, shadowOpacity: 0.4, shadowRadius: 2.5, shadowOffset: CGSize.init(width: 1, height: 1), masksToBounds: false)

// Custom round corner with some parameter, for this example I create circle view.
roundCorner(view: view_orange, cornerRadius: view_orange.frame.height/2, shadowOpacity: 0.35, shadowRadius: 3.2)

为UIView、UIButton、UITextField等创建动画就像这样简单

pulsate(view: yourVieworButton)

或仅通过添加您需要的参数来创建自定义动画

// Custom animation with some parameter
shake(view: view_green, duration: 0.2, autoreverses: true, repeatCount: 3)

// Custom animation with full parameter
flash(view: view_orange, duration: 0.5, autoreverses: true, repeatCount: 5, fromValue: 1, toValue: 0.2, timingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))

Load Image Demo    加载图片

即使没有网络连接,您也可以加载之前已加载的图像,这样显示图像更快,还可以节省网络流量。这为用户提供了良好的体验。

只需要一行代码,我们就可以从URL加载图像,而无需背景。

image_view.loadImage(imageUrl: "url")

使用此简单代码,在图像完全加载之前加载具有背景图像的图像(例如带有“AppIcon”图像背景)。

image_view.loadImage(imageUrl: "url", backgroundImage: #imageLiteral(resourceName: "AppIcon"))

连接演示    检查网络连接

检查网络连接非常简单

if isConnectedToInternet() {
resultText = "Connected"
} else {
resultText = "Not Connected"
}

Toast 演示    动态 Toast

简单的 Toast

toast(message: "your message", view: self.view)

带参数的定制 Toast,示例

toast(message: "This is Toast with parameter added:\ny (vertical position) and height", view: self.view, y: 145, height: 58)

修改所有参数的完整 Toast,示例

toast(message: "Complete Toast with all parameter", view: view, duration: 5, textColor: UIColor.white, backgroundColor: UIColor.blue, y: 179, height: 32, fontSize: 16)

加密演示    密码学哈希函数(SHA)

SHA512是一种密码学哈希函数,当应用于输入时,将产生一个非常可能的128位十六进制数字,与不同输入产生的值不匹配。此函数在安全应用和协议中实现,包括TLS和SSL、PGP、SSH、S/MIME、IPsec、保存密码、图像缓存等。仅使用此函数将值转换为SHA512。

sha512(value: "value to convert")

转换为SHA256

sha256(value: "value to convert")

警告演示    警告 & 表单

简单警告

alert(title: "Simple Alert")

自定义警告

let yesAction = UIAlertAction(title: "Yes", style: .default) { (action) in
toast(message: "Yes action", view: self.view)
}
let noAction = UIAlertAction(title: "No", style: .destructive) { (action) in
toast(message: "No action", view: self.view)
}
alert(title: "Alert", message: "Custom alert", actions: [yesAction, noAction])

简单表单

alert(title: "Simple Sheet", style: .actionSheet)

自定义表单

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
toast(message: "Cancel action", view: self.view)
}
let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { (action) in
toast(message: "Delete action", view: self.view)
}
alert(title: "Are you sure?", message: "You can not undo this action", actions: [cancelAction, deleteAction], style: .actionSheet)

适用于iOS、iPadOS和macOS应用的单一库

好消息,除了iOS应用,您还可以使用这个库为您的iPadOS和macOS应用进行开发,使用Xcode 11即可,但不用担心,在较低的Xcode版本下,您仍然可以使用这个库为您的iOS应用进行开发。

该库中包含的项目示例,您可以从中克隆或下载。使用Xcode 11打开项目,并选择如下图片所示的“AfriwanLibExamples”。

Project example