You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.3 KiB
68 lines
2.3 KiB
//
|
|
// UIViewExtension.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by Fm-user on 12/23/17.
|
|
// Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VisualEffectView
|
|
|
|
extension UIView {
|
|
func roundCorners(_ corners: UIRectCorner, radius: CGFloat, borderColor: UIColor?, borderWidth: CGFloat?) {
|
|
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
|
|
|
|
let mask = CAShapeLayer()
|
|
mask.frame = self.bounds
|
|
mask.path = path.cgPath
|
|
self.layer.mask = mask
|
|
|
|
if borderWidth != nil {
|
|
addBorder(mask, borderWidth: borderWidth!, borderColor: borderColor!)
|
|
}
|
|
}
|
|
|
|
private func addBorder(_ mask: CAShapeLayer, borderWidth: CGFloat, borderColor: UIColor) {
|
|
let borderLayer = CAShapeLayer()
|
|
borderLayer.path = mask.path
|
|
borderLayer.fillColor = UIColor.clear.cgColor
|
|
borderLayer.strokeColor = borderColor.cgColor
|
|
borderLayer.lineWidth = borderWidth
|
|
borderLayer.frame = bounds
|
|
layer.addSublayer(borderLayer)
|
|
}
|
|
|
|
func rounded() {
|
|
self.layer.cornerRadius = self.frame.height / 2
|
|
}
|
|
|
|
func addBlur() {
|
|
let visualEffectView = VisualEffectView(frame: self.frame)
|
|
visualEffectView.colorTint = .clear
|
|
visualEffectView.colorTintAlpha = 0.2
|
|
visualEffectView.blurRadius = 3
|
|
visualEffectView.scale = 1
|
|
visualEffectView.isUserInteractionEnabled = false
|
|
self.addSubview(visualEffectView)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
extension UIView {
|
|
func fadeIn(duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
|
|
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
|
|
self.alpha = 1.0
|
|
}, completion: completion)
|
|
}
|
|
|
|
func fadeOut(duration: TimeInterval = 1.0, delay: TimeInterval = 3.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
|
|
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
|
|
self.alpha = 0.0
|
|
}, completion: completion)
|
|
}
|
|
}
|
|
|