Created
August 26, 2021 15:26
-
-
Save pvn/5a8194dc15567751f23db2915ad8cae4 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// Uiview.swift | |
// Created by praveen shrivastav on 26/08/2021. | |
// | |
import UIKit | |
extension UIView{ | |
func makeGradientView(_ colorOne:UIColor,colorTwo:UIColor ){ | |
let gradientLayer = CAGradientLayer() | |
gradientLayer.frame = self.bounds | |
gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor] //Add different color here | |
gradientLayer.startPoint = CGPoint(x: 0, y: 0.5) | |
gradientLayer.endPoint = CGPoint(x: 1, y: 0.5) | |
self.layer.addSublayer(gradientLayer) | |
} | |
func makeOverlayViewGradient(_ colorOne:UIColor,colorTwo:UIColor ){ | |
let gradientLayer = CAGradientLayer() | |
gradientLayer.frame = self.bounds | |
gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor] | |
gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0) | |
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0) | |
gradientLayer.frame = CGRect(x: 0.0, y: 0.0, width: self.frame.size.width, height: self.frame.size.height) | |
self.layer.addSublayer(gradientLayer) | |
} | |
func shadowEffect(){ | |
self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath | |
self.layer.shadowRadius = 5 | |
self.layer.shadowOffset = .zero | |
self.layer.shadowOpacity = 1 | |
self.layer.shadowColor = UIColor.yellow.cgColor//hexStringToUIColor(hex: "0C1F23").cgColor | |
} | |
func roundCorner(corners: UIRectCorner, radius: CGFloat) { | |
let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let maskLayer = CAShapeLayer() | |
maskLayer.frame = bounds | |
maskLayer.path = maskPath.cgPath | |
layer.mask = maskLayer | |
} | |
@IBInspectable | |
var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
} | |
} | |
@IBInspectable | |
var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = newValue | |
} | |
} | |
@IBInspectable | |
var borderColor: UIColor? { | |
get { | |
if let color = layer.borderColor { | |
return UIColor(cgColor: color) | |
} | |
return nil | |
} | |
set { | |
if let color = newValue { | |
layer.borderColor = color.cgColor | |
} else { | |
layer.borderColor = nil | |
} | |
} | |
} | |
@IBInspectable | |
var shadowRadius: CGFloat { | |
get { | |
return layer.shadowRadius | |
} | |
set { | |
layer.shadowRadius = newValue | |
} | |
} | |
@IBInspectable | |
var shadowOpacity: Float { | |
get { | |
return layer.shadowOpacity | |
} | |
set { | |
layer.shadowOpacity = newValue | |
} | |
} | |
} | |
/* How to use */ | |
/* | |
self.view.shadowEffect() | |
self.view.makeGradientView(hexStringToUIColor(hex: "0d262d"), colorTwo: hexStringToUIColor(hex: "0d2127")) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment