/AfriwanLib

General library for iOS, iPadOS and macOS app. Load image, create animation, round corner, check connection, crypto, toast, alert and much more easily with AfriwanLib.

Primary LanguageSwiftOtherNOASSERTION

One Library for All

General library for iOS, iPadOS and macOS app. Load an image, create animation, round corner of view/button, check internet connection, crypto, toast, alert and much more easily with AfriwanLib. You can click the image below for easy step to use this library.

Load Image Link Animation Link Connection Link

Toast Link Crypto Link Alert Link

How to use

First step, add AfriwanLib on your Podfile

pod 'AfriwanLib'

Open your Terminal and run Pod Install. Don’t forget to import AfriwanLib in your Class:

import AfriwanLib

Animation Demo    Create Animation & Round Corner

Now you can create round corner of your view or button easily with single lline of code:

roundCorner(view: button_blue, cornerRadius: 15)

Or create custom round corner only with adding parameter you needed:

// 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)

Create animation for UIView, UIButton, UITextField, etc as simple as this:

pulsate(view: yourVieworButton)

Or create custom animation only with adding parameter you needed:

// 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    Load Image

Load an image, even there is no internet connection you can see an image that have been loaded before, so it faster to display image and saving internet quota. It's give good experience for user.

With single line of code we can load an image from url without background:

image_view.loadImage(imageUrl: "url")

Load image with background image before image fully loaded (for example with "AppIcon" image background) with this simple code:

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

Connection Demo    Check Internet Connection

Very easy to check internet connection

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

Toast Demo    Dynamic Toast

Simple toast:

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

Custom toast with some parameter, example:

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

Complete toast with modify all parameter, example:

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

Crypto Demo    Cryptographic Hash Function (SHA)

The SHA (Secure Hash Algorithm) is one of a number of cryptographic hash functions. A cryptographic hash is like a signature for a text or a data file. Hash is a one way function – it cannot be decrypted back. It's implemented in some widely used security applications and protocols, including TLS and SSL, PGP, SSH, S/MIME, IPsec, image caching. Moreover, this makes it suitable for password validation, challenge hash authentication, anti-tamper, digital signatures, etc. SHA-256 algorithm generates an almost-unique, fixed size 256-bit (32-byte) hash. Convert value to SHA-256:

sha256(value: "value to convert")

SHA-512 is a cryptographic hash function that when applied to the provided input results in a 128-digit hexadecimal number that is highly unlikely to match the value produced for a different input. Convert value to SHA-512 only with this function:

sha512(value: "value to convert")

Alert Demo    Alert & Sheet

This is example for show Alert & Sheet easily. Simple alert:

alert(title: "Simple Alert")

Custom 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])

Simple sheet:

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

Custom sheet:

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)

One Library for iOS, iPadOS, and macOS App

The good news, beside iOS app, you can use this library for your iPadOS and macOS app too with Xcode 11, but don't worry with lower Xcode you still can use this library for your iOS app.

Project example include in this Library, you can clone or download from this repository. Use Xcode 11 to open project and choose "AfriwanLibExamples" like picture below:

Project example