Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Customize indicator view iOS swift

extension UIView {

func addActivityIndicator() {
    //    creating a view (let's call it "loading" view) which will be added on top of the view you want to have activity indicator on (parent view)
    let view = UIView()
    //    setting up a background for a view so it would make content under it look like not active
    view.backgroundColor = UIColor.white.withAlphaComponent(0.7)

    //    adding "loading" view to a parent view
    //    setting up auto-layout anchors so it would cover whole parent view
    self.addSubview(view)
    view.translatesAutoresizingMaskIntoConstraints = false
    view.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
    view.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
    view.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
    view.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true

    //    creating array with images, which will be animated
    //    in my case I have 30 images with names activity0.png ... activity29.png
    var imagesArray = [UIImage(named: "activity(0)")!]
    for i in 1..<30 {
        imagesArray.append(UIImage(named: "activity(i)")!)
    }

    //    creating UIImageView with array of images
    //    setting up animation duration and starting animation
    let activityImage = UIImageView()
    activityImage.animationImages = imagesArray
    activityImage.animationDuration = TimeInterval(0.7)
    activityImage.startAnimating()

    //    adding UIImageView on "loading" view
    //    setting up auto-layout anchors so it would be in center of "loading" view with 30x30 size
    view.addSubview(activityImage)
    activityImage.translatesAutoresizingMaskIntoConstraints = false
    activityImage.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    activityImage.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    activityImage.widthAnchor.constraint(equalToConstant: 30).isActive = true
    activityImage.heightAnchor.constraint(equalToConstant: 30).isActive = true
}

func removeActivityIndicator() {
    //    checking if a view has subviews on it
    guard let lastSubView = self.subviews.last else { return }
    //    removing last subview with an assumption that last view is a "loading" view
    lastSubView.removeFromSuperview()
} }
Comment

PREVIOUS NEXT
Code Example
Swift :: Swift Change Value of Dictionary 
Swift :: Swift Bitwise XOR Operator 
Swift :: how to screen record swift stackoverflow 
Swift :: waiting for all the threads to finish swift 
Swift :: Swift Computed Property In Extension 
Swift :: Swift enum With Switch Statement 
Swift :: procedural audio with swift 
Swift :: store multiple items in one core data record 
Swift :: Swift Iterate Over a Set 
Swift :: ios swift local storage with icloud 
Swift :: swift converting time string to number 
Swift :: how to switch tabs in xcode 
Swift :: flow ios swift kotlin 
Swift :: swift 5 uidatepicker display inline 
Swift :: Notification Service Extension vs Content Extension 
Swift :: bzxjhjgvjgvjgvjv 
Swift :: swift split an array into chunks 
Swift :: swift error handling 
Swift :: password reset with phone number in firebase flutter 
Swift :: cifilter image preserve orientation 
Ruby :: how to check if data is an array or not ruby 
Ruby :: rails validate uniqueness 
Ruby :: rails g resource 
Ruby :: shopify cart show total save 
Ruby :: add key and value to hash ruby 
Ruby :: iterate over each key value in hash ruby 
Ruby :: concatenate arrays in ruby 
Ruby :: ruby strings 
Ruby :: rails scope syntax 
Ruby :: ruby activerecord find where less than 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =