MBCircularProgressBar
  • September 25, 2023

If you use MBCircularProgressBar, please tell me and I will add your app here.

Usage


To run the example project, clone the repo, and run pod update from the Example directory first.

Installation


CocoaPods

MBCircularProgressBar is available through CocoaPods.

To install it, simply add the following lines to your Podfile:

  • Add this line to the begining of your Podfile in order to support @IBDesignable. More info here (Thanks to: @StevenMasini)

use_frameworks!

  • Add this line so with every Pod install/update cocoapods would download the library intro your project:

pod “MBCircularProgressBar”

Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate MBCircularProgressBar into your Xcode project using Carthage, specify it in your Cartfile:

github “MatiBot/MBCircularProgressBar”

Run carthage update to build the framework and drag the built MBCircularProgressBar.framework into your Xcode project.

Directly

You can also download the MBCircularProgressBar{View,Layer}.{m,h} files into your project directly

Properties


Property name Property type Description Range
value CGFloat The value to be displayed in the center [0,maxValue]
maxValue CGFloat The maximum possible value, used to calculate the progress (value/maxValue) [0,∞)
showValueString BOOL Should show value string
showUnitString BOOL Should show unit string
valueFontName NSString The name of the font of the value string Any valid font name
valueFontSize CGFloat The font size of the value text [0,∞)
valueFontName NSString The name of the font of the unit string Any valid font name
unitFontSize CGFloat The font size of the unit text [0,∞)
unitString NSString The string that represents the units, usually %
fontColor UIColor The color of the value and unit text
decimalPlaces NSInteger Number of decimal places of the value [0,∞)
progressRotationAngle CGFloat Progress bar rotation (Clockewise) [0,100]
progressAngle CGFloat Set a partial angle for the progress bar [0,100]
progressLineWidth CGFloat The width of the progress bar (user space units) [0,∞)
progressColor UIColor The color of the progress bar
progressStrokeColor UIColor The color of the progress bar frame
progressCapType NSInteger The shape of the progress bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
emptyLineWidth CGFloat The width of the background bar (user space units) [0,∞)
emptyLineColor UIColor The color of the background bar
emptyCapType CGFloat The shape of the background bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
textOffset CGPoint The offset to apply to the unit / value text (0,0) = center of the circle

Animation


In order to animate a change in the progress bar you should nest the value property manipulation in a [UIView animateWithDuration:] method

[UIView animateWithDuration:1.f animations:^{
self.progressBar.value = 55.f;
}];

References


[iOS][Swift] MBCircularProgressBar で円形のプログレスバーを実現 by @cocominap (in Japanese)

GitHub


View Github

YOU MIGHT ALSO LIKE...
PageView

SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS.

Pages

    

How to take action when a property changes

1. Taking Action When a Property Changes: Property Observers Swift lets you observe and respond to changes in a property’s ...

How to create your own structs? How to compute property values dynamically?

1. Creating Your Own Structs In Swift, a struct is a value type that you define with the struct keyword. ...

How to use trailing closures and shorthand syntax?

1. Trailing Closure Syntax When the last parameter to a function is a closure, you can write that closure after ...