git.iko.soy/dashared/hookah-tau
on develop help sign in
dashared/hookah-tau/Hookah Tau/Extenstions+IBDesignable.swift
25 lines 971 B history raw
1//
2// Extenstions+IBDesignable.swift
3// Hookah Tau
4//
5// Created by cstore on 16/11/2019.
6// Copyright © 2019 Daria Rednikina. All rights reserved.
7//
9import UIKit
11@IBDesignable class RadialGradientView: UIView {
13 @IBInspectable var outsideColor: UIColor = UIColor.red
14 @IBInspectable var insideColor: UIColor = UIColor.clear.withAlphaComponent(0)
16 override func draw(_ rect: CGRect) {
17 let colors = [insideColor.cgColor, outsideColor.cgColor] as CFArray
18 let endRadius = sqrt(pow(frame.width/2, 2) + pow(frame.height/2, 2))
19 let center = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2)
20 let gradient = CGGradient(colorsSpace: nil, colors: colors, locations: nil)
21 let context = UIGraphicsGetCurrentContext()
23 context?.drawRadialGradient(gradient!, startCenter: center, startRadius: 0.0, endCenter: center, endRadius: endRadius, options: CGGradientDrawingOptions.drawsBeforeStartLocation)
24 }