iphone sdk button sound
i want to add a soun开发者_JS百科d to button please help me with this.
You can use the method - (void)playInputClick
, found in the UIDevice
class. You can access an instance of this class using the static method + (UIDevice *)currentDevice
. Use this method to attatch the default input sound to your own custom UI.
- (IBAction)startPlayback:(UIButton *)sender {
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
player.delegate = self;
[player play];
}
}
- (IBAction)startPlayback:(UIButton *)sender {
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
player.delegate = self;
[player play];
}
}
精彩评论