Compatibility
- 1.0.25 and master5.35.25.15.04.2
- 1.0.25 and masteriOSmacOS(Intel)macOS(ARM)LinuxtvOSwatchOS
Piano keyboard view for iOS, in Swift
An iOS piano keyboard view for iPhone or iPad, written in Swift 5. Has an IBDesignable preview in interface builder with IBInspectable properties for:
All images are drawn using Core Graphics.
To use via CocoaPods, add the following line to your Podfile:
pod 'PianoKeyboard'
With Xcode 11+ you can add PianoKeyboard to your project using the Swift Package Manager. From the File menu select Swift Packages and then select Add Package Dependency. A dialogue then will request the package repository URL, enter:
https://github.com/garynewby/PianoKeyboard.git
The Example app demonstrates how to integrate and use PianoKeyboard in your project. It includes a simple AVAudioEngine/AVAudioUnitSampler based sound source.
func pianoKeyDown(_ keyNumber: Int) {
// Called when the key corresponding to midi number keyNumber is pressed
}
func pianoKeyUp(_ keyNumber: Int) {
// Called when the key corresponding to midi number keyNumber is released
}
A key's label must be assigned a value for it to show:
keyboard.setLabel(for: 60, text: "Do")
keyboard.setLabel(for: 62, text: "Re")
keyboard.setLabel(for: 64, text: "Mi")
for noteNumber in 65...72 {
keyboard.setLabel(for: noteNumber, text: Note.name(for: noteNumber))
}
brew install swiftlint
Gary Newby
Licensed under the MIT License.