
Here’s something I made for a student at CSM, thought someone might find useful. A soundboard app, you can setup with your own sounds by modifying the .plist file alone. Change the names of the buttons in there to match the titles of your button images and sounds, and the app will create your board.
For example, if you had a sound a.caf, as well as corresponding a.png & a_highlighted.png, this is what your plist might look like.
<plist version="1.0">
<dict>
<key>a</key>
<dict>
<key>x</key>
<integer>50</integer>
<key>y</key>
<integer>500</integer>
</dict>
</dict>
This is the view controller that takes care of arranging the buttons.
// Buttons
AppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
// Get button names
NSArray * buttonNames = [appDelegate.buttons allKeys];
for(int i = 0; i < [appDelegate.buttons count]; i++)
{
// Load button image
NSString * buttonName = [buttonNames objectAtIndex:i];
UIImage * buttonImage = [UIImage imageNamed:[buttonName stringByAppendingFormat:@".png"]];
UIImage * buttonHighlightImage = [UIImage imageNamed:[buttonName stringByAppendingFormat:@"_highlight.png"]];
if(buttonImage == nil || buttonHighlightImage == nil)
NSLog(@"Could not load button! Check the keys in your plist match the contents of the buttons folder");
// Position button
CGPoint point = CGPointMake([[[appDelegate.buttons objectForKey:buttonName] objectForKey:@"x"] floatValue], [[[appDelegate.buttons objectForKey:buttonName] objectForKey:@"y"] floatValue]);
// Use button image frame as size for view
ButtonView * newLetter = [[ButtonView alloc] initWithFrame:CGRectMake(point.x, point.y, buttonImage.size.width, buttonImage.size.height) andName:buttonName];
[newLetter.button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[newLetter.button setBackgroundImage:buttonHighlightImage forState:UIControlStateHighlighted];
// Use our own "glow" for the highlight state
[newLetter.button setAdjustsImageWhenHighlighted:NO];
[self.view addSubview:newLetter];
[newLetter release];
}
Download it here → gryton.zip