Swiftpack.co -  maxkonovalov/MKGradientView as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
🌈 Highly customizable Core Graphics based gradient view for iOS
.package(url: "https://github.com/maxkonovalov/MKGradientView.git", from: "2.0.2")


Language Platform License Version Carthage compatible

Highly customizable Core Graphics based gradient view



Available gradient types:

  • Linear (Axial)
  • Radial (Circular)
  • Conical (Angular)
  • Bilinear (Four Point)



To install MKGradientView via CocoaPods, add the following line to your Podfile:

pod 'MKGradientView'


To install MKGradientView via Carthage, add the following line to your Cartfile:

github "maxkonovalov/MKGradientView"


See example Xcode project

Interface Builder

Simple 2-color gradients can be set up in Interface Builder. Set your view's custom class to MKGradientView.

You can specify the following custom inspectable properties:

  • Gradient Type
  • Start Color
  • End Color
  • Start Point
  • End Point


let gradientView = GradientView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
gradientView.type = .linear
gradientView.colors = [.red, .green]
gradientView.locations = [0, 1]
gradientView.startPoint = CGPoint(x: 0, y: 0)
gradientView.endPoint = CGPoint(x: 1, y: 1)

To set up a Bilinear gradient, you need to specify colors2 array:

let gradientView = GradientView(frame: CGRect(x: 100, y: 0, width: 100, height: 100))
gradientView.type = .bilinear
gradientView.colors = [.red, .yellow]
gradientView.colors2 = [.blue, .cyan]


GradientLayer is image-backed, and the algorithm performance behind it highly depends on the size of the generated image. To speed it up, minimum possible layer size should be used. It can be adjusted with GradientLayer's contentsScale property, 1.0 being an optimal value for performance/quality balance. Use lower values like 0.5 to speed up rendering time or set it equal to UIScreen.main.scale to get precise result.


  • iOS 8.0
  • Xcode 10, Swift 4+


MKGradientView is available under the MIT license. See the LICENSE file for more info.


Stars: 160
Last commit: 22 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API