Skip to content

Instantly share code, notes, and snippets.

@jeffersonsetiawan
Created September 20, 2018 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffersonsetiawan/1bf3b96f32d91b2cf6f2a55f25457231 to your computer and use it in GitHub Desktop.
Save jeffersonsetiawan/1bf3b96f32d91b2cf6f2a55f25457231 to your computer and use it in GitHub Desktop.
CouponView
//
// DummyView.swift
// CustomShape
//
// Created by Jefferson Setiawan on 19/09/18.
// Copyright © 2018 Jefferson Setiawan. All rights reserved.
//
import UIKit
internal class DummyView: UIView {
private var borderLayer = CAShapeLayer()
@IBOutlet var contentView: UIView!
@IBOutlet weak var shadowView: UIView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var leftView: UIView!
@IBOutlet weak var concaveView: UIView!
@IBOutlet weak var actionView: UIView!
override internal init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func commonInit() {
Bundle.main.loadNibNamed(String(describing: type(of: self)), owner: self, options: nil)
couponShape()
addSubview(contentView)
// leftView.cornerRadius = 20.0
// actionView.cornerRadius = 20.0
}
func couponShape() {
let couponPath = UIBezierPath()
let zeroPoint = CGPoint.zero
couponPath.move(to: zeroPoint)
couponPath.addLine(to: CGPoint(x: leftView.frame.width, y: zeroPoint.y))
let radius = concaveView.frame.width / 2
let centerX = zeroPoint.x + leftView.frame.width + radius
couponPath.addArc(withCenter: CGPoint(x: centerX, y: zeroPoint.y), radius: radius, startAngle: CGFloat.pi, endAngle: 0, clockwise: false)
couponPath.addLine(to: CGPoint(x: containerView.frame.width, y: zeroPoint.y))
couponPath.addLine(to: CGPoint(x: containerView.frame.width, y: containerView.frame.height))
couponPath.addArc(withCenter: CGPoint(x: leftView.frame.width + radius, y: containerView.frame.height), radius: radius, startAngle: CGFloat.pi * 0, endAngle: CGFloat.pi, clockwise: false)
couponPath.addLine(to: CGPoint(x: zeroPoint.x, y: containerView.frame.height))
couponPath.close()
let finalPath = UIBezierPath(cgPath: couponPath.cgPath)
finalPath.append(UIBezierPath(rect: containerView.bounds))
finalPath.append(couponPath)
let shapeLayer = CAShapeLayer()
shapeLayer.path = couponPath.cgPath
// shapeLayer.mask = roundedMask
let roundedMask = CAShapeLayer()
roundedMask.path = UIBezierPath(roundedRect: containerView.bounds, cornerRadius: 20.0).cgPath
// roundedMask.cornerRadius = 20.0
roundedMask.mask = shapeLayer
//
self.containerView.layer.mask = shapeLayer
//
let shadowLayer = CAShapeLayer()
shadowLayer.frame = containerView.frame
shadowLayer.path = shapeLayer.path
shadowLayer.shadowOpacity = 0.5
shadowLayer.shadowRadius = 5
shadowLayer.masksToBounds = false
shadowLayer.shadowOffset = CGSize(width: 0, height: 20)
//
//
// containerView.layer.mask = shapeLayer
//
self.shadowView.layer.addSublayer(shadowLayer)
// self.shadowView.layer.insertSublayer(shadowLayer, at: 0)
//
borderLayer.path = shapeLayer.path
borderLayer.strokeColor = UIColor.tpGreen().cgColor
borderLayer.lineWidth = 2
}
private func createCouponPath() {
}
internal func didSelect() {
self.shadowView.layer.addSublayer(borderLayer)
}
internal func didDeselect() {
borderLayer.removeFromSuperlayer()
}
}
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DummyView" customModule="RevampBankAccountUI" customModuleProvider="target">
<connections>
<outlet property="actionView" destination="YmR-Rz-dnc" id="MI8-BE-bqA"/>
<outlet property="concaveView" destination="vre-S5-ceu" id="3GL-Rh-sJG"/>
<outlet property="containerView" destination="M07-1s-cGf" id="sUh-tC-lXo"/>
<outlet property="contentView" destination="iN0-l3-epB" id="koG-9a-Xy0"/>
<outlet property="leftView" destination="dTC-UU-Dgx" id="Cyo-JY-md4"/>
<outlet property="shadowView" destination="eoo-qC-qdn" id="Gfw-Hg-U4Z"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="125"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eoo-qC-qdn">
<rect key="frame" x="4" y="4" width="367" height="117"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="M07-1s-cGf">
<rect key="frame" x="4" y="4" width="367" height="117"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dTC-UU-Dgx">
<rect key="frame" x="0.0" y="0.0" width="217" height="117"/>
<color key="backgroundColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vre-S5-ceu">
<rect key="frame" x="217" y="0.0" width="30" height="117"/>
<color key="backgroundColor" red="0.32129067950000001" green="0.84462268780000005" blue="1" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="kIx-ii-lng"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YmR-Rz-dnc">
<rect key="frame" x="247" y="0.0" width="120" height="117"/>
<color key="backgroundColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="T63-DB-95l"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="dTC-UU-Dgx" firstAttribute="top" secondItem="M07-1s-cGf" secondAttribute="top" id="FCY-RY-UeE"/>
<constraint firstItem="dTC-UU-Dgx" firstAttribute="leading" secondItem="M07-1s-cGf" secondAttribute="leading" id="GeB-1z-HhA"/>
<constraint firstAttribute="trailing" secondItem="YmR-Rz-dnc" secondAttribute="trailing" id="HLI-Q5-oI1"/>
<constraint firstItem="YmR-Rz-dnc" firstAttribute="top" secondItem="M07-1s-cGf" secondAttribute="top" id="NTG-vE-mFD"/>
<constraint firstItem="vre-S5-ceu" firstAttribute="top" secondItem="M07-1s-cGf" secondAttribute="top" id="fqR-dF-2cd"/>
<constraint firstAttribute="bottom" secondItem="vre-S5-ceu" secondAttribute="bottom" id="llL-MG-DWa"/>
<constraint firstItem="YmR-Rz-dnc" firstAttribute="leading" secondItem="vre-S5-ceu" secondAttribute="trailing" id="m0K-Xz-ill"/>
<constraint firstAttribute="bottom" secondItem="dTC-UU-Dgx" secondAttribute="bottom" id="qsr-PG-NCJ"/>
<constraint firstAttribute="bottom" secondItem="YmR-Rz-dnc" secondAttribute="bottom" id="rvm-Vm-NWh"/>
<constraint firstItem="vre-S5-ceu" firstAttribute="leading" secondItem="dTC-UU-Dgx" secondAttribute="trailing" id="v0z-1e-Pma"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="M07-1s-cGf" secondAttribute="bottom" constant="4" id="1Yz-ji-FGx"/>
<constraint firstItem="M07-1s-cGf" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="4" id="98G-QS-UGB"/>
<constraint firstItem="M07-1s-cGf" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="4" id="9KM-BG-1o6"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="eoo-qC-qdn" secondAttribute="trailing" constant="4" id="Nv2-DL-NUz"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="M07-1s-cGf" secondAttribute="trailing" constant="4" id="ZID-ZS-A0f"/>
<constraint firstItem="eoo-qC-qdn" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="4" id="nyH-1R-7rv"/>
<constraint firstAttribute="bottom" secondItem="eoo-qC-qdn" secondAttribute="bottom" constant="4" id="qxf-C3-Igc"/>
<constraint firstItem="eoo-qC-qdn" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="4" id="vqc-YL-yuF"/>
</constraints>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<point key="canvasLocation" x="43.5" y="-217.5"/>
</view>
</objects>
</document>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment