🌈 Highly customizable Core Graphics based gradient view for iOS

Overview

MKGradientView

Language Platform License Version Carthage compatible

Highly customizable Core Graphics based gradient view

MKGradientView

Features

Available gradient types:

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

Installation

CocoaPods

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

pod 'MKGradientView'

Carthage

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

github "maxkonovalov/MKGradientView"

Usage

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

Code

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)
view.addSubview(gradientView)

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]
view.addSubview(gradientView)

Performance

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.

Requirements

  • iOS 8.0
  • Xcode 10, Swift 4+

License

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

You might also like...
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.
A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Overview Description Requirements Installation Usage Author License Description XMLParser lets you convert a pure Swift dictionary into XML string and

πŸ“° Consistent & accessible visual styling on iOS with support for Dynamic Type.
πŸ“° Consistent & accessible visual styling on iOS with support for Dynamic Type.

TypographyKit makes it easy to define typography styles and colour palettes in your iOS app helping you achieve visual consistency in your design as w

UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics
UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics

The YLProgressBar is an UIProgressView replacement with a highly and fully customizable animated progress bar in pure Core Graphics. It has been imple

Simple refresh control for iOS based on SpriteKit and Core Graphics
Simple refresh control for iOS based on SpriteKit and Core Graphics

RainyRefreshControl Simple refresh control for iOS based on SpriteKit and Core Graphics. Project inspired by concept of Yup Nguyen Installation Instal

πŸ“Š A customizable gradient progress bar (UIProgressView).
πŸ“Š A customizable gradient progress bar (UIProgressView).

GradientProgressBar A customizable gradient progress bar (UIProgressView). Inspired by iOS 7 Progress Bar from Codepen. Example To run the example pro

βŒ›οΈA customizable animated gradient loading bar.
βŒ›οΈA customizable animated gradient loading bar.

GradientLoadingBar A customizable animated gradient loading bar. Inspired by iOS 7 Progress Bar from Codepen. Example To run the example project, clon

βŒ›οΈA customizable animated gradient loading bar.
βŒ›οΈA customizable animated gradient loading bar.

GradientLoadingBar A customizable animated gradient loading bar. Inspired by iOS 7 Progress Bar from Codepen. Example To run the example project, clon

πŸ“Š A customizable gradient progress bar (UIProgressView).
πŸ“Š A customizable gradient progress bar (UIProgressView).

GradientProgressBar A customizable gradient progress bar (UIProgressView). Inspired by iOS 7 Progress Bar from Codepen. Example To run the example pro

Create Live Graphics in SwiftUI (iOS, tvOS & macOS)

PixelUI import SwiftUI import PixelUI struct ContentView: View { var body: some View { GeometryReader { geo in

Powerful and easy-to-use vector graphics Swift library with SVG support
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Powerful and easy-to-use vector graphics Swift library with SVG support
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Easily Manage Graphics in Xcode Projects
Easily Manage Graphics in Xcode Projects

Introduction Challenges Managing Graphic Assets Manually Create Multiple Sizes Store Generated Image Files What If You Had... Care-Free Graphic Manage

Simple and highly customizable iOS tag list view, in Swift.
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

Simple and highly customizable iOS tag list view, in Swift.
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

Highly customizable iOS tags view [input, edit, dynamic, tag, token, field, NSTokenField]
Highly customizable iOS tags view [input, edit, dynamic, tag, token, field, NSTokenField]

RKTagsView Highly customizable iOS tags view (like NSTokenField). Supports horizontal and vertical direction, editing, multiple selection, Auto Layout

Simple and highly customizable iOS tag list view, in Swift.
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

A paging view controller with a highly customizable menu ✨
A paging view controller with a highly customizable menu ✨

Getting Started | Customization | Installation Features Parchment lets you page between view controllers while showing any type of generic indicator t

Easy to use, highly customizable gauge view
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

Comments
  • Fix for crash on lack of background color

    Fix for crash on lack of background color

    If the MKGradientView didn't have a background color, it would crash (unexpected nil). Maybe only a Swift 4 thing but idk. Now the example on the readme actually works!

    opened by escherwd 2
  • Crash with release build on Xcode 11.4

    Crash with release build on Xcode 11.4

    I'm seeing a crash that I can only reproduce on the release build. Running on simulator does not result in a crash. Here's the info:

    EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000112b54020 MKGradientView MKGradientGenerator.swift - Line 58 specialized static GradientGenerator.gradientImage(type:size:colors:colors2:locations:locations2:startPoint:endPoint:startPoint2:endPoint2:scale:) + 58

    Any ideas? This just started happening when building app with latest Xcode 11.4.

    opened by yosoycody 1
  • Color distribution according to percentage?

    Color distribution according to percentage?

    I'm trying to achieve a 3-colored gradient view where color distribution can be configured. I understand that your view & CGGradientLayer both have locations property but I'm still not able to achieve the results needed. I'm trying to achieve this: http://i.stack.imgur.com/HN73s.png For further details http://stackoverflow.com/questions/33788533/swift-2-1-cagradientlayer-color-location-distribution

    Can you help me achieve this?

    opened by AbidHussainCom 1
  • Specify color space when generating gradient

    Specify color space when generating gradient

    When I changed to use P3 wide colors in our app, I noticed that the gradients didn't use that color space.

    I looked through the code and saw that MKGradientGenerator uses CGColorSpaceCreateDeviceRGB. I changed that to CGColorSpace(name: CGColorSpace.displayP3) and the gradient was displaying in P3.

    Maybe you can add a parameter (with default value) or get the color space from the start/end color?

    Thanks!

    enhancement 
    opened by Thomasch 1
Owner
Max Konovalov
iOS Developer πŸ‘¨πŸ»β€πŸ’»
Max Konovalov
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 2, 2023
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

Marko Tadić 82 Dec 27, 2022
🎞 Powerful gradient animations made simple for iOS.

AnimatedGradientView is a UIView subclass which makes it simple to add animated gradients to your iOS app. It is written purely in Swift. Further docu

Ross Butler 431 Dec 12, 2022
The code for my CoreGraphics+CoreAnimation talk, held during the 2012 iOS Game Design Seminar at the Technical University Munich.

PKCoreTechniques ======= Core Techniques is the result of a presentation I held at the Technical University of Munich during the 'iOS Game Design Semi

Philip Kluz 143 Sep 21, 2022
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
Visual designing library for iOS & OSX

ProcessingKit ProcessingKit is a Visual designing library for iOS & OSX. ProcessingKit written in Swift ?? and you can write like processing. Demo Dem

Atsuya Sato 333 Nov 12, 2022
GraphLayout - iOS UI controls to visualize graphs. Powered by Graphviz

GraphLayout GraphLayout - UI controls for graph visualization. It is powered by Graphviz. Graph visualization is a way of representing structural info

null 97 Sep 26, 2022