Created
September 23, 2018 11:46
-
-
Save jeffersonsetiawan/54d65dc5a9f03b456c3702d10f4de463 to your computer and use it in GitHub Desktop.
Playground for Coupon like View (Concaved 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
import UIKit | |
import PlaygroundSupport | |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 647)) | |
view.backgroundColor = UIColor.white | |
let shadowView = UIView(frame: CGRect(x:50, y: 50, width:250, height:250)) | |
view.addSubview(shadowView) | |
let someView = UIView(frame: CGRect(x:50, y: 50, width:250, height:250)) | |
someView.backgroundColor = UIColor.white | |
view.addSubview(someView) | |
let shapeLayer = CAShapeLayer() | |
shapeLayer.frame = someView.bounds | |
shapeLayer.path = UIBezierPath(roundedRect: someView.bounds, | |
byRoundingCorners: [UIRectCorner.bottomLeft,UIRectCorner.bottomRight] , | |
cornerRadii: CGSize(width: 5.0, height: 5.0)).cgPath | |
let rect = CGRect(x:0, y:0, width:200, height:100) | |
let cornerRadius:CGFloat = 5 | |
let subPathSideSize:CGFloat = 25 | |
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius) | |
let leftSubPath = UIBezierPath(arcCenter: CGPoint(x: rect.width / 2, y: 0), | |
radius: subPathSideSize / 2, startAngle: .pi, endAngle: .pi * 0, clockwise: false) | |
leftSubPath.close() | |
let rightSubPath = UIBezierPath(arcCenter: CGPoint(x: rect.width / 2, y: rect.height), | |
radius: subPathSideSize / 2, startAngle: .pi, endAngle: .pi * 0, clockwise: true) | |
rightSubPath.close() | |
path.append(leftSubPath) | |
path.append(rightSubPath.reversing()) | |
let mask = CAShapeLayer() | |
mask.frame = shapeLayer.bounds | |
mask.path = path.cgPath | |
someView.layer.mask = mask | |
let shadowMask = CAShapeLayer() | |
shadowMask.frame = shadowView.bounds | |
shadowMask.path = path.cgPath | |
shadowMask.shadowOpacity = 0.2 | |
shadowMask.shadowRadius = 4 | |
shadowMask.masksToBounds = false | |
shadowMask.shadowOffset = CGSize(width: 0, height: 2) | |
shadowView.backgroundColor = UIColor.clear | |
shadowView.layer.addSublayer(shadowMask) | |
let borderLayer = CAShapeLayer() | |
borderLayer.path = path.cgPath | |
borderLayer.strokeColor = UIColor.green.cgColor | |
borderLayer.fillColor = UIColor.clear.cgColor | |
borderLayer.lineWidth = 1 | |
someView.layer.addSublayer(borderLayer) | |
view | |
PlaygroundPage.current.liveView = view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment