Created
April 20, 2017 19:06
-
-
Save wildthink/6da4e24c5a8c34a8603d7157fa339a21 to your computer and use it in GitHub Desktop.
BlurredRoundedView updated to Swift 3
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
import UIKit | |
import MapKit | |
import XCPlayground | |
// https://macteo.it/ios/2016/08/10/blurred-rounded-uiview.html | |
let extraLightBlur = UIBlurEffect(style: .extraLight) | |
let cornerRadius : CGFloat = 0 | |
class BlurredRoundedView: UIView { | |
let effectBackground = UIVisualEffectView(effect: extraLightBlur) | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
commonInit() | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} | |
func commonInit() { | |
initLayer() | |
initEffectView() | |
} | |
func initLayer() { | |
backgroundColor = UIColor.white | |
layer.cornerRadius = cornerRadius | |
layer.masksToBounds = false | |
} | |
func initEffectView() { | |
effectBackground.frame = bounds | |
effectBackground.layer.cornerRadius = cornerRadius | |
effectBackground.layer.masksToBounds = true | |
addSubview(effectBackground) | |
sendSubview(toBack: effectBackground) | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius) | |
layer.masksToBounds = false | |
layer.shadowColor = UIColor.darkGray.cgColor | |
layer.shadowOffset = CGSize(width: 2.0, height: 2.0) | |
layer.shadowOpacity = 0.4 | |
layer.shadowRadius = 4 | |
layer.shadowPath = shadowPath.cgPath | |
} | |
} | |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 480)) | |
let delta = 10.0 | |
let frame = CGRect( x:0, y:0, width:200, height:200 ) | |
let mapView = MKMapView( frame: view.bounds ) | |
var region = MKCoordinateRegion() | |
region.center.latitude = 42.6 | |
region.center.longitude = 11.9 | |
region.span.latitudeDelta = delta | |
region.span.longitudeDelta = delta | |
mapView.setRegion( region, animated: true ) | |
view.addSubview(mapView) | |
let floatingView = BlurredRoundedView(frame: CGRect(x: 60, y: 60, width: 200, height: 360)) | |
view.addSubview(floatingView) | |
XCPlaygroundPage.currentPage.liveView = view | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment