https://github.com/yzhong52/gradientviewdemo
https://github.com/yzhong52/gradientviewdemo
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/yzhong52/gradientviewdemo
- Owner: yzhong52
- Created: 2018-02-24T16:30:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-26T15:31:22.000Z (almost 7 years ago)
- Last Synced: 2025-02-14T17:55:15.501Z (8 months ago)
- Language: Swift
- Size: 229 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Demo for using gradient overlay view
This is a demo project of showing how to create a gradient view and use it.
## How does it work?
Step 1. Define a custom gradient view (Swift 4):
import UIKit
class GradientView: UIView {
override open class var layerClass: AnyClass {
return CAGradientLayer.classForCoder()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
let gradientLayer = self.layer as! CAGradientLayer
gradientLayer.colors = [
UIColor.white.cgColor,
UIColor.init(white: 1, alpha: 0).cgColor
]
backgroundColor = UIColor.clear
}
}Step 2. - Drag and drop a `UIView` in your storyboard and set its custom class to `GradientView`
## Result
This is the final result of how it looks as an overlay on the map view.
![]()