Created
January 19, 2021 22:29
-
-
Save alexpersian/88cad463fd6912e47e9270c7b6fd5513 to your computer and use it in GitHub Desktop.
Rough attempt at making a glowing pill style view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
class MyViewController : UIViewController { | |
override func loadView() { | |
let pillView = UIView(frame: CGRect(x: 64, y: 64, width: 32, height: 128)) | |
pillView.backgroundColor = .white | |
pillView.layer.cornerRadius = pillView.frame.width / 2 | |
pillView.layer.borderWidth = 1 | |
pillView.layer.borderColor = UIColor.systemGray2.cgColor | |
pillView.layer.shadowOffset = .zero | |
pillView.layer.shadowColor = UIColor.systemGray4.cgColor | |
pillView.layer.shadowRadius = 10 | |
pillView.layer.shadowOpacity = 0.75 | |
let fillView = UIView(frame: CGRect(x: 4, y: 32, width: 24, height: 92)) | |
fillView.layer.cornerRadius = fillView.frame.width / 2 | |
let fillGradient = CAGradientLayer() | |
fillGradient.colors = [UIColor.systemOrange.cgColor, UIColor.systemRed.cgColor] | |
fillGradient.frame = fillView.bounds | |
fillGradient.cornerRadius = fillView.frame.width / 2 | |
fillView.layer.addSublayer(fillGradient) | |
// This bit doesn't look quite right. Needs more tweaking to soften the edge or something. | |
// let fillGradientGauss = CAGradientLayer() | |
// fillGradientGauss.colors = [UIColor.systemOrange.cgColor, UIColor.systemRed.cgColor] | |
// fillGradientGauss.cornerRadius = fillView.frame.width / 2 | |
// if let filter = CIFilter(name: "CIGaussianBlur") { | |
// fillGradientGauss.filters = [filter] | |
// } | |
// fillGradientGauss.opacity = 0.3 | |
// fillGradientGauss.frame = fillView.bounds.applying(CGAffineTransform(scaleX: 1.2, y: 1.2)) | |
// fillView.layer.addSublayer(fillGradientGauss) | |
fillView.layer.shadowOffset = .zero | |
fillView.layer.shadowColor = UIColor.systemOrange.cgColor | |
fillView.layer.shadowRadius = 10 | |
fillView.layer.shadowOpacity = 0.9 | |
fillView.layer.shadowPath = UIBezierPath(rect: fillView.bounds).cgPath | |
pillView.addSubview(fillView) | |
let bgView = UIView(frame: CGRect(x: 0, y: 0, width: 256, height: 256)) | |
bgView.backgroundColor = .white | |
bgView.addSubview(pillView) | |
self.view = bgView | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment