0

scrollView にこのボタンがあり、押すと音を鳴らす必要があります。

UIButton *profileButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [profileButton setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateNormal];
    [profileButton setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateHighlighted];
    profileButton.frame = CGRectMake(0, 620, 320, 250);

[self.scrollView addSubview:profileButton];

どうすればこれを行うことができますか? ありがとう、

4

1 に答える 1

1

ボタンを押してタッチを追加する

[profileButton addTarget:self action:@selector(onButtonPress) forControlEvents:UIControlEventTouchUpInside];

// このインクルード ファイルと AudioToolbox フレームワークが必要です

#import <AudioToolbox/AudioToolbox.h>

音を鳴らす

-(void) onButtonPress {
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"mp3"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
    AudioServicesPlaySystemSound (soundID);
}
于 2013-03-03T14:13:35.077 に答える