Latest 0.2.0
License MIT
Platforms ios 10.0, requires ARC
Frameworks UIKit

A tag cloud view with gravity for iOS. It is a rewritten version of in swift 3 with UIdynamics gravity support (Thanks for this nice tutorial for UI dynamics –

You may play around GravityTagCloudView on Apptize.

Fill some bugs in the iPhone SE screen:

(To measure the performance of UIDynamic, you may include konoma/fps-counter in your project.)

Playground example:

Play with random font size:


Play with weighted font size and fill the entire view with tags:


///TODO: gif

///TODO: example for no gravity, random font size

How To Get Started

Installation with CocoaPods

Edit your Podfile and add DKTagCloudView, (TODO add to offical pod spec):

pod 'GravityTagCloudView', '~> 0.2.0'

Add import GravityTagCloudView to the top of classes that will use it.

Create instances (Also supports xib/storyboard) :

let gravityTagCloudView = GravityTagCloudView()

gravityTagCloudView.frame = CGRect(x: 0, y: 0, width: 360, height: 200)


Setup items:

If you want the size of the label is propertional to their weight, please set labelSizeType properties to kWeighted and assign array to titleWeights:

gravityTagCloudView.labelSizeType = .weighted
gravityTagCloudView.titleWeights = [["title":"elephant", "weight":10],
                                    ["title":"cow", "weight":7],
                                    ["title":"horse", "weight":7],
                                    ["title":"dog", "weight":5],
                                    ["title":"cat", "weight":3],
                                    ["title":"rat", "weight":1],
                                    ["title":"mouse", "weight":1],




gravityTagCloudView.tagClickBlock = { title, tag -> Void in       
  print("tag =(tag), title=(title)")



 *  Label size option. Defautls to random.
public var labelSizeType : LabelSizeType = .random

 *  Gravity enabled?
public var isGravity : Bool = true

 *  Min font size. Defautls to 14.
public var minFontSize : Float = 14

 *  Max font size. Defaults to 60.
public var maxFontSize : Float = 60

 *  Random text colors with default list
public var randomColors = [, UIColor.cyan, UIColor.purple,,, UIColor.yellow, UIColor.lightGray, UIColor.gray,]


This code is distributed under the terms and conditions of the MIT license.

Latest podspec

    "name": "GravityTagCloudView",
    "module_name": "GravityTagCloudView",
    "version": "0.2.0",
    "summary": "A tag cloud view with gravity.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Bill Chan": "[email protected]"
    "platforms": {
        "ios": "10.0"
    "source": {
        "git": "",
        "tag": "0.2.0"
    "source_files": "GravityTagCloudView/**/GravityTagCloudView.swift",
    "frameworks": "UIKit",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This