GKCover is a lightweight framework that provides a simple way to display various types of covers in your iOS app.
Features
- Display covers with different styles, including rounded corners and insets
- Supports both images and colors as covers
- Control cover position and size easily
- Add custom subviews to covers
- Smooth animations for showing and hiding covers
- Gesture support for dismissing covers
Installation
To install GKCover using CocoaPods, add the following line to your Podfile:
pod 'GKCover'
Then, run the following command:
pod update
Usage
To start using GKCover, import the framework:
import GKCover
Displaying a Cover
To display a cover, create a new instance of GKCover and set its content:
let cover = GKCover() cover.content = .color(UIColor.red)
The above code creates a cover with a solid red color. You can also set the content to an instance of UIImage to display an image as the cover.
You can customize the appearance of the cover using various properties:
cover.maskAlpha = 0.4 // Sets the transparency of the cover cover.cornerRadius = 10 // Sets the corner radius of the cover cover.isDismissable = true // Allows the cover to be dismissed by tapping
Additionally, you can add custom subviews to the cover:
let titleLabel = UILabel() titleLabel.text = "Hello, World!" cover.addSubview(titleLabel)
Displaying a Cover with Animation
You can animate the showing and hiding of a cover with the animation duration and options:
cover.show(onView: self.view, animated: true, duration: 0.3, options: .curveEaseInOut)
cover.hide(animated: true, duration: 0.3, options: .curveEaseInOut)
Delegate Methods
If you need to respond to cover events, you can implement the GKCoverDelegate protocol:
class ViewController: UIViewController, GKCoverDelegate { // ... func coverWillShow(_ cover: GKCover) { // Called before the cover is shown } func coverDidShow(_ cover: GKCover) { // Called after the cover is shown } func coverWillHide(_ cover: GKCover) { // Called before the cover is hidden } func coverDidHide(_ cover: GKCover) { // Called after the cover is hidden } }
Conclusion
GKCover provides a straightforward solution for displaying various types of covers in your iOS app. It offers customizable options and smooth animations, making it a versatile choice for displaying overlays.