Skip to main content

Custom Loader (Activity Indicator) in Swift

Creating a custom activity indicator in Swift allows you to tailor the appearance and behavior of your loading spinner to fit the style of your app. Here's a step-by-step guide to creating a simple custom activity indicator using UIView Step 1: Create a New Swift File for the Custom Activity Indicator Create a new Swift file and name it  RotatingCirclesView.swift . Add the following code to define a custom UIView subclass for your activity indicator: // //   RotatingCirclesView.swift //   Welcome In // //   Created by Praveen Kumar on 05/09/24. // import UIKit class RotatingCirclesView : UIView {          let circle1 = UIView ( frame : CGRect ( x : 20 , y : 20 , width : 60 , height : 60 ))     let circle2 = UIView ( frame : CGRect ( x : 120 , y : 20 , width : 60 , height : 60 ))          let position : [ CGRect ] = [ CGRect ( x : 30 , y : 20 , width : 60 , height : 60 ), CGRect ( x : 60 , y : 15 , width : 70 , height : 70 ), CGRect ( x : 110 , y : 20 , width : 60 , heigh

Create Graphs & Charts in App with Swift With Charts cocoapods

Charts 3.6.0

1. CocoaPods Install

Add pod 'Charts' in your podfile

pod 'Charts'

Then Pod Install With Terminal.

Then 

1. if you want to used Bar Chart in your project then Start.

import Charts
import UIKit

    class ViewController: UIViewController, ChartViewDelegate {
    
    var barChart = BarChartView()
    
    override func viewDidLoad(){
    super.viewDidLoad()
    barChart .delegate = self
    }  
    
    override func  viewDidLayoutSubviews(){
    super.viewDidLayoutSubviews()
    barChart.frame = CGRect(x: 0, y: 0, width: self.view,frame.size.width , hieght: self.view,frame.size.width)
    barChart.center = view.center
    view.addSubview(barChart)
    
    var entries = [BarChartDataEntry]()
    for x in 0..<10{
        entries.append(BarChartDataEntry(x: Double(x), y: Double(x)))
    }
    let set = BarChartDataSet(entries)
    set.colors = ChartColorTemplets.joyful() 
    let data = BarChartData(dataSet: set)
    barChart.data = data
    }
}

2. if you want to used Line Chart in your project then Start.

import Charts
import UIKit

    class ViewController: UIViewController, ChartViewDelegate {
    
    var lineChart = LineChartView()
    
    override func viewDidLoad(){
    super.viewDidLoad()
    lineChart .delegate = self
    }  
    
    override func  viewDidLayoutSubviews(){
    super.viewDidLayoutSubviews()
    lineChart .frame = CGRect(x: 0, y: 0, width: self.view,frame.size.width , hieght: self.view,frame.size.width)
    lineChart .center = view.center
    view.addSubview(lineChart )
    
    var entries = [LineChartDataEntry]()
    for x in 0..<10{
        entries.append(LineChartDataEntry(x: Double(x), y: Double(x)))
    }
    let set = LineChartDataSet(entries)
    set.colors = ChartColorTemplets.material()
    let data = LineChartData(dataSet: set)
    lineChart.data = data
    }
}


3. if you want to used Pie Chart in your project then Start.

import Charts
import UIKit

    class ViewController: UIViewController, ChartViewDelegate {
    
    var pieChart = PieChartView()
    
    override func viewDidLoad(){
    super.viewDidLoad()
    pieChart .delegate = self
    }  
    
    override func  viewDidLayoutSubviews(){
    super.viewDidLayoutSubviews()
    pieChart .frame = CGRect(x: 0, y: 0, width: self.view,frame.size.width , hieght: self.view,frame.size.width)
    pieChart .center = view.center
    view.addSubview(pieChart )
    
    var entries = [PieChartDataEntry]()
    for x in 0..<10{
        entries.append(PieChartDataEntry(x: Double(x), y: Double(x)))
    }
    let set = PieChartDataSet(entries)
    set.colors = ChartColorTemplets.colorful()
    let data = PieChartData(dataSet: set)
    pieChart .data = data
    }
}


Comments

Post a Comment