VolumeBar
is a Swift volume indicator that doesn't obstruct content on screen. A basic implementation is just one line of code, but it can be heavily customized via several appearance and presentation properties.
- Customizable appearance
- Orientation change support
- Hides system volume HUD automatically
- Simple API
Current Swift compatibility breakdown:
Swift Version | Framework Version |
---|---|
3.0 | master |
2.3 | 1.1 |
2.2 | 1.1 |
A basic implementation of VolumeBar
is just one line of code.
VolumeBar.sharedInstance.start()
By default, adding VolumeBar
to your app will cause background audio to pause when your app is opened. To prevent this, add the following line of code wherever you call the start
method:
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
Calling the start
method begins observing changes in the system volume. After calling start
, VolumeBar
will show automatically whenever your app is active and the volume changes. This is appropriate for most use cases. To stop observing changes and use the system volume HUD again, call stop
:
VolumeBar.sharedInstance.stop()
Please see the documentation and check out the sample app (VolumeBarSample) for more details.
Customize tint color, bar tint color, and track tint color:
VolumeBar.sharedInstance.tintColor = UIColor.white
VolumeBar.sharedInstance.backgroundColor = UIColor.black.withAlphaComponent(0.5)
VolumeBar.sharedInstance.trackTintColor = UIColor.clear
Customize layout properties:
VolumeBar.sharedInstance.barHeight = 5
VolumeBar.sharedInstance.segmentCount = 8
VolumeBar.sharedInstance.interitemSpacing = 5
If start
has been called, VolumeBar
will automatically show when the system volume changes. You can also manually show and hide VolumeBar
.
VolumeBar.sharedInstance.show()
VolumeBar.sharedInstance.hide()
Change the animation style:
VolumeBar.sharedInstance.animationStyle = .fade // default is .slide
VolumeBar.sharedInstance.animationDuration = 0.5
VolumeBar.sharedInstance.minimumVisibleDuration = 2.0
VolumeBar
needs to know when the status bar is hidden or changes style. These properties should be updated in the viewWillAppear
method of each view controller.
VolumeBar.sharedInstance.statusBarHidden = false
VolumeBar.sharedInstance.statusBarStyle = .lightContent
VolumeBar
is available using the Cocoa dependency manager CocoaPods.
To integrate, add the following to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'VolumeBar', '~> 2.0.4'
Installation is also available using the dependency manager Carthage. To integrate, add the following line to your Cartfile
:
github "gizmosachin/VolumeBar" "master"
Installation is also available using the Swift Package Manager. To integrate, add the following to your Package.swift
:
import PackageDescription
let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "https://github.com/gizmosachin/VolumeBar.git", majorVersion: 0),
]
)
You can also simply copy VolumeBar.swift
into your Xcode project.
API documentation is available here.
- Need help? Use Stack Overflow with the tag 'volumebar-swift'.
- Questions? Use Stack Overflow with the tag 'volumebar-swift'.
- Found a bug? Open an issue.
- Feature idea? Open an issue.
- Want to contribute? Submit a pull request.
VolumeBar is available under the MIT license, see the LICENSE file for more information.