Giter Site home page Giter Site logo

nakplaybackindicatorview's Introduction

Version Build Status

Icon NAKPlaybackIndicatorView

Music.app

NAKPlaybackIndicatorView is a view that mimics the music playback indicator in the Music.app on iOS. It has some vertical bars and they oscillate randomly.

Requires iOS 8.0 or later.

Trying the Demo App

You can try the demo app instantly with CocoaPods:

# This will open an Xcode workspace
$ pod try NAKPlaybackIndicatorView

In the opened workspace, choose the Demo scheme and run.

Installation

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

pod 'NAKPlaybackIndicatorView'

Then run pod install.

Basic Usage

Here's a basic example:

#import <NAKPlaybackIndicatorView/NAKPlaybackIndicatorView.h>

- (void)viewDidLoad
{
    [super viewDidLoad];

    NAKPlaybackIndicatorViewStyle *style = [NAKPlaybackIndicatorViewStyle iOS7Style];
    NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithStyle:style];
    [self.view addSubview:indicator];
    [indicator sizeToFit];

    // Initially the `state` property is NAKPlaybackIndicatorViewStateStopped
    // and the `hidesWhenStopped` property is YES.
    // Thus, the view is hidden at this time.

    // The view appears and the bars start animation.
    indicator.state = NAKPlaybackIndicatorViewStatePlaying;

    // The bars stop animation and become idle.
    indicator.state = NAKPlaybackIndicatorViewStatePaused;

    // The view becomes hidden.
    indicator.state = NAKPlaybackIndicatorViewStateStopped;
}

You can use NAKPlaybackIndicatorView in both code and Storyboard, and it works well with both Auto Layout and frame-based layout.

Code with Auto Layout

NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithFrame:CGRectZero];
indicator.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:indicator];

// Then, add some positioning layout constraints.
// Note that normally you don't need to add sizing constraints
// since NAKPlaybackIndicatorView has an intrinsic content size.
// It will be automatically resized to fit its content.

Code with Frame-Based Layout

NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithFrame:CGRectZero];
[self.view addSubview:indicator];
[indicator sizeToFit]; // Resize itself to fit its content.

Storyboard with Auto Layout

  1. Put a UIView on your view.
  2. Set its custom class to NAKPlaybackIndicatorView.
  3. In the Size Inspector (⌥⌘5), set the Intrinsic Size to Placeholder and set the width to 12 and the height to 12. Note that this is just for convenience of the appearance on the Storyboard, and the placeholder size won't be used at runtime.
  4. Add some positioning layout constraints.

Storyboard with Frame-Based Layout

  1. Put a UIView on your view.
  2. Set its custom class to NAKPlaybackIndicatorView.
  3. In the Size Inspector (⌥⌘5), set the width to 12 and the height to 12.

Customization

Bar Count, Size, and Spacing

Bars can be customized via NAKPlaybackIndicatorViewStyle.

Color

The color of the bars can be changed by setting tintColor property (UIView) of the view or its ancestor view.

View Size

Normally the view can be automatically resized to fit its content by:

  • Omitting sizing constraints in Auto Layout, since it has an intrinsic content size.
  • Calling sizeToFit in frame-based layout.

Or if you explicitly specify size, the bars will be placed in the center of the view.

Class Reference

NAKPlaybackIndicatorView's class reference is available on CocoaDocs.org.

License

Copyright (c) 2014–2017 Yuji Nakayama

See the LICENSE.txt for details.

nakplaybackindicatorview's People

Contributors

dependabot[bot] avatar yujinakayama 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

nakplaybackindicatorview's Issues

Positioning error with safe area layout?

I am using the Xcode 9.4.1 with storyboard and safe area layout and the following code to position the playback indicator on my own "small" view:

    NAKPlaybackIndicatorViewStyle *style = [NAKPlaybackIndicatorViewStyle iOS10Style];
    NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithStyle:style];
    indicator.translatesAutoresizingMaskIntoConstraints = YES;  
    [self.view addSubview:indicator];
    [indicator sizeToFit];
    indicator.frame = _myPlaybackIndicatorView.frame;
    indicator.state = NAKPlaybackIndicatorViewStatePlaying;

But the indicator is not positioned as expected in the middle of the "myPlaybackIndicatorView.frame" but somewhere else. I think the problem is regarding the safe area. What would be the best practice to position the playback indicator "over" a view?

Not displayed correct:

screen shot 2018-09-07 at 00 07 05

Displayed as expected:

screen shot 2018-09-07 at 00 07 45

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.