Giter VIP home page Giter VIP logo

swiftspinner's Introduction

SwiftSpinner

Version License Platform Swift 5.0

SwiftSpinner is an extra beautiful activity indicator with plain and bold style. It uses dynamic blur and translucency to overlay the current screen contents and display an activity indicator with text (or the so called “spinner”).


I developed it for my Swift app called Doodle Doodle and wanted to share it with everyone.

This is how the activity looks like (from the demo app):

SwiftSpinner Screenshot

Usage

To run the example project, clone the repo, and run pod install from the DemoApp directory first. That’ll run the demo program which shows you how the spinner looks like and what it can do.

Code samples

The simple code to get SwiftSpinner running in your own app.

  • In case you installed SwiftSpinner via CocoaPods you need to import it (add this somewhere at the top of your source code file):
import SwiftSpinner
  • When you want to show an animated activity (eg. rings are randomly rotating around):
SwiftSpinner.show("Connecting to satellite...")
  • If you want to show a static activity indicator (eg. a message with two complete rings around it)
SwiftSpinner.show("Failed to connect, waiting...", animated: false)
  • When you want to hide the activity:
SwiftSpinner.hide()

In case you want to do something after the hiding animation completes you can provide a closure to the hide() method:

SwiftSpinner.hide({
  //do stuff
})

That's all. If you want to change the text of the current activity, just call show(...) again, this will animate the old text into the new text.

Beyond the basics

If you are using SwiftSpinner to show an alert message you can also easily add a dismiss handler:

SwiftSpinner.show("Connecting \nto satellite...").addTapHandler({
  SwiftSpinner.hide()
})

Or even add a subtitle to let the user know they can tap to do stuff:

SwiftSpinner.show("Connecting \nto satellite...").addTapHandler({
  SwiftSpinner.hide()
}, subtitle: "Tap to hide while connecting! This will affect only the current operation.")

In case you want to adjust the font of the spinner title:

SwiftSpinner.setTitleFont(UIFont(name: "Futura", size: 22.0))

To reset back to the default font:

SwiftSpinner.setTitleFont(nil)

In case you want to change an arbitrary aspect of the text on screen access directly:

SwiftSpinner.shared.titleLabel
SwiftSpinner.shared.subtitleLabel

You can show a spinner only if certain amount of time has passed (e.g. if you are downloading a file - show a message only if the operation takes longer than certain amount of time):

SwiftSpinner.show(delay: 2.0, title: "It's taking longer than expected")

If you call show(…) or hide() before the delay time has passed - this will clear the call to show(delay: …).

You show a message for a certain duration:

SwiftSpinner.show(duration: 4.0, title: "It's taking longer than expected")

Or you can use SwiftSpinner as a progress bar by directly setting the current progress like so:

SwiftSpinner.show(progress: 0.2, title: "Downloading Data...") // 20% trough the process

If you want to see the content behind the spinner, set the showBlurBackground to false:

SwiftSpinner.showBlurBackground = false

Requirements

UIKit must be imported. If you are using SwiftSpinner in an App Extension, you must add EXTENSION to your Other Swift Flags Build Settings.

Extension Setting Screenshot

Installation

SwiftSpinner is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftSpinner"

In case you don’t want to use CocoaPods - just copy the file SwiftSpinner/SwiftSpinner.swift to your Xcode project.

Credit

Author: Marin Todorov

More about Marin:


iOS Animations by Tutorials, Author

iOS Animations by Emails Newsletter, Author

License

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

swiftspinner's People

Contributors

andreamazz avatar chefren avatar coulsonwang avatar dakdroid avatar davidlari avatar dimaru avatar dwoodgate avatar fortmarek avatar gaelfoppolo avatar heart avatar icanzilb avatar joseph-montanez avatar joyo246 avatar kylemay avatar logananderson avatar maxxfrazer avatar nickdnk avatar palmtrae avatar paweljankowski avatar psk239 avatar rayfix avatar rinatkhanov avatar sean7512 avatar stanevprime avatar stoykovprime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftspinner's Issues

Swift Spinner Doesn't Show iOS9.2 - Solved - Submitted PR

SwiftSpinner used to work when called from any method. But in recent updates with Swift and iOS9.2 the SwiftSpinner gets lost in which window it should add the view to. I have solved the issue and submitted a PR from my fork.

Prevent interaction while on display

Hi there! I've just used your spinner today and found that the views below it still allow interaction while the spinner itself is on display.

SwiftSpinner won't show when segueing from AppDelegate to ViewController

I made a simple project where I have two ViewControllers embedded in a Navigation controller. when i segue from first view controller to second view controller then SwiftSpinner shows up as expected. My second view controller with id "secondView" has a SwifSpinner in viewDidLoad().

Problem is when I try to segue to second view controller with id "secondView" directly from appDelegate. When segue is performed this way SwiftSpinner doesn't show up. Any ideas why or if there's a workaround? Below is my code:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let navController: UINavigationController = (self.window!.rootViewController as! UINavigationController)
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)


        let initialViewController = storyboard.instantiateViewControllerWithIdentifier("secondView") as! SwitSpinnerViewController
        navController.pushViewController(initialViewController, animated: false)
        self.window?.rootViewController = navController

        return true
    }

}
import UIKit

import SwiftSpinner
class SwitSpinnerViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        SwiftSpinner.show("Testing")


    }
}

Couple of Questions

Hey, amazing tweak!
How can I dismiss it after some seconds?
How can I change the grey background?

Feature Request: Dismiss on touch

I would love to have the ability to dismiss the spinner when a user touches the screen. This is helpful when displaying error messages to the user.
Thank you

Not updating

So my database calls take a moment or two but are quite fast. So I show the swiftspinner and I want to hide it or display a new message with animated:false but it often takes 10 or 15 seconds to update, long after the method itself is called.

shoWithDelay and tapHandler(hide) don't work

Hi,
I try to add a tap handler with a showWithDelay SwiftSpinner but the SwiftSpinner.hide is never called, with the following code :

SwiftSpinner.showWithDelay(2.0, title: "Connexion \nen cours...").addTapHandler({
SwiftSpinner.hide()
}, subtitle: "Tap to hide while connecting! This will affect only the current operation.")

Is it possible to do what I want ?

Bug fix involving UIFont and Xcode update

var defaultTitleFont = UIFont(name: "HelveticaNeue", size: 22.0)!

Needs to be changed to .init in order to build without errors.

var defaultTitleFont = UIFont.init(name: "HelveticaNeue", size: 22.0)!

animateWithDuration

On upgrade to Xcode 7.1 and Swift 2 I am getting an error saying that nil is not compatible with options:. Any recommendation on which option I should use?

UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.0, options: nil, animations:

Custom subtitle font

The ability to customize the subtitle font would be a nice addition to SwiftSpinner.

why it doesn't work with me?

iOS 8.0

btn clicked but SwiftSpinner not showing.

import UIKit
import SwiftSpinner

class SettingViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let btn = UIButton(frame: CGRectMake( 50, 200,200,20))
    btn.setTitle("back to loading view", forState: .Normal)
    btn.setTitleColor(UIColor.blueColor(), forState: .Normal)
    btn.setTitleColor(UIColor.redColor(), forState: .Selected)
    btn.addTarget(self, action: "buttonClicked:", forControlEvents: .TouchUpInside)
    self.view.addSubview(btn)
}


func buttonClicked(sender:UIButton!){
    SwiftSpinner.show("hehe", animated: true)
    print("clicked")
}

}

Doesn't work on viewDidLoad

Hi !

I've tried to add your nice spinner on my project, and, to do a first test, I've just call "show" method on the "viewDidLoad" of my first controller... But nothing was shown.

Then, I've tried to put it on "viewDidAppear" and it was OK.

Is it normal ?

Continuos rotation

Is it possible that the circles continues to rotate instead moving step by step?
Thanks

title can't be showed

Hi!
I use you Spinner in my iOS9.2 hybrid app to show uploadging in didRecieveJsNotification(). When I call show() method it show the circle without title and animate, before hiding it show the last title "100%" in a shot time

iOS 10 Support

Love this spinner!

I was testing it with iOS 10 and it is not working correctly. When do you think you will be able to add iOS 10 support? Please keep me posted as it is something we would love to leave in even when iOS 10 releases publicly.

Wont load on UIViewController but will on UINavigationController

I'm not sure why this is happening,.

I tested this on a project with navigation controller. It worked, So I created a new project as I had another idea and put the code on. For some reason it wouldnt work.

I check both projects and everything was the same apart from the class decleration.

So I changed:

class ViewController: UIViewController {

to

class ViewController: UINavigationController {

and it worked. Any ideas how to get this to load in a blank view controller?

Custom colors

It would be nice to be able to customize the blur text color. Now the blur color is a private property so subclassing does not help.

Progress

Is it possible that the circles can be bigger and bigger as a progress hud?

Thank !

Stops animating

Ive tried to (in viewDidLoad and viewDidAppear) to start and stop animations in the main thread but cant get it to work. I am new to swift and am looking for help. I looked at the demo app in the zip file, but i dont want the spinning animation to only run for a select amount of time. Any help is appreciated

i tried the following code in both view did appear and view did load:

    dispatch_async(dispatch_get_main_queue(), {
        SwiftSpinner.show("Processing data...", animated: true)
    })

    //parse some data here

    dispatch_async(dispatch_get_main_queue(),{
        SwiftSpinner.hide()
    })

Background is not blured correctly

Hello thank you for providing the SwiftSpinner library! When implementing your library I have a strangely blurred background on the right of the view. The color is slightly different to the rest of the View although the background color is the same

simulator screen shot sep 24 2015 8 50 43 pm

Share Xcode scheme so SwiftSpinner works with Carthage

Carthage is a decentralized dependency manager that gives developers more control over how frameworks are integrated compared to CocoaPods, and is becoming increasingly popular. It uses xcodebuild to build dependancies instead of using a shared workspace, and the only requirement for frameworks is that there's a shared scheme so that the tool can discover and build it properly.

Don't adjust when orientation changed

If we change the device orientation when the spinner is showed, the spinner don't adjust it self for the hole screen. (tested in real iphone 4S device)
spinner bug

Visible square box on iOS 10

As I see this issue was fixed in #77 for Swift 3 version of Spinner(v. 1.0.1)

@icanzilb Can you create the same fix for 0.9.5 (Swift 2.3) and submit new version to cocoapods?

SwiftSpinner.hide() not working within function

Hi,

I am trying to open and hide the SwiftSpinner but it does not work when I isolate the SwiftSpinner.hide() call into a completion block.

The code is :

    SwiftSpinner.show("Connexion...", animated: true)

    loginRequest(loginData, {(success:Bool) -> Void in
        println("value = \(success)")
        SwiftSpinner.hide()
    })

The spinner just stops moving without diseappearing. It's like the spinner.removeFromSuperview is not working.
Thank you in advance,

Demo App looks great in simulator; barely readable on iPad Air 2

Just running the unmodified Demo app - it looks fine on the simulator - i can see the hurricane image blurred, rings are bright, text is bright.

On physical device - everything is very dark. Can't see the blurred hurricane. Barely read the text.

Brightness is turned up to ~ 75% on the device.

Text and circle color.

Hi, I want to know if the text and the circle can be set to a specific color rather than referring to the colors of the underlying view. In this specific case, I would like the text and the circle was white.

Best regards
Costantino

textandcirclecolor

Xcode 6.3 & Swift 1.2 compatibility

Hello,
seems like with the release of Xcode 6.3 some minor changes in code must be done, like label "completion:" in call of all CGAffineTransformMakeRotation handlers and as! for all force downcasts.

Thank you in advance.

"No such Module?"

Getting a "No such Module" error next to "import SwiftSpinner" when trying to run the demo on the simulator. Sorry if this is a novice question. New to iOS development. Tried deleting the "DerivedData" folder, cleaning, and building, but no luck. Any suggestions? Thanks!

showWithDelay shows even after a hide()

In the latest release, the hide() method does not seem to stop a showWithDelay from happening.

The following code

SwiftSpinner.show("Authenticating...")
SwiftSpinner.showWithDelay(4.0, title: "Authenticating... Sorry, it's taking so long.", animated: true)

Shows the "Authenticating..." spinner. Then, 4 seconds later the "showWithDelay" spinner pops up, even if the "hide()" method has already been called.

The spinner appears behind a black layer on real iOS device

I'm using SwiftSpinner in a project, when I use the iOS simulator (iPhone 6S iOS 9.3) on my Macbook Pro the SwiftSpinner works just fine,
SwiftSpinner.show("Loading...")
Blur effect, white color are well displayed. But when I launch it on my iPhone 6 (iOS 9.3) it looks like there is a black layer over the spinner :

img_2550

Any solutions ?

Thanks !

Tinting?

It's possibile chamge color of spinner?

Spinner not shown when called from AppDelegate

I have no problem showing the Swift spinner from any function/view controller except AppDelegate. The problem comes only when I call SwiftSpinner.show("Loading...") from AppDelegate. I have set breakpoints and checked. The show() function in SwiftSpinner.swift is getting called and executed. But the spinner is not shown on the window. I have also updated the code with this MMasterson@68e718b . But still same problem. Anyone has any solution for this?

is it possible to resize the blur?

Im just wondering if instead of blurring the whole screen, would it be possible to set the parameters of the blur to maybe a smaller box in the middle or set it to a side, so we can use it to show loading without covering the whole screen(example: Zillow app loading message, a small block on the top)

thanks for your amazing code!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.