Add + All Screens
This commit is contained in:
1 parent
85d52cd837
commit
50d52c70a4
464 files changed
+12893
-4125
No files matched your search
+80
-12
@@ -7,6 +7,9 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
import AVFoundation
|
||||
|
||||
// MARK: Animations
|
||||
|
||||
extension UIButton {
|
||||
@@ -121,25 +124,90 @@ extension UIView {
|
||||
|
||||
// MARK: - Change Color
|
||||
|
||||
func animationColor(duration: Speed = .s1) {
|
||||
|
||||
let color = CABasicAnimation(keyPath: "backgroundColor")
|
||||
color.fromValue = UIColor.white.cgColor
|
||||
color.toValue = UIColor.red.cgColor
|
||||
color.duration = duration.rawValue
|
||||
color.beginTime = CACurrentMediaTime() + 0.3
|
||||
color.autoreverses = true
|
||||
func animationOpacity(duration: CGFloat, value: CGFloat, beginTime: CGFloat = 0.0) {
|
||||
//
|
||||
let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))// "opacity")
|
||||
pulseAnimation.fromValue = 0
|
||||
pulseAnimation.toValue = 1 // 0.1
|
||||
pulseAnimation.duration = 100
|
||||
|
||||
pulseAnimation.isRemovedOnCompletion = false
|
||||
pulseAnimation.beginTime = CACurrentMediaTime() + beginTime //CACurrentMediaTime() + AVCoreAnimationBeginTimeAtZero + 1.0
|
||||
pulseAnimation.fillMode = .both
|
||||
pulseAnimation.isAdditive = false
|
||||
// pulseAnimation.repeatCount = .infinit
|
||||
layer.add(pulseAnimation, forKey: "opacityIn")
|
||||
|
||||
|
||||
|
||||
let animtingLayer: CALayer = CALayer(layer: layer)
|
||||
|
||||
|
||||
let pulseAnimation2 = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))// "opacity")
|
||||
pulseAnimation2.fromValue = 1
|
||||
pulseAnimation2.toValue = beginTime // 0.1
|
||||
pulseAnimation2.duration = 100
|
||||
pulseAnimation2.isRemovedOnCompletion = false
|
||||
pulseAnimation2.beginTime = 1.0// AVCoreAnimationBeginTimeAtZero + 0.0
|
||||
pulseAnimation2.fillMode = .both
|
||||
pulseAnimation2.isAdditive = false
|
||||
// pulseAnimation2.repeatCount = .infinit
|
||||
|
||||
|
||||
animtingLayer.add(pulseAnimation2, forKey: "opacityOut")
|
||||
layer.addSublayer(animtingLayer)
|
||||
|
||||
|
||||
layer.opacity = 0.0
|
||||
|
||||
}
|
||||
|
||||
layer.add(color, forKey: "animationColor")
|
||||
func animationColor(duration: Speed = .s1, colors: [UIColor]) {
|
||||
|
||||
// layer.removeAnimation(forKey: "backgroundColor")
|
||||
// layer.sublayers?.forEach {
|
||||
// $0.mask?.removeAnimation(forKey: "backgroundColor")
|
||||
// }
|
||||
// layer.removeAllAnimations()
|
||||
// layer.removeFromSuperlayer()
|
||||
let darkerColor = colors[0]
|
||||
let lighterColor = colors[1]
|
||||
let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.backgroundColor))
|
||||
pulseAnimation.fromValue = darkerColor
|
||||
pulseAnimation.toValue = lighterColor
|
||||
pulseAnimation.duration = 1
|
||||
pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
pulseAnimation.autoreverses = true
|
||||
pulseAnimation.repeatCount = .infinity
|
||||
pulseAnimation.isRemovedOnCompletion = false
|
||||
|
||||
// let color = CABasicAnimation(keyPath: "backgroundColor")
|
||||
// color.fromValue = colors[0]// UIColor.green.cgColor
|
||||
// color.toValue = colors[1] // UIColor.red.cgColor
|
||||
// color.duration = duration.rawValue
|
||||
// color.beginTime = CACurrentMediaTime() + 0.3
|
||||
//// color.autoreverses = true
|
||||
//// color.repeatDuration = 1
|
||||
// color.autoreverses = true
|
||||
// color.repeatCount = 500
|
||||
// layer.cornerRadius = self.layer.cornerRadius
|
||||
//// layer.add(color, forKey: "animationColor")
|
||||
|
||||
|
||||
|
||||
layer.removeAnimation(forKey: "animationColor")
|
||||
layer.add(pulseAnimation, forKey: "animationColor")
|
||||
backgroundColor = .clear
|
||||
}
|
||||
|
||||
// MARK: - Pulsate
|
||||
|
||||
func pulsate(duration: Speed = .ms200) {
|
||||
func pulsate(duration: Speed = .ms200, value: CGFloat = 0.9) {
|
||||
|
||||
let pulse = CASpringAnimation(keyPath: "transform.scale")
|
||||
pulse.duration = duration.rawValue
|
||||
pulse.fromValue = 0.95
|
||||
pulse.fromValue = value
|
||||
pulse.toValue = 1.0
|
||||
pulse.autoreverses = true
|
||||
pulse.repeatCount = 2
|
||||
@@ -151,11 +219,11 @@ extension UIView {
|
||||
|
||||
// MARK: - Pulsate 2
|
||||
|
||||
func pulsateNew(visible: Alpha) {
|
||||
func pulsateNew(visible: Alpha, value: CGFloat = 0.9) {
|
||||
if visible == .visible {
|
||||
animate(self, transform: .identity)
|
||||
} else {
|
||||
animate(self, transform: CGAffineTransform.identity.scaledBy(x: 0.95, y: 0.95))
|
||||
animate(self, transform: CGAffineTransform.identity.scaledBy(x: value, y: value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -37,7 +37,7 @@ class Button: UIButton {
|
||||
|
||||
/// Simple tap implementation
|
||||
typealias Closure = () -> ()
|
||||
typealias ClosureClick = (_ down: Bool) -> ()
|
||||
typealias ClosureClick = (_ event: UIControl.Event) -> ()
|
||||
|
||||
|
||||
class ClosureSleeve {
|
||||
@@ -63,16 +63,20 @@ extension UIControl {
|
||||
|
||||
func tapClassic(_ closure: @escaping ClosureClick) {
|
||||
self.tap(for: .touchDown) { // [weak self] in
|
||||
closure(true)
|
||||
print(" btn tapClassic touchDown")
|
||||
closure(.touchDown)
|
||||
}
|
||||
self.tap(for: .touchUpInside) { // [weak self] in
|
||||
closure(false)
|
||||
print(" btn tapClassic touchUpInside")
|
||||
closure(.touchUpInside)
|
||||
}
|
||||
self.tap(for: .touchUpOutside) { // [weak self] in
|
||||
closure(false)
|
||||
print(" btn tapClassic touchUpOutside")
|
||||
closure(.touchUpOutside)
|
||||
}
|
||||
self.tap(for: .touchCancel) { // [weak self] in
|
||||
closure(false)
|
||||
print(" btn tapClassic touchCancel")
|
||||
closure(.touchCancel)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-13
@@ -68,12 +68,12 @@ class ButtonAnimationView: UIView {
|
||||
switch animationType {
|
||||
case 1: return .alpha(0.5)
|
||||
case 2: return .layerGray(0.1845)
|
||||
case 3: return .pulsate(new: false)
|
||||
case 4: return .pulsate(new: true)
|
||||
case 3: return .pulsate(new: false, value: 0.9)
|
||||
case 4: return .pulsate(new: true, value: 0.9)
|
||||
case 5: return .shake(new: false)
|
||||
case 6: return .shake(new: true)
|
||||
case 7: return .flash
|
||||
case 8: return .color
|
||||
case 8: return .color([.white, .red])
|
||||
case 9: return .androidStyle(color: .white)
|
||||
default: return .alpha(0.5)
|
||||
}
|
||||
@@ -110,10 +110,10 @@ extension UIButton {
|
||||
enum TapType {
|
||||
case alpha(_ value: CGFloat) // 0.5
|
||||
case layerGray(_ value: CGFloat = 0.1845) // 0.1845 add black shadow
|
||||
case pulsate(new: Bool = false)
|
||||
case pulsate(new: Bool = false, value: CGFloat = 0.9)
|
||||
case shake(new: Bool = false)
|
||||
case flash
|
||||
case color
|
||||
case color(_ arr: [UIColor] = [.white, .red])
|
||||
case androidStyle(color: UIColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1))
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ extension UIButton {
|
||||
}
|
||||
if !tapAdded {
|
||||
|
||||
let tap = BindableGestureRecognizer { [weak self] sender in
|
||||
let tapp = BindableGestureRecognizer { [weak self] sender in
|
||||
|
||||
guard let superview = self?.superview else { return }
|
||||
let touchPoint = sender.location(in: superview)
|
||||
@@ -155,8 +155,17 @@ extension UIButton {
|
||||
guard let dur: Speed = self?.defaultDuration(type: type) else { return }
|
||||
self?.androidPulseAnimation(duration: dur, color: color, position: touchPoint)
|
||||
|
||||
|
||||
if sender.state == .began {
|
||||
callback?(.touchDown)
|
||||
} else if sender.state == .changed {
|
||||
callback?(.touchDown)
|
||||
} else if sender.state == .ended {
|
||||
callback?(.touchUpInside)
|
||||
}
|
||||
// callback?(.touchUpInside)
|
||||
}
|
||||
addGestureRecognizer(tap)
|
||||
addGestureRecognizer(tapp)
|
||||
}
|
||||
}
|
||||
default: break
|
||||
@@ -196,9 +205,9 @@ extension UIButton {
|
||||
func defaultDuration(type: TapType) -> Speed {
|
||||
switch type {
|
||||
case .alpha(_), .layerGray(_): return .ms300
|
||||
case .pulsate(_), .flash: return .ms200
|
||||
case .pulsate(_, _), .flash: return .ms200
|
||||
case .shake(_): return .ms50
|
||||
case .color, .androidStyle(_): return .s1
|
||||
case .color(_), .androidStyle(_): return .s1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,10 +237,10 @@ extension UIButton {
|
||||
views.forEach {
|
||||
switch type {
|
||||
case .flash: $0.flash(duration: dur)
|
||||
case .color: $0.animationColor(duration: dur)
|
||||
case .pulsate(let new):
|
||||
if new { $0.pulsateNew(visible: visible) }
|
||||
else { $0.pulsate(duration: dur) }
|
||||
case .color(let arr): $0.animationColor(duration: dur, colors: arr)
|
||||
case .pulsate(let new, let value):
|
||||
if new { $0.pulsateNew(visible: visible, value: value) }
|
||||
else { $0.pulsate(duration: dur, value: value) }
|
||||
case .shake(let new):
|
||||
if new { $0.shake() }
|
||||
else { $0.shakeNew(duration: dur) }
|
||||
|
||||
@@ -0,0 +1,716 @@
|
||||
//
|
||||
// DesignTest.swift
|
||||
// FigmaConvertXib
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 28.07.2020.
|
||||
// Copyright © 2020 mrusta. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignFigure: UIView {
|
||||
/// Rectange | Ellipse | Polygon | Star
|
||||
@IBInspectable var figureType: Int = 0
|
||||
@IBInspectable var starRadius: CGFloat = 0
|
||||
@IBInspectable var starCount: Int = 5
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
@IBInspectable var blur: CGFloat = 0.0
|
||||
@IBInspectable var image: UIImage?
|
||||
/// ScaleToFill | Fit | Fill
|
||||
@IBInspectable var imageMode: Int = 1
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
@IBInspectable var grColor1: UIColor?
|
||||
@IBInspectable var grColor2: UIColor?
|
||||
@IBInspectable var grColor3: UIColor?
|
||||
@IBInspectable var grColor4: UIColor?
|
||||
@IBInspectable var grColor5: UIColor?
|
||||
@IBInspectable var grColor6: UIColor?
|
||||
@IBInspectable var grStartPoint: CGPoint = .zero
|
||||
@IBInspectable var grEndPoint: CGPoint = .zero
|
||||
/// Default: Linear
|
||||
@IBInspectable var grRadial: Bool = false
|
||||
@IBInspectable var grDrawsOptions: Bool = true
|
||||
@IBInspectable var grDebug: Bool = false
|
||||
@IBInspectable var grPointPercent: Bool = true
|
||||
@IBInspectable var grBlendMode: Int = 0
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
@IBInspectable var inShColor: UIColor = .clear
|
||||
@IBInspectable var inShRadius: CGFloat = 0.0
|
||||
@IBInspectable var inShOffset: CGSize = .zero
|
||||
@IBInspectable var shColor: UIColor = .clear
|
||||
@IBInspectable var shRadius: CGFloat = 0.0
|
||||
@IBInspectable var shOffset: CGSize = .zero
|
||||
|
||||
func setup() {
|
||||
|
||||
if let foundView = viewWithTag(55) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigure_(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 55
|
||||
d.figureType = figureType
|
||||
d.starRadius = starRadius
|
||||
d.starCount = starCount
|
||||
d.cornerRadius = cornerRadius
|
||||
d.blur = blur
|
||||
d.image = image
|
||||
d.imageMode = imageMode
|
||||
d.fillColor = fillColor
|
||||
d.grColor1 = grColor1
|
||||
d.grColor2 = grColor2
|
||||
d.grColor3 = grColor3
|
||||
d.grColor4 = grColor4
|
||||
d.grColor5 = grColor5
|
||||
d.grColor6 = grColor6
|
||||
d.grStartPoint = grStartPoint
|
||||
d.grEndPoint = grEndPoint
|
||||
d.grRadial = grRadial
|
||||
d.grDrawsOptions = grDrawsOptions
|
||||
d.grDebug = grDebug
|
||||
d.grPointPercent = grPointPercent
|
||||
d.grBlendMode = grBlendMode
|
||||
d.brWidth = brWidth
|
||||
d.brColor = brColor
|
||||
d.brDash = brDash
|
||||
d.inShColor = inShColor
|
||||
d.inShRadius = inShRadius
|
||||
d.inShOffset = inShOffset
|
||||
d.shColor = shColor
|
||||
d.shRadius = shRadius
|
||||
d.shOffset = shOffset
|
||||
insertSubview(d, at: 0)
|
||||
|
||||
if grDebug {
|
||||
if let foundView = viewWithTag(44) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigureDebug(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 44
|
||||
d.grStartPoint = grStartPoint
|
||||
d.grEndPoint = grEndPoint
|
||||
d.grPointPercent = grPointPercent
|
||||
|
||||
insertSubview(d, at: 1)
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutSubviews() { setup() }
|
||||
|
||||
}
|
||||
|
||||
@IBDesignable
|
||||
class DesignFigureDebug: UIView {
|
||||
|
||||
@IBInspectable var grStartPoint: CGPoint = .zero
|
||||
@IBInspectable var grEndPoint: CGPoint = .zero
|
||||
@IBInspectable var grPointPercent: Bool = true
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
super.draw(rect)
|
||||
|
||||
addGradientDebugPoints()
|
||||
}
|
||||
|
||||
func addGradientDebugPoints() {
|
||||
|
||||
var start = grStartPoint
|
||||
var end = grStartPoint
|
||||
|
||||
if grPointPercent {
|
||||
end = CGPoint(x: grEndPoint.x * frame.width, y: grEndPoint.y * frame.height)
|
||||
start = CGPoint(x: grStartPoint.x * frame.width, y: grStartPoint.y * frame.height)
|
||||
}
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
let radius: CGFloat = 5
|
||||
|
||||
context.setBlendMode(CGBlendMode.normal)
|
||||
context.setLineWidth(3.0)
|
||||
|
||||
|
||||
context.setFillColor(UIColor.black.cgColor)
|
||||
|
||||
context.setStrokeColor(UIColor.systemRed.cgColor)
|
||||
|
||||
let circleRect = CGRect(x: start.x - radius,
|
||||
y: start.y - radius,
|
||||
width: radius * 2,
|
||||
height: radius * 2)
|
||||
|
||||
context.fillEllipse(in: circleRect)
|
||||
context.strokeEllipse(in: circleRect)
|
||||
|
||||
context.setStrokeColor(UIColor.green.cgColor)
|
||||
|
||||
let circleRect2 = CGRect(x: end.x - radius,
|
||||
y: end.y - radius,
|
||||
width: radius * 2,
|
||||
height: radius * 2)
|
||||
|
||||
context.fillEllipse(in: circleRect2)
|
||||
context.strokeEllipse(in: circleRect2)
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum DesignFigureType: Int {
|
||||
case rectange = 0
|
||||
case ellipse = 1
|
||||
case polygon = 2
|
||||
case star = 3
|
||||
}
|
||||
|
||||
@IBDesignable
|
||||
class DesignFigure_: UIView {
|
||||
|
||||
@IBInspectable var figureType: Int = 0 /// Rectange Ellipse Polygon Star
|
||||
|
||||
@IBInspectable var starRadius: CGFloat = 0
|
||||
@IBInspectable var starCount: Int = 5
|
||||
//MARK: Radius
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
//MARK: Blur
|
||||
|
||||
@IBInspectable var blur: CGFloat = 0.0
|
||||
|
||||
//MARK: Image
|
||||
|
||||
@IBInspectable var image: UIImage?
|
||||
@IBInspectable var imageMode: Int = 1 /// Scale to fill / Aspect fit / fill
|
||||
|
||||
//MARK: Fill
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
|
||||
//MARK: Gradient
|
||||
|
||||
@IBInspectable var grColor1: UIColor?
|
||||
@IBInspectable var grColor2: UIColor?
|
||||
@IBInspectable var grColor3: UIColor?
|
||||
@IBInspectable var grColor4: UIColor?
|
||||
@IBInspectable var grColor5: UIColor?
|
||||
@IBInspectable var grColor6: UIColor?
|
||||
|
||||
@IBInspectable var grStartPoint: CGPoint = .zero
|
||||
@IBInspectable var grEndPoint: CGPoint = .zero
|
||||
|
||||
@IBInspectable var grRadial: Bool = false /// default: linear
|
||||
@IBInspectable var grDrawsOptions: Bool = true
|
||||
@IBInspectable var grDebug: Bool = false
|
||||
@IBInspectable var grPointPercent: Bool = true
|
||||
@IBInspectable var grBlendMode: Int = 0
|
||||
|
||||
//MARK: Border
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
//MARK: Inner Shadow
|
||||
|
||||
@IBInspectable var inShColor: UIColor = .clear
|
||||
@IBInspectable var inShRadius: CGFloat = 0.0
|
||||
@IBInspectable var inShOffset: CGSize = .zero
|
||||
|
||||
//MARK: Shadow
|
||||
|
||||
@IBInspectable var shColor: UIColor = .clear
|
||||
@IBInspectable var shRadius: CGFloat = 0.0
|
||||
@IBInspectable var shOffset: CGSize = .zero
|
||||
|
||||
|
||||
|
||||
//MARK: - Draw
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
super.draw(rect)
|
||||
|
||||
guard let bezier = figurePath(bounds) else { return }
|
||||
|
||||
addFill(bezier: bezier)
|
||||
|
||||
addImage(bezier: bezier)
|
||||
|
||||
addGradient(bezier: bezier)
|
||||
|
||||
addInnerShadow(bezier: bezier)
|
||||
addBorder()
|
||||
addShadow()
|
||||
|
||||
addBlur()
|
||||
}
|
||||
|
||||
//MARK: - Figure Type
|
||||
|
||||
private func figurePath(_ rect: CGRect) -> UIBezierPath? {
|
||||
|
||||
let starR = starRadius / 50
|
||||
if starCount < 1 { starCount = 1 }
|
||||
|
||||
switch figureType {
|
||||
case 1: return UIBezierPath(ovalIn: rect)
|
||||
case 2: return star(polygon: true, rect: rect, radius: starR, pointsOnStar: starCount)
|
||||
case 3: return star(rect: rect, radius: starR, pointsOnStar: starCount)
|
||||
default: return rectangle(rect: rect, radius: cornerRadius)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Border / Stroke
|
||||
|
||||
private func addBorder() {
|
||||
|
||||
if brWidth < 0 { brWidth = 0 }
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
// brColor.setStroke()
|
||||
|
||||
guard let bezier = figurePath(bounds) else { return }
|
||||
|
||||
context.saveGState()
|
||||
|
||||
if brDash > 0 {
|
||||
|
||||
UIColor.clear.setFill()
|
||||
bezier.fill()
|
||||
|
||||
brColor.setStroke()
|
||||
bezier.lineWidth = brWidth * 2
|
||||
|
||||
let dashPattern : [CGFloat] = [ CGFloat(brDash), CGFloat(brDash)]
|
||||
bezier.setLineDash(dashPattern, count: 2, phase: 0)
|
||||
bezier.stroke()
|
||||
|
||||
} else {
|
||||
|
||||
brColor.setStroke()
|
||||
|
||||
bezier.lineWidth = brWidth * 2
|
||||
bezier.stroke()
|
||||
}
|
||||
|
||||
|
||||
|
||||
bezier.stroke()
|
||||
bezier.stroke()
|
||||
|
||||
context.restoreGState()
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
|
||||
private func addImage(bezier: UIBezierPath) {
|
||||
|
||||
guard let image = image else { return }
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
var f: CGRect = CGRect(x: 0, y: -bounds.height, width: bounds.width, height: bounds.height)
|
||||
|
||||
if imageMode == 1 || imageMode == 2 {
|
||||
|
||||
var w: CGFloat = 0
|
||||
var h: CGFloat = 0
|
||||
|
||||
let percent = bounds.height / image.size.height
|
||||
w = image.size.width * percent
|
||||
h = bounds.height
|
||||
|
||||
if (imageMode == 1) && (w > bounds.width) ||
|
||||
(imageMode == 2) && (bounds.width > w) {
|
||||
|
||||
let percent = bounds.width / image.size.width
|
||||
h = image.size.height * percent
|
||||
w = bounds.width
|
||||
}
|
||||
|
||||
let x = (bounds.width / 2) - (w / 2)
|
||||
let y = (-h + (((bounds.height / 2) - (h / 2)) * (-1)))
|
||||
|
||||
f = CGRect(x: x, y: y, width: w, height: h)
|
||||
}
|
||||
|
||||
context.saveGState()
|
||||
bezier.addClip()
|
||||
context.scaleBy(x: 1, y: -1)
|
||||
context.draw(image.cgImage!, in: f, byTiling: false)
|
||||
context.restoreGState()
|
||||
|
||||
}
|
||||
|
||||
//MARK: - Fill
|
||||
|
||||
private func addFill(bezier: UIBezierPath) {
|
||||
|
||||
guard let fillColor = fillColor else { return }
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
bezier.close()
|
||||
context.saveGState()
|
||||
fillColor.setFill()
|
||||
bezier.fill()
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
//MARK: - Gradient
|
||||
|
||||
private func addGradient(bezier: UIBezierPath) {
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
var colors: [CGColor] = []
|
||||
|
||||
if let c = grColor1 { colors.append(c.cgColor) }
|
||||
if let c = grColor2 { colors.append(c.cgColor) }
|
||||
if let c = grColor3 { colors.append(c.cgColor) }
|
||||
if let c = grColor4 { colors.append(c.cgColor) }
|
||||
if let c = grColor5 { colors.append(c.cgColor) }
|
||||
if let c = grColor6 { colors.append(c.cgColor) }
|
||||
|
||||
if colors.count < 2 {
|
||||
colors.append(UIColor.clear.cgColor)
|
||||
colors.append(UIColor.clear.cgColor)
|
||||
} else if colors.count < 1 {
|
||||
if grColor1 != nil {
|
||||
colors.append(UIColor.clear.cgColor)
|
||||
} else {
|
||||
colors.insert(UIColor.clear.cgColor, at: 0)
|
||||
}
|
||||
}
|
||||
|
||||
guard let gradient = CGGradient(colorsSpace: nil,
|
||||
colors: colors as CFArray,
|
||||
locations: nil) else { return }
|
||||
|
||||
let bMode = CGBlendMode(rawValue: CGBlendMode.RawValue(grBlendMode)) ?? CGBlendMode.sourceAtop
|
||||
context.setBlendMode(bMode)
|
||||
|
||||
let options: CGGradientDrawingOptions =
|
||||
grDrawsOptions ? [ .drawsBeforeStartLocation, .drawsAfterEndLocation ] : [ ]
|
||||
|
||||
var grEndPointR: CGPoint = grEndPoint
|
||||
var grStartPointR: CGPoint = grStartPoint
|
||||
if grPointPercent {
|
||||
grEndPointR = CGPoint(x: (grEndPoint.x * frame.width), y: (grEndPoint.y * frame.height))
|
||||
grStartPointR = CGPoint(x: (grStartPoint.x * frame.width), y: (grStartPoint.y * frame.height))
|
||||
}
|
||||
|
||||
bezier.close()
|
||||
context.saveGState()
|
||||
bezier.addClip()
|
||||
|
||||
if grRadial {
|
||||
|
||||
let x: CGFloat = (grEndPointR.x - grStartPointR.x)
|
||||
let y: CGFloat = (grEndPointR.y - grStartPointR.y)
|
||||
let distance: CGFloat = sqrt((x * x) + (y * y))
|
||||
|
||||
context.drawRadialGradient(gradient,
|
||||
startCenter: grStartPointR,
|
||||
startRadius: 0,
|
||||
endCenter: grStartPointR,
|
||||
endRadius: distance,
|
||||
options: options)
|
||||
} else {
|
||||
|
||||
context.drawLinearGradient(gradient,
|
||||
start: grStartPointR,
|
||||
end: grEndPointR,
|
||||
options: options)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Shadow
|
||||
|
||||
private func addShadow() {
|
||||
|
||||
if shRadius < 0 { shRadius = 0 }
|
||||
|
||||
layer.shadowOffset = shOffset
|
||||
layer.shadowOpacity = 1.0
|
||||
layer.shadowRadius = shRadius
|
||||
layer.shadowColor = shColor.cgColor
|
||||
}
|
||||
|
||||
private func addShadowContext(bezier: UIBezierPath) {
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
bezier.close()
|
||||
|
||||
//// Shadow Declarations
|
||||
let shadow = NSShadow()
|
||||
shadow.shadowColor = shColor
|
||||
shadow.shadowOffset = shOffset
|
||||
shadow.shadowBlurRadius = shRadius * 2
|
||||
|
||||
context.saveGState()
|
||||
|
||||
context.setShadow(offset: shadow.shadowOffset,
|
||||
blur: shadow.shadowBlurRadius,
|
||||
color: (shadow.shadowColor as! UIColor).cgColor)
|
||||
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
//MARK: - Inner Shadow
|
||||
|
||||
private func addInnerShadow(bezier: UIBezierPath) {
|
||||
|
||||
if inShRadius < 0 { inShRadius = 0 }
|
||||
|
||||
let innerShadow = NSShadow()
|
||||
innerShadow.shadowColor = inShColor
|
||||
innerShadow.shadowOffset = inShOffset
|
||||
innerShadow.shadowBlurRadius = inShRadius * 2
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
////// Star Inner Shadow
|
||||
context.saveGState()
|
||||
context.clip(to: bezier.bounds)
|
||||
context.setShadow(offset: .zero, blur: 0)
|
||||
context.setAlpha((innerShadow.shadowColor as! UIColor).cgColor.alpha)
|
||||
context.beginTransparencyLayer(auxiliaryInfo: nil)
|
||||
|
||||
let starOpaqueShadow = (innerShadow.shadowColor as! UIColor).withAlphaComponent(1)
|
||||
context.setShadow(offset: innerShadow.shadowOffset,
|
||||
blur: innerShadow.shadowBlurRadius,
|
||||
color: starOpaqueShadow.cgColor)
|
||||
|
||||
context.setBlendMode(.sourceOut)
|
||||
context.beginTransparencyLayer(auxiliaryInfo: nil)
|
||||
|
||||
starOpaqueShadow.setFill()
|
||||
|
||||
bezier.fill()
|
||||
|
||||
context.endTransparencyLayer()
|
||||
context.endTransparencyLayer()
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Blur
|
||||
|
||||
private func addBlur() {
|
||||
|
||||
guard blur > 0 else { return }
|
||||
|
||||
guard let image = screenShotContext() else { return }
|
||||
|
||||
self.addblur(screen: image, blur: blur)
|
||||
}
|
||||
|
||||
// MARK: Screen Shot Context
|
||||
|
||||
private func screenShotContext() -> UIImage? {
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return nil }
|
||||
guard let cgimage: CGImage = context.makeImage() else { return nil }
|
||||
let image = UIImage(cgImage: cgimage)
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
// MARK: Clear Context
|
||||
|
||||
private func clearContext() {
|
||||
|
||||
let f = CGRect(x: 0, y: 0,
|
||||
width: frame.width * 2,
|
||||
height: frame.height * 2)
|
||||
|
||||
let context = UIGraphicsGetCurrentContext()
|
||||
context?.clear(f)
|
||||
}
|
||||
|
||||
|
||||
private func addblur(screen: UIImage, blur: CGFloat) {
|
||||
|
||||
clearContext()
|
||||
|
||||
func blurImage(image: UIImage) -> UIImage? {
|
||||
|
||||
guard let ciscreen: CIImage = CIImage(image: screen) else { return nil }
|
||||
|
||||
guard let filter: CIFilter = CIFilter(name: "CIGaussianBlur") else { return nil }
|
||||
filter.setDefaults()
|
||||
filter.setValue(ciscreen, forKey: kCIInputImageKey)
|
||||
filter.setValue(blur, forKey: kCIInputRadiusKey)
|
||||
|
||||
|
||||
let bl2 = ((blur * 3) * -1)
|
||||
let bl4 = (blur * 6)
|
||||
|
||||
let contextFrame = CGRect(
|
||||
x: bl2,
|
||||
y: bl2,
|
||||
width: bl4 + image.size.width,
|
||||
height: bl4 + image.size.height
|
||||
)
|
||||
|
||||
// let bl2 = ((blur * 2) * -1)
|
||||
// let bl4 = (blur * 4)
|
||||
// let contextFrame2 = CGRect(x: bl2,
|
||||
// y: bl2,
|
||||
// width: bl4 + (frame.width * 2),
|
||||
// height: bl4 + (frame.height * 2))
|
||||
|
||||
let ciContext = CIContext(options: nil)
|
||||
guard let ci: CIImage = filter.value(forKey: kCIOutputImageKey) as? CIImage else { return nil }
|
||||
guard let cImg = ciContext.createCGImage(ci, from: contextFrame) else { return nil }
|
||||
|
||||
let finalImage = UIImage(cgImage: cImg)
|
||||
|
||||
return finalImage
|
||||
}
|
||||
|
||||
let p2: CGFloat = 1
|
||||
let p4: CGFloat = p2 * 2
|
||||
|
||||
let bl2 = ((blur * p2) * -1)
|
||||
let bl4 = (blur * p4)
|
||||
|
||||
let x: CGFloat = 0
|
||||
let ofW = (x * 1) * -1
|
||||
let ofH = (x * 1) * -1
|
||||
|
||||
let ofW2 = (x * 2)
|
||||
let ofH2 = (x * 2)
|
||||
|
||||
let contextFrame = CGRect(x: bl2 + ofW,
|
||||
y: bl2 + ofH,
|
||||
width: bl4 + ofW2 + frame.width,
|
||||
height: bl4 + ofH2 + frame.height)
|
||||
|
||||
let blurImageView = UIImageView(frame: contextFrame)
|
||||
blurImageView.image = blurImage(image: screen)
|
||||
blurImageView.contentMode = .scaleAspectFill
|
||||
|
||||
|
||||
addSubview(blurImageView)
|
||||
}
|
||||
|
||||
//MARK: - Rectangle Bezier
|
||||
|
||||
func rectangle(rect: CGRect, radius: CGFloat) -> UIBezierPath {
|
||||
|
||||
let r = self.cornerRadius(radius)
|
||||
let w = rect.width
|
||||
let h = rect.height
|
||||
|
||||
let path = UIBezierPath()
|
||||
path.move(to: CGPoint(x: r, y: 0.0))
|
||||
|
||||
path.addLine(to: CGPoint(x: w - r, y: 0.0))
|
||||
path.addArc(withCenter: CGPoint(x: w - r, y: r),
|
||||
radius: r,
|
||||
startAngle: 3.0 * .pi / 2.0,
|
||||
endAngle: 2 * .pi,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: w, y: h - r))
|
||||
path.addArc(withCenter: CGPoint(x: w - r, y: h - r),
|
||||
radius: r,
|
||||
startAngle: 0.0,
|
||||
endAngle: .pi / 2.0,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: r, y: h))
|
||||
path.addArc(withCenter: CGPoint(x: r, y: h - r),
|
||||
radius: r,
|
||||
startAngle: .pi / 2.0,
|
||||
endAngle: .pi,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: 0.0, y: r))
|
||||
path.addArc(withCenter: CGPoint(x: r, y: r),
|
||||
radius: r,
|
||||
startAngle: .pi,
|
||||
endAngle: 3.0 * .pi / 2.0,
|
||||
clockwise: true)
|
||||
|
||||
path.close()
|
||||
return path
|
||||
}
|
||||
|
||||
//MARK: - Star Bezier
|
||||
|
||||
func star(polygon: Bool = false, rect: CGRect, radius: CGFloat, pointsOnStar: Int) -> UIBezierPath {
|
||||
|
||||
let path = UIBezierPath()
|
||||
|
||||
let minSize = max(rect.width, rect.height)
|
||||
var starExtrusion: CGFloat = minSize * 0.18695652173
|
||||
if radius != 0 {
|
||||
starExtrusion = minSize * radius
|
||||
}
|
||||
|
||||
let center: CGPoint = .zero
|
||||
|
||||
var angle: CGFloat = -CGFloat(.pi / 2.0)
|
||||
let angleIncrement = CGFloat(.pi * 2.0 / Double(pointsOnStar))
|
||||
let radius = minSize / 2.0
|
||||
|
||||
var firstPoint = true
|
||||
|
||||
func pointFrom(angle: CGFloat, radius: CGFloat, offset: CGPoint) -> CGPoint {
|
||||
return CGPoint(x: radius * cos(angle) + offset.x,
|
||||
y: radius * sin(angle) + offset.y)
|
||||
}
|
||||
|
||||
for _ in 1...pointsOnStar {
|
||||
|
||||
let point: CGPoint = pointFrom(angle: angle, radius: radius, offset: center)
|
||||
let nextPoint: CGPoint = pointFrom(angle: angle + angleIncrement, radius: radius, offset: center)
|
||||
let midPoint: CGPoint = pointFrom(angle: angle + angleIncrement / 2.0, radius: starExtrusion, offset: center)
|
||||
|
||||
var perY: CGFloat = 1.0
|
||||
var perX: CGFloat = 1.0
|
||||
|
||||
if rect.height < rect.width {
|
||||
perY = (rect.height / minSize)
|
||||
} else {
|
||||
perX = (rect.width / minSize)
|
||||
}
|
||||
|
||||
let p = CGPoint(x: (point.x * perX) + (rect.width / 2.0),
|
||||
y: (point.y * perY) + (rect.height / 2.0))
|
||||
|
||||
let n = CGPoint(x: (nextPoint.x * perX) + (rect.width / 2.0),
|
||||
y: (nextPoint.y * perY) + (rect.height / 2.0))
|
||||
|
||||
let m = CGPoint(x: (midPoint.x * perX) + (rect.width / 2.0),
|
||||
y: (midPoint.y * perY) + (rect.height / 2.0))
|
||||
|
||||
if firstPoint {
|
||||
firstPoint = false
|
||||
path.move(to: p)
|
||||
}
|
||||
|
||||
if !polygon {
|
||||
path.addLine(to: m)
|
||||
}
|
||||
path.addLine(to: n)
|
||||
|
||||
angle += angleIncrement
|
||||
}
|
||||
|
||||
path.close()
|
||||
|
||||
return path
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,510 @@
|
||||
//
|
||||
// DesignTest.swift
|
||||
// FigmaConvertXib
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 28.07.2020.
|
||||
// Copyright © 2020 mrusta. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignnImageView: UIView {
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
@IBInspectable var image: UIImage?
|
||||
@IBInspectable var imageMode: Int = 1
|
||||
@IBInspectable var blur: CGFloat = 0.0
|
||||
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
func setup() {
|
||||
|
||||
if let foundView = viewWithTag(55) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigure_(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 55
|
||||
d.cornerRadius = cornerRadius
|
||||
d.blur = blur
|
||||
d.image = image
|
||||
d.imageMode = imageMode
|
||||
d.fillColor = fillColor
|
||||
d.brWidth = brWidth
|
||||
d.brColor = brColor
|
||||
d.brDash = brDash
|
||||
insertSubview(d, at: 0)
|
||||
|
||||
}
|
||||
|
||||
override func layoutSubviews() { setup() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignnGradientView: UIView {
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
@IBInspectable var grColor1: UIColor?
|
||||
@IBInspectable var grColor2: UIColor?
|
||||
@IBInspectable var grColor3: UIColor?
|
||||
@IBInspectable var grStartPoint: CGPoint = .zero
|
||||
@IBInspectable var grEndPoint: CGPoint = .zero
|
||||
@IBInspectable var grRadial: Bool = false /// default: linear
|
||||
|
||||
func setup() {
|
||||
|
||||
if let foundView = viewWithTag(55) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigure_(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 55
|
||||
d.cornerRadius = cornerRadius
|
||||
// d.blur = blur
|
||||
// d.image = image
|
||||
// d.imageMode = imageMode
|
||||
d.fillColor = fillColor
|
||||
d.brWidth = brWidth
|
||||
d.brColor = brColor
|
||||
d.brDash = brDash
|
||||
|
||||
d.grColor1 = grColor1
|
||||
d.grColor2 = grColor2
|
||||
d.grColor3 = grColor3
|
||||
// d.grColor4 = grColor4
|
||||
// d.grColor5 = grColor5
|
||||
// d.grColor6 = grColor6
|
||||
d.grStartPoint = grStartPoint
|
||||
d.grEndPoint = grEndPoint
|
||||
d.grRadial = grRadial
|
||||
// d.grDrawsOptions = grDrawsOptions
|
||||
// d.grDebug = grDebug
|
||||
// d.grPointPercent = grPointPercent
|
||||
// d.grBlendMode = grBlendMode
|
||||
|
||||
insertSubview(d, at: 0)
|
||||
|
||||
}
|
||||
|
||||
override func layoutSubviews() { setup() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignnShadowView: UIView {
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
@IBInspectable var shColor: UIColor = .clear
|
||||
@IBInspectable var shRadius: CGFloat = 0.0
|
||||
@IBInspectable var shOffset: CGSize = .zero
|
||||
|
||||
|
||||
func setup() {
|
||||
|
||||
if let foundView = viewWithTag(55) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigure_(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 55
|
||||
d.cornerRadius = cornerRadius
|
||||
// d.blur = blur
|
||||
// d.image = image
|
||||
// d.imageMode = imageMode
|
||||
d.fillColor = fillColor
|
||||
d.brWidth = brWidth
|
||||
d.brColor = brColor
|
||||
d.brDash = brDash
|
||||
|
||||
|
||||
d.shColor = shColor
|
||||
d.shRadius = shRadius
|
||||
d.shOffset = shOffset
|
||||
insertSubview(d, at: 0)
|
||||
|
||||
}
|
||||
|
||||
override func layoutSubviews() { setup() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignnView: UIView {
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
func setup() {
|
||||
|
||||
if let foundView = viewWithTag(55) {
|
||||
foundView.removeFromSuperview()
|
||||
}
|
||||
|
||||
let d = DesignFigure_(frame: bounds)
|
||||
d.backgroundColor = .clear
|
||||
d.tag = 55
|
||||
d.cornerRadius = cornerRadius
|
||||
// d.blur = blur
|
||||
// d.image = image
|
||||
// d.imageMode = imageMode
|
||||
d.fillColor = fillColor
|
||||
d.brWidth = brWidth
|
||||
d.brColor = brColor
|
||||
d.brDash = brDash
|
||||
insertSubview(d, at: 0)
|
||||
|
||||
}
|
||||
|
||||
override func layoutSubviews() { setup() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@IBDesignable
|
||||
class DesignFillView_: UIView {
|
||||
|
||||
|
||||
@IBInspectable var cornerRadius: CGFloat = 0.0
|
||||
|
||||
//MARK: Blur
|
||||
|
||||
@IBInspectable var blur: CGFloat = 0.0
|
||||
|
||||
//MARK: Image
|
||||
|
||||
@IBInspectable var image: UIImage?
|
||||
@IBInspectable var imageMode: Int = 1 /// Scale to fill / Aspect fit / fill
|
||||
|
||||
//MARK: Fill
|
||||
|
||||
@IBInspectable var fillColor: UIColor?
|
||||
//MARK: Border
|
||||
|
||||
@IBInspectable var brColor: UIColor = .clear
|
||||
@IBInspectable var brWidth: CGFloat = 0.0
|
||||
@IBInspectable var brDash: Int = 0
|
||||
|
||||
|
||||
|
||||
@IBInspectable var shColor: UIColor = .clear
|
||||
@IBInspectable var shRadius: CGFloat = 0.0
|
||||
@IBInspectable var shOffset: CGSize = .zero
|
||||
|
||||
//MARK: - Draw
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
super.draw(rect)
|
||||
|
||||
guard let bezier = figurePath(bounds) else { return }
|
||||
|
||||
addFill(bezier: bezier)
|
||||
addImage(bezier: bezier)
|
||||
addBorder()
|
||||
addShadow()
|
||||
addBlur()
|
||||
}
|
||||
|
||||
//MARK: - Figure Type
|
||||
|
||||
private func figurePath(_ rect: CGRect) -> UIBezierPath? {
|
||||
return rectangle(rect: rect, radius: cornerRadius)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private func addImage(bezier: UIBezierPath) {
|
||||
|
||||
guard let image = image else { return }
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
var f: CGRect = CGRect(x: 0, y: -bounds.height, width: bounds.width, height: bounds.height)
|
||||
|
||||
if imageMode == 1 || imageMode == 2 {
|
||||
|
||||
var w: CGFloat = 0
|
||||
var h: CGFloat = 0
|
||||
|
||||
let percent = bounds.height / image.size.height
|
||||
w = image.size.width * percent
|
||||
h = bounds.height
|
||||
|
||||
if (imageMode == 1) && (w > bounds.width) ||
|
||||
(imageMode == 2) && (bounds.width > w) {
|
||||
|
||||
let percent = bounds.width / image.size.width
|
||||
h = image.size.height * percent
|
||||
w = bounds.width
|
||||
}
|
||||
|
||||
let x = (bounds.width / 2) - (w / 2)
|
||||
let y = (-h + (((bounds.height / 2) - (h / 2)) * (-1)))
|
||||
|
||||
f = CGRect(x: x, y: y, width: w, height: h)
|
||||
}
|
||||
|
||||
context.saveGState()
|
||||
bezier.addClip()
|
||||
context.scaleBy(x: 1, y: -1)
|
||||
context.draw(image.cgImage!, in: f, byTiling: false)
|
||||
context.restoreGState()
|
||||
|
||||
}
|
||||
|
||||
//MARK: - Fill
|
||||
|
||||
private func addFill(bezier: UIBezierPath) {
|
||||
|
||||
guard let fillColor = fillColor else { return }
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
bezier.close()
|
||||
context.saveGState()
|
||||
fillColor.setFill()
|
||||
bezier.fill()
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
|
||||
//MARK: - Shadow
|
||||
|
||||
private func addShadow() {
|
||||
|
||||
if shRadius < 0 { shRadius = 0 }
|
||||
|
||||
layer.shadowOffset = shOffset
|
||||
layer.shadowOpacity = 1.0
|
||||
layer.shadowRadius = shRadius
|
||||
layer.shadowColor = shColor.cgColor
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Border / Stroke
|
||||
|
||||
private func addBorder() {
|
||||
|
||||
if brWidth < 0 { brWidth = 0 }
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
||||
|
||||
// brColor.setStroke()
|
||||
|
||||
guard let bezier = figurePath(bounds) else { return }
|
||||
|
||||
context.saveGState()
|
||||
|
||||
if brDash > 0 {
|
||||
|
||||
UIColor.clear.setFill()
|
||||
bezier.fill()
|
||||
|
||||
brColor.setStroke()
|
||||
bezier.lineWidth = brWidth * 2
|
||||
|
||||
let dashPattern : [CGFloat] = [ CGFloat(brDash), CGFloat(brDash)]
|
||||
bezier.setLineDash(dashPattern, count: 2, phase: 0)
|
||||
bezier.stroke()
|
||||
|
||||
} else {
|
||||
|
||||
brColor.setStroke()
|
||||
|
||||
bezier.lineWidth = brWidth * 2
|
||||
bezier.stroke()
|
||||
}
|
||||
|
||||
|
||||
|
||||
bezier.stroke()
|
||||
bezier.stroke()
|
||||
|
||||
context.restoreGState()
|
||||
context.restoreGState()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Blur
|
||||
|
||||
private func addBlur() {
|
||||
|
||||
guard blur > 0 else { return }
|
||||
|
||||
guard let image = screenShotContext() else { return }
|
||||
|
||||
self.addblur(screen: image, blur: blur)
|
||||
}
|
||||
|
||||
// MARK: Screen Shot Context
|
||||
|
||||
private func screenShotContext() -> UIImage? {
|
||||
|
||||
guard let context = UIGraphicsGetCurrentContext() else { return nil }
|
||||
guard let cgimage: CGImage = context.makeImage() else { return nil }
|
||||
let image = UIImage(cgImage: cgimage)
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
// MARK: Clear Context
|
||||
|
||||
private func clearContext() {
|
||||
|
||||
let f = CGRect(x: 0, y: 0,
|
||||
width: frame.width * 2,
|
||||
height: frame.height * 2)
|
||||
|
||||
let context = UIGraphicsGetCurrentContext()
|
||||
context?.clear(f)
|
||||
}
|
||||
|
||||
|
||||
private func addblur(screen: UIImage, blur: CGFloat) {
|
||||
|
||||
clearContext()
|
||||
|
||||
func blurImage(image: UIImage) -> UIImage? {
|
||||
|
||||
guard let ciscreen: CIImage = CIImage(image: screen) else { return nil }
|
||||
|
||||
guard let filter: CIFilter = CIFilter(name: "CIGaussianBlur") else { return nil }
|
||||
filter.setDefaults()
|
||||
filter.setValue(ciscreen, forKey: kCIInputImageKey)
|
||||
filter.setValue(blur, forKey: kCIInputRadiusKey)
|
||||
|
||||
|
||||
let bl2 = ((blur * 3) * -1)
|
||||
let bl4 = (blur * 6)
|
||||
|
||||
let contextFrame = CGRect(
|
||||
x: bl2,
|
||||
y: bl2,
|
||||
width: bl4 + image.size.width,
|
||||
height: bl4 + image.size.height
|
||||
)
|
||||
|
||||
// let bl2 = ((blur * 2) * -1)
|
||||
// let bl4 = (blur * 4)
|
||||
// let contextFrame2 = CGRect(x: bl2,
|
||||
// y: bl2,
|
||||
// width: bl4 + (frame.width * 2),
|
||||
// height: bl4 + (frame.height * 2))
|
||||
|
||||
let ciContext = CIContext(options: nil)
|
||||
guard let ci: CIImage = filter.value(forKey: kCIOutputImageKey) as? CIImage else { return nil }
|
||||
guard let cImg = ciContext.createCGImage(ci, from: contextFrame) else { return nil }
|
||||
|
||||
let finalImage = UIImage(cgImage: cImg)
|
||||
|
||||
return finalImage
|
||||
}
|
||||
|
||||
let p2: CGFloat = 1
|
||||
let p4: CGFloat = p2 * 2
|
||||
|
||||
let bl2 = ((blur * p2) * -1)
|
||||
let bl4 = (blur * p4)
|
||||
|
||||
let x: CGFloat = 0
|
||||
let ofW = (x * 1) * -1
|
||||
let ofH = (x * 1) * -1
|
||||
|
||||
let ofW2 = (x * 2)
|
||||
let ofH2 = (x * 2)
|
||||
|
||||
let contextFrame = CGRect(x: bl2 + ofW,
|
||||
y: bl2 + ofH,
|
||||
width: bl4 + ofW2 + frame.width,
|
||||
height: bl4 + ofH2 + frame.height)
|
||||
|
||||
let blurImageView = UIImageView(frame: contextFrame)
|
||||
blurImageView.image = blurImage(image: screen)
|
||||
blurImageView.contentMode = .scaleAspectFill
|
||||
|
||||
|
||||
addSubview(blurImageView)
|
||||
}
|
||||
|
||||
//MARK: - Rectangle Bezier
|
||||
|
||||
func rectangle(rect: CGRect, radius: CGFloat) -> UIBezierPath {
|
||||
|
||||
let r = self.cornerRadius(radius)
|
||||
let w = rect.width
|
||||
let h = rect.height
|
||||
|
||||
let path = UIBezierPath()
|
||||
path.move(to: CGPoint(x: r, y: 0.0))
|
||||
|
||||
path.addLine(to: CGPoint(x: w - r, y: 0.0))
|
||||
path.addArc(withCenter: CGPoint(x: w - r, y: r),
|
||||
radius: r,
|
||||
startAngle: 3.0 * .pi / 2.0,
|
||||
endAngle: 2 * .pi,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: w, y: h - r))
|
||||
path.addArc(withCenter: CGPoint(x: w - r, y: h - r),
|
||||
radius: r,
|
||||
startAngle: 0.0,
|
||||
endAngle: .pi / 2.0,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: r, y: h))
|
||||
path.addArc(withCenter: CGPoint(x: r, y: h - r),
|
||||
radius: r,
|
||||
startAngle: .pi / 2.0,
|
||||
endAngle: .pi,
|
||||
clockwise: true)
|
||||
|
||||
path.addLine(to: CGPoint(x: 0.0, y: r))
|
||||
path.addArc(withCenter: CGPoint(x: r, y: r),
|
||||
radius: r,
|
||||
startAngle: .pi,
|
||||
endAngle: 3.0 * .pi / 2.0,
|
||||
clockwise: true)
|
||||
|
||||
path.close()
|
||||
return path
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// Label.swift
|
||||
// PlusBank
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 25.02.2021.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UILabel {
|
||||
|
||||
func addUnderline(size: Int = 1) {
|
||||
|
||||
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self.text ?? "")
|
||||
attributeString.addAttribute(.underlineStyle, value: size, range: NSMakeRange(0, attributeString.length))
|
||||
|
||||
self.attributedText = attributeString
|
||||
}
|
||||
}
|
||||
|
||||
func sizeToFitLabel(text: String?, font: UIFont? = nil, lines: Int = 99, x: CGFloat = 16.0) -> CGFloat {
|
||||
return TableAdapterCellData.classCalculateLabel(text: text, font: font, lines: lines, x: x).height
|
||||
}
|
||||
@@ -68,7 +68,7 @@ extension StoryboardController: ContainerControllerDelegate {
|
||||
let container = ContainerController(addTo: self, layout: layoutC)
|
||||
container.view.cornerRadius = radius
|
||||
container.view.addShadow()
|
||||
container.view.tag = 12
|
||||
container.view.tag = 13
|
||||
if let delegate = delegate {
|
||||
container.delegate = delegate
|
||||
} else {
|
||||
@@ -105,14 +105,16 @@ extension StoryboardController: ContainerControllerDelegate {
|
||||
container.backView?.addSubview(back)
|
||||
}
|
||||
|
||||
let table = TableAdapterView(frame: CGRect(x: 0, y: 0, width: ContainerDevice.width, height: 0), style: .plain)
|
||||
table.indicatorStyle = .default
|
||||
// container.add(scrollView: addCollectionView())
|
||||
|
||||
|
||||
let table = TableAdapterView(frame: CGRect(x: 0, y: 0, width: ContainerDevice.width, height: 0), style: .plain)
|
||||
table.indicatorStyle = .default
|
||||
// container.add(scrollView: addCollectionView())
|
||||
|
||||
if let items = items {
|
||||
table.set(items: items )
|
||||
|
||||
container.add(scrollView: table)
|
||||
}
|
||||
container.add(scrollView: table)
|
||||
|
||||
container.move(type: .hide, animation: false)
|
||||
|
||||
@@ -130,4 +132,8 @@ extension StoryboardController: ContainerControllerDelegate {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func containerControllerHandlePan(_ containerController: ContainerController, pan: UIPanGestureRecognizer) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIColor {
|
||||
var redValue: CGFloat{ return CIColor(color: self).red }
|
||||
var greenValue: CGFloat{ return CIColor(color: self).green }
|
||||
var blueValue: CGFloat{ return CIColor(color: self).blue }
|
||||
var alphaValue: CGFloat{ return CIColor(color: self).alpha }
|
||||
}
|
||||
|
||||
class Colors {
|
||||
|
||||
class func hex(_ hex: Int) -> UIColor {
|
||||
let mask = 0xFF
|
||||
let r = CGFloat((hex >> 16) & mask) / 255
|
||||
let g = CGFloat((hex >> 8) & mask) / 255
|
||||
let b = CGFloat((hex) & mask) / 255
|
||||
return UIColor(red: r, green: g, blue: b, alpha: 1)
|
||||
}
|
||||
|
||||
|
||||
class func hexStr(_ hex: String) -> UIColor {
|
||||
let input = hex.replacingOccurrences(of: "#", with: "").uppercased()
|
||||
var a: CGFloat = 1.0, r: CGFloat = 0.0, b: CGFloat = 0.0, g: CGFloat = 0.0
|
||||
func colorComponent(from string: String, start: Int, length: Int) -> CGFloat {
|
||||
let substring = (string as NSString).substring(with: NSRange(location: start, length: length))
|
||||
let fullHex = length == 2 ? substring : "\(substring)\(substring)"
|
||||
var hexComponent: UInt64 = 0
|
||||
Scanner(string: fullHex).scanHexInt64(&hexComponent)
|
||||
return CGFloat(Double(hexComponent) / 255.0)
|
||||
}
|
||||
switch (input.count) {
|
||||
case 3 /* #RGB */:
|
||||
r = colorComponent(from: input, start: 0, length: 1)
|
||||
g = colorComponent(from: input, start: 1, length: 1)
|
||||
b = colorComponent(from: input, start: 2, length: 1)
|
||||
case 4 /* #ARGB */:
|
||||
a = colorComponent(from: input, start: 0, length: 1)
|
||||
r = colorComponent(from: input, start: 1, length: 1)
|
||||
g = colorComponent(from: input, start: 2, length: 1)
|
||||
b = colorComponent(from: input, start: 3, length: 1)
|
||||
case 6 /* #RRGGBB */:
|
||||
r = colorComponent(from: input, start: 0, length: 2)
|
||||
g = colorComponent(from: input, start: 2, length: 2)
|
||||
b = colorComponent(from: input, start: 4, length: 2)
|
||||
case 8 /* #AARRGGBB */:
|
||||
a = colorComponent(from: input, start: 0, length: 2)
|
||||
r = colorComponent(from: input, start: 2, length: 2)
|
||||
g = colorComponent(from: input, start: 4, length: 2)
|
||||
b = colorComponent(from: input, start: 6, length: 2)
|
||||
default:
|
||||
break
|
||||
}
|
||||
return UIColor(red: r, green: g, blue: b, alpha: a)
|
||||
}
|
||||
|
||||
class func rgba( _ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat) -> UIColor {
|
||||
return UIColor(red: red / 255, green: green / 255, blue: blue / 255, alpha: alpha)
|
||||
}
|
||||
|
||||
class func rgb( _ red: CGFloat, _ green: CGFloat, _ blue: CGFloat) -> UIColor {
|
||||
return rgba(red, green, blue, 1)
|
||||
}
|
||||
|
||||
class func grayLevel(_ gray: CGFloat) -> UIColor {
|
||||
return rgb(gray * 255, gray * 255, gray * 255)
|
||||
}
|
||||
|
||||
class func blackAlpha(_ alpha: CGFloat) -> UIColor {
|
||||
return rgba(0, 0, 0, alpha)
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
static public let lightGray = blackAlpha(0.1)
|
||||
static public let slightlyDark = blackAlpha(0.3)
|
||||
static public let halfBlack = blackAlpha(0.5)
|
||||
|
||||
static public let black = grayLevel(0) // 0 %
|
||||
static public let gray = grayLevel(127) // 49 %
|
||||
static public let lightInactiveGray = grayLevel(178) // 69 %
|
||||
static public let silver = grayLevel(229) // 89 %
|
||||
static public let inactiveGray = grayLevel(246) // 96 %
|
||||
static public let white = grayLevel(255) // 100 %
|
||||
|
||||
static public let transparentGray = rgba(225, 225, 225, 0.3)
|
||||
static public let lightOrange = rgba(255, 105, 0, 0.1)
|
||||
|
||||
static public let red = rgb(255, 59, 48)
|
||||
static public let blue = rgb(44, 174, 233)
|
||||
static public let yellow = rgb(254, 219, 6)
|
||||
static public let orange = rgb(255, 105, 0)
|
||||
static public let purple = rgb(128, 0, 128)
|
||||
static public let gold = rgb(226, 201, 127)
|
||||
static public let beige = rgb(245, 245, 220)
|
||||
static public let brand = rgb(255, 105, 0)
|
||||
static public let approveGreen = rgb(49, 183, 0)
|
||||
static public let darkBlue = rgb(74, 144, 226)
|
||||
static public let semidarkBlue = rgb(0, 107, 202)
|
||||
static public let darkGray = rgb(142, 142, 147)
|
||||
static public let lightYellow = rgb(254, 229, 6)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Font.swift
|
||||
// ContainerControllerSwift_Example
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 08.08.2024.
|
||||
// Copyright © 2024 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIFont {
|
||||
class func mediumSystemFont(ofSize pointSize: CGFloat) -> UIFont {
|
||||
return self.systemFont(ofSize: pointSize, weight: .medium)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Label.swift
|
||||
// PlusBank
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 25.02.2021.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UILabel {
|
||||
|
||||
func addUnderline(size: Int = 1) {
|
||||
|
||||
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self.text ?? "")
|
||||
attributeString.addAttribute(.underlineStyle, value: size, range: NSMakeRange(0, attributeString.length))
|
||||
|
||||
self.attributedText = attributeString
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func sizeToFitLabel(text: String?, font: UIFont? = nil, lines: Int = 99, padding: CGFloat = 0.0) -> CGSize {
|
||||
|
||||
let label = UILabel(frame: .init(x: 0, y: 0, width: 60, height: 15))
|
||||
label.font = font
|
||||
label.numberOfLines = lines
|
||||
label.text = text ?? ""
|
||||
label.sizeToFit()
|
||||
return .init(width: label.frame.size.width + (padding * 2), height: label.frame.size.height)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// UIView+AutoLayout.swift
|
||||
// ContainerControllerSwift_Example
|
||||
//
|
||||
// Created by Рустам Мотыгуллин on 12.08.2024.
|
||||
// Copyright © 2024 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
//MARK: - Round
|
||||
extension UIView {
|
||||
|
||||
|
||||
|
||||
func addConstraintsZerro(view: UIView?, superView: UIView?, padding: CGFloat) {
|
||||
|
||||
|
||||
// let padding: CGFloat = 0
|
||||
|
||||
if let mainCardView = superView, let view3 = view {
|
||||
|
||||
|
||||
view3.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
|
||||
let bottomConstraint = NSLayoutConstraint(
|
||||
item: mainCardView,
|
||||
attribute: NSLayoutConstraint.Attribute.bottom,
|
||||
relatedBy: NSLayoutConstraint.Relation.equal,
|
||||
toItem: view3,
|
||||
attribute: NSLayoutConstraint.Attribute.bottom,
|
||||
multiplier: 1,
|
||||
constant: (padding * -1)
|
||||
)
|
||||
|
||||
let trailingConstraint = NSLayoutConstraint(
|
||||
item: mainCardView,
|
||||
attribute: NSLayoutConstraint.Attribute.trailing,
|
||||
relatedBy: NSLayoutConstraint.Relation.equal,
|
||||
toItem: view3,
|
||||
attribute: NSLayoutConstraint.Attribute.trailing,
|
||||
multiplier: 1,
|
||||
constant: (padding * -1)
|
||||
)
|
||||
|
||||
let topConstraint = NSLayoutConstraint(
|
||||
item: mainCardView,
|
||||
attribute: NSLayoutConstraint.Attribute.top,
|
||||
relatedBy: NSLayoutConstraint.Relation.equal,
|
||||
toItem: view3,
|
||||
attribute: NSLayoutConstraint.Attribute.top,
|
||||
multiplier: 1,
|
||||
constant: padding
|
||||
)
|
||||
|
||||
let leadingConstraint = NSLayoutConstraint(
|
||||
item: mainCardView,
|
||||
attribute: NSLayoutConstraint.Attribute.leading,
|
||||
relatedBy: NSLayoutConstraint.Relation.equal,
|
||||
toItem: view3,
|
||||
attribute: NSLayoutConstraint.Attribute.leading,
|
||||
multiplier: 1,
|
||||
constant: padding
|
||||
)
|
||||
|
||||
addConstraints([bottomConstraint, trailingConstraint, topConstraint, leadingConstraint])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user